sonnyboy Posted April 4, 2007 Share Posted April 4, 2007 Hello folk I have a football league table and I'm trying to number my rows in the column named "Pos" but so far I not getting any success, someone please bail me out find below my script, this script displays my results fine but without my Positions (Pos); <?php function printTable($result) { $i=0; //get the first row in the table: if(!$row = mysql_fetch_assoc($result)) { return false; } //set up the table: print("<table><tr>"); print ("<th>Pos</th>"); //print the column names as table headers: foreach($row as $key=>$value) { print("<th>$key</th>"); } print("</tr>"); //loop through the table, printing //the field values in table cells: do { $i++; print("<tr>"); print ("<td>$i</td>"); foreach($row as $key=>$value) { print("<td>$value</td>"); } print("</tr>"); } while ($row = mysql_fetch_assoc($result)); //close out the table: print("</tr></table>"); return true; } ?> Link to comment https://forums.phpfreaks.com/topic/45644-displaying-query-results/ Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 you could use SELECT COUNT(*) FROM table or use mysql_num_rows($result) Link to comment https://forums.phpfreaks.com/topic/45644-displaying-query-results/#findComment-221697 Share on other sites More sharing options...
AndyB Posted April 5, 2007 Share Posted April 5, 2007 you could use SELECT COUNT(*) FROM table or use mysql_num_rows($result) @MadTechie - why would that help? Link to comment https://forums.phpfreaks.com/topic/45644-displaying-query-results/#findComment-221700 Share on other sites More sharing options...
MadTechie Posted April 5, 2007 Share Posted April 5, 2007 Good point, mis-read the post what about a function to print the number ie <?php function theRow() { static $a = 0; echo $a; $a++; } ?> other than that i can't see a problem.. Link to comment https://forums.phpfreaks.com/topic/45644-displaying-query-results/#findComment-221706 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.