fry2010 Posted March 8, 2009 Share Posted March 8, 2009 Ok this is a real simple one. I dont know why I cant get it working, I can normally do loops etc to echo data in table but this isnt working... $conn = db_connect(); $result = $conn->query("SELECT * FROM notice_board"); $result2 = $conn->query("SELECT COUNT(*) FROM notice_board"); $row = $result->fetchObject(); $column = $result2->fetchColumn(); $i = 0; while($i < $column) { echo '<tr>'; echo '<td>'.$row->id.'</td><td>'.$row->type.'</td><td>'.$row->entry.'</td><td>'.$row->sl.'</td><td>'.$row->tp.'</td><td>'.$row->notes.'</td><td>'.$row->changes.'</td>'; echo '</tr>'; $i++; } $conn = NULL; This will produce a table with 3 rows in it with all the columns, the only problem is that it is repeating the first row in the database table. So the id is just listed as number 1. Not 1,2,3. Here is the output. 1 buy 1.9865 1.9865 1.9865 1.9865 1 buy 1.9865 1.9865 1.9865 1.9865 1 buy 1.9865 1.9865 1.9865 1.9865 There is only three rows in the database so it has echoed the correct number of rows, just not each row. Link to comment https://forums.phpfreaks.com/topic/148461-solved-echo-all-data-in-mysql-table/ Share on other sites More sharing options...
RussellReal Posted March 8, 2009 Share Posted March 8, 2009 $conn = db_connect(); $result = $conn->query("SELECT * FROM notice_board"); $result2 = $conn->query("SELECT COUNT(*) FROM notice_board"); while($row = $result->fetchObject()) { $column = $result2->fetchColumn(); echo '<tr>'; echo '<td>'.$row->id.'</td><td>'.$row->type.'</td><td>'.$row->entry.'</td><td>'.$row->sl.'</td><td>'.$row->tp.'</td><td>'.$row->notes.'</td><td>'.$row->changes.'</td>'; echo '</tr>'; } $conn = NULL; Link to comment https://forums.phpfreaks.com/topic/148461-solved-echo-all-data-in-mysql-table/#findComment-779499 Share on other sites More sharing options...
fry2010 Posted March 8, 2009 Author Share Posted March 8, 2009 sweet, works a like a charm, thanks Russell. Link to comment https://forums.phpfreaks.com/topic/148461-solved-echo-all-data-in-mysql-table/#findComment-779511 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.