How to get a table number to auto-increment?
Posted: Tue Jul 28, 2009 4:25 am
A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$count = 1;
//in the loop which outputs each row of the table
echo $count++;
Cheers, will use that code now and see how it goes. And it's just for a menu so maybe a maximum of 20 links (even that's probably exaggerating to much) so no need to use pagination.turbolemon wrote:You just want to display a table row number next to each of the results?
Obviously you come into problems if you use pagination, as you will have to offset the count variable by the number of items per page multiplied by the page number.Code: Select all
$count = 1; //in the loop which outputs each row of the table echo $count++;
Code: Select all
while($fetchmenu = mysql_fetch_array($menu))
{
$id = $fetchmenu['id'];
$title = $fetchmenu['title'];
$link = $fetchmenu['weblink'];
$module = $fetchmenu['module'];
$level = $fetchmenu['level'];
$count = 1;
echo "<tr align=\"center\"><td class=\"tbl\">";
echo $count++;
echo "</td><td class=\"tbl\"><input type=\"checkbox\" name=\"check_list\" value=\"1\"></td><td align=\"left\" class=\"tbl\" style=\"padding-left: 5px;\"><a href=\"index.php?file=Admin&page=Menu&function=Edit&id=" . $id . "\">" . $title . "</a></td><td class=\"tbl\">Position</td><td class=\"tbl\">URL</td><td class=\"tbl\">" . $level . "</td><td class=\"tbl\">" . $id . "</td><td class=\"tbl\"><a href=\"index.php?file=Admin&page=Menu&function=Edit&id=" . $id . "\"><img border=\"0\" src=\"themes/default/images/edit_f2.png\" alt=\"\" /></a></td><td class=\"tbl\"><a href=\"index.php?file=Admin&page=Menu&function=Delete&id=" . $id . "\"><img border=\"0\" src=\"themes/default/images/cancel_f2.png\" alt=\"\" /></a></td></tr>\n";
}Code: Select all
$count = 1;
while($fetchmenu = mysql_fetch_array($menu))
{
$id = $fetchmenu['id'];
$title = $fetchmenu['title'];
$link = $fetchmenu['weblink'];
$module = $fetchmenu['module'];
$level = $fetchmenu['level'];
echo "<tr align=\"center\"><td class=\"tbl\">";
echo $count++;
echo "</td><td class=\"tbl\"><input type=\"checkbox\" name=\"check_list\" value=\"1\"></td><td align=\"left\" class=\"tbl\" style=\"padding-left: 5px;\"><a href=\"index.php?file=Admin&page=Menu&function=Edit&id=" . $id . "\">" . $title . "</a></td><td class=\"tbl\">Position</td><td class=\"tbl\">URL</td><td class=\"tbl\">" . $level . "</td><td class=\"tbl\">" . $id . "</td><td class=\"tbl\"><a href=\"index.php?file=Admin&page=Menu&function=Edit&id=" . $id . "\"><img border=\"0\" src=\"themes/default/images/edit_f2.png\" alt=\"\" /></a></td><td class=\"tbl\"><a href=\"index.php?file=Admin&page=Menu&function=Delete&id=" . $id . "\"><img border=\"0\" src=\"themes/default/images/cancel_f2.png\" alt=\"\" /></a></td></tr>\n";
}Code: Select all
while($fetchmenu = mysql_fetch_array($menu))
{
$id = $fetchmenu['id'];
$title = $fetchmenu['title'];
$link = $fetchmenu['weblink'];
$module = $fetchmenu['module'];
$level = $fetchmenu['level'];
$count = 1;
echo "<tr align=\"center\"><td class=\"tbl\">";
echo $count++;
?>
</td>
<td class="tbl"><input type="checkbox" name="check_list" value="1"></td>
<td class="tbl"><?php echo $level ?></td>
</tr>
<?php
}