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/45633-tabulating-sql-query-results/ Share on other sites More sharing options...
Barand Posted April 4, 2007 Share Posted April 4, 2007 So what exactly is the problem. It numbers each row when it prints. Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221677 Share on other sites More sharing options...
sonnyboy Posted April 4, 2007 Author Share Posted April 4, 2007 well that was what i was hoping to achieve but so far it still does not number the rows like i expected. Not even printing the title (Pos) either, i need the rows numbered...pls advice Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221680 Share on other sites More sharing options...
Barand Posted April 5, 2007 Share Posted April 5, 2007 Running your code on a table of mine gave [pre] Pos date location qty value area id 1 2003-01-08 Ashton 542 4216.87 E 1 2 2003-01-08 Bolton 317 2896.7 N 2 3 2003-01-08 Bury 1089 15161.2 N 3 4 2003-01-08 Oldham 866 7607.68 E 4 5 2003-01-08 Piccadilly 1106 25598.7 C 5 [/pre] What do you expect? Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221684 Share on other sites More sharing options...
sonnyboy Posted April 5, 2007 Author Share Posted April 5, 2007 really?? very strange...that is what I expected but I'm not seeing the Pos column, maybe my browser is haunted! ??? Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221687 Share on other sites More sharing options...
Barand Posted April 5, 2007 Share Posted April 5, 2007 Myfull code (the table shouldn't matter as it should work for any) <?php include 'db.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; } $res = mysql_query("SELECT * FROM baagriddata"); printTable($res); ?> Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221690 Share on other sites More sharing options...
Barand Posted April 5, 2007 Share Posted April 5, 2007 Results are the same with IE and Firefox Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221693 Share on other sites More sharing options...
sonnyboy Posted April 5, 2007 Author Share Posted April 5, 2007 no worries, its still not working I even tried clearing my cache...but no luck, will sleep on it...thnx neway! :-\ Link to comment https://forums.phpfreaks.com/topic/45633-tabulating-sql-query-results/#findComment-221707 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.