To create a dynamic table within php, I set the variable $count from a query, which counts the rows in specific table. Then I would like to create a table with the exact number of rows as a html table:
for($i=1;$i=<$count;$i++){
echo"<tr><td>$name</td><td>$rights</td></tr>";
}
That’s the way i want the table to be displayed. But everytime the for-loop is called, the values of $name and $rights should be taken from the database-table. But how should i handle this? I thought about a simple query selecting the name from the line where ID equals i. But then i remembered that always when i delete an entry from the table there will be gaps.
For example when there 3 entries and i delete the second one. There just are 2 entries; so the name of the second row, which ID is 3, will never be selected. Is there any way of handling this problem in an appropriated way?
You wouldnt use a
foryou would use awhileor aforeachwith the results from the query.