...

View Full Version : Adding numbers to each row



jcdevelopment
02-29-2012, 07:18 PM
I have this current code that easily spits out entered data along with a time stamp.



<?php
$db = mysql_connect('*','*','*');
mysql_select_db('*',$db);

$sel = "SELECT * from rsvp_101";

$q = mysql_query($sel,$db);
echo "<table>";
while ($row = mysql_fetch_assoc($q)) {


$first_name = $row['first_name'];
$last_name = $row['last_name'];
$office = $row['office'];
$guests = $row['guests'];
$date = $row['date'];



echo("

<tr><td>$first_name $last_name </td> <td>$office </td><td> Guests attending: $guests</td><td> $date</tr>

<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
");




}

?>


I am just looking for a solution in PHP to add, in numerical order, a number on each line repeating. Does anyone know of a way so it will look something like this:

1 name office date
2 name office date
3 name office date
etc....

thanks for any help.

mlseim
02-29-2012, 07:24 PM
like this?



<?php
$db = mysql_connect('*','*','*');
mysql_select_db('*',$db);

$sel = "SELECT * from rsvp_101";

$q = mysql_query($sel,$db);
echo "<table>";

$line=1;

while ($row = mysql_fetch_assoc($q)) {


$first_name = $row['first_name'];
$last_name = $row['last_name'];
$office = $row['office'];
$guests = $row['guests'];
$date = $row['date'];

echo("

<tr><td>$line</td><td>$first_name $last_name </td> <td>$office </td><td> Guests attending: $guests</td><td> $date</tr>

<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
<tr><td>&nbsp;</td><td>&nbsp;</td></tr>
");
$line++;




}

?>

jcdevelopment
02-29-2012, 07:34 PM
could have sworn i tried that.... It never worked, probably placed it in the whil statement. Thanks!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum