hi
first of all i want to create a linking with two tables in database:

1 table :

id,name
1 nick
2 john
3 michael

2 table (i want to use this table for dropdown list)

id,job
1 engineer
2 scientist
3 coder

how can i link them both?

the second thing i want is to create dynamical html tables(generate) which will be displayed by (while)
but if the first table has things inside from id 1 to 7 how can i make in second table to start from id 1 and not from 8?is this possible?

All help will be appresiated. :)

Member Avatar for diafol

hi
first of all i want to create a linking with two tables in database:

1 table :

id,name
1 nick
2 john
3 michael

2 table (i want to use this table for dropdown list)

id,job
1 engineer
2 scientist
3 coder

how can i link them both?

Create a 3rd table called userjob which has the fields: id (auto/PK), user_id, job_id if you want your users to be able to have more than one job.
Easy option - one job per user: create a third field in users table called "job" (tinyint, 2) - this will be able to take the id value from the job table. This is known as a 'foreign key' in RDBs.

To retrieve linked data, you need to use 'JOIN' syntax, e.g. INNER/LEFT/RIGHT JOIN - see the mysql online manual. If all users HAVE to choose a job, INNER JOIN will be the best bet, else LEFT JOIN - e.g. list all users with their jobs whether they have jobs or not (show empty for no job).

the second thing i want is to create dynamical html tables (generate) which will be displayed by (while)
but if the first table has things inside from id 1 to 7 how can i make in second table to start from id 1 and not from 8?is this possible?

Yes. Just reset the variable, e.g.

if($var > 6)$var = 1; // or any variation on this theme $var == 7 etc.

Before you can output the html, you need to know what tags you need on each 'row':

<?php
...
while(....){
 $tableoutput .= "\n\t\t<tr>\n\t\t\t<td>....</td>\n\t\t\t<td>...</td>\n\t\t\t<td>...</td>\n\t\t</tr>";
}
...
?>
<table>
  <thead>
    <tr>
       <th>...</th>
       <th>...</th>
       <th>...</th>
    </tr>
  </thead>
  <tbody>
<?php echo $tableoutput;?>
  </tbody>
</table>

Thank you very much.One more question :
Is it possible to reset the id's inside the database id

like :

id,job,etc...
1
2
3
1
2
3

Member Avatar for diafol

NO! Your ID field serves as your Primary Key, which MUST be unique for each record. Repeating an ID doesn't really make sense. Why do you want to do this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.