cody4camp Posted December 5, 2010 Share Posted December 5, 2010 I know I'm doing it something right, but can someone tell me why only one table is showing up? Can you help me fix the issue? Heres my code: function showcoords() { echo"J3st3r's CoordVision"; $result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION.""); dbarray($result); $fields_num = mysql_num_fields($result); echo "<table border='1'>"; // printing table headers echo "<td>Alliance</td>"; echo "<td>Region</td>"; echo "<td>Coord</td>"; // printing table rows while($row = mysql_fetch_array($result)) { // $row is array... foreach( .. ) puts every element // of $row to $cell variable foreach($row AS $Cell) echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } echo "</table>"; mysql_free_result($result); } I have 2 rows inserted into my coords table. Just frustrated and ignorant to php. Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/ Share on other sites More sharing options...
BlueSkyIS Posted December 5, 2010 Share Posted December 5, 2010 a couple things: there is no TR open/close for the header row. your foreach needs curly brackets {} to surround the multiple lines of code executed within. Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143382 Share on other sites More sharing options...
cody4camp Posted December 5, 2010 Author Share Posted December 5, 2010 function showcoords() { echo"J3st3r's CoordVision"; $result=dbquery("SELECT alliance, region, coordx, coordy FROM ".DB_COORDFUSION.""); echo "<table border='1'>"; // printing table headers echo "<tr>"; echo "<td>Alliance</td>"; echo "<td>Region</td>"; echo "<td>Coord</td>"; echo "</tr>\n"; // printing table rows while($row = mysql_fetch_array($result)) { foreach($row as $Cell) { echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } } echo "</table>"; mysql_free_result($result); } Done what you mentioned, and now it displays the same row 8 times. Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143385 Share on other sites More sharing options...
BlueSkyIS Posted December 5, 2010 Share Posted December 5, 2010 // printing table rows while($row = mysql_fetch_assoc($result)) { foreach($row as $Cell) { echo "<tr>"; echo "<td>".$Cell['alliance']."</td>\n"; echo "<td>".$Cell['region']."</td>\n"; echo "<td>".$Cell['coordx'].",".$Cell['coordy']."</td>\n"; echo "</tr>\n"; } } Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143388 Share on other sites More sharing options...
cody4camp Posted December 5, 2010 Author Share Posted December 5, 2010 replacing with your code gives this: [attachment deleted by admin] Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143390 Share on other sites More sharing options...
BlueSkyIS Posted December 5, 2010 Share Posted December 5, 2010 haha. my bad. try this: // printing table rows while($row = mysql_fetch_assoc($result)) { echo "<tr>"; echo "<td>".$row['alliance']."</td>\n"; echo "<td>".$row['region']."</td>\n"; echo "<td>".$row['coordx'].",".$row['coordy']."</td>\n"; echo "</tr>\n"; } Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143392 Share on other sites More sharing options...
cody4camp Posted December 5, 2010 Author Share Posted December 5, 2010 Worked nicely. Thank-you for all your help today Blue. Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143394 Share on other sites More sharing options...
cody4camp Posted December 5, 2010 Author Share Posted December 5, 2010 How would I make this where it only displays 50 rows, then has a <previous next> below it to show the next/previous 50 or so? Link to comment https://forums.phpfreaks.com/topic/220768-turning-mysql-table-into-html-table/#findComment-1143396 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.