yogibear Posted May 21, 2007 Share Posted May 21, 2007 Hi all I’m not total new to php but I still don’t understand a lot of php things so please go easy. I have 3 fields from a database going into a table. username, car and credits and a rank column the table is ordered by the total of 3 different fields in the database. I want the rank column to start at 1 for row 1, and 2 for row 2 and so on. I have tried some things that i found in another post but couldnt get them to work so I removed it. Rank Username Car Credits 1 qwert ford 100 2 test renault 50 this is the code i have <?php $con = mysql_connect("localhost","***","***"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("***", $con); $result = mysql_query("SELECT * FROM userinformation ORDER by credits + original + totalspent DESC"); echo "<table border='1'> <tr> <th>Rank</th> <th>Username</th> <th>Car</th> <th>Credits</th> </tr>";while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>". $row['rank'] . "</td>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['car'] . "</td>"; echo "<td>" . $row['credits'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> I hope someone can help thanks in advanced yogi Link to comment https://forums.phpfreaks.com/topic/52361-solved-numbering-fields-in-a-table/ Share on other sites More sharing options...
Barand Posted May 21, 2007 Share Posted May 21, 2007 <?php echo "<table border='1'> <tr> <th>Rank</th> <th>Username</th> <th>Car</th> <th>Credits</th> </tr>"; $rank = 1; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>". $rank++ . "</td>"; echo "<td>" . $row['username'] . "</td>"; echo "<td>" . $row['car'] . "</td>"; echo "<td>" . $row['credits'] . "</td>"; echo "</tr>"; } echo "</table>"; mysql_close($con); ?> Link to comment https://forums.phpfreaks.com/topic/52361-solved-numbering-fields-in-a-table/#findComment-258423 Share on other sites More sharing options...
yogibear Posted May 22, 2007 Author Share Posted May 22, 2007 Hi thank you so much, its so simple when you know how Link to comment https://forums.phpfreaks.com/topic/52361-solved-numbering-fields-in-a-table/#findComment-259019 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.