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. Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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"; } } Quote Link to comment 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] Quote Link to comment 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"; } Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.