jasonhardwick Posted May 21, 2008 Share Posted May 21, 2008 My page expodes and displays a column of my database (network) right now they are listed like so result 1 result 2 result 3 what i want to do is display them like so result 1 result 2 result 3 result 4 result 5 result 6 result 7 result 8 anyone know what i can do to get this type of display? <?php include "config.php"; $tbl_name3="user"; $sql3="SELECT * from $tbl_name3 WHERE uname = '{$_SESSION['username']}' ORDER BY id ASC LIMIT 0,1000"; $result3=mysql_query($sql3) or die(mysql_error()); while ($row3 = mysql_fetch_assoc($result3)) { $network_id = $row3['network']; $network_id_parts = explode(',',$network_id); foreach ($network_id_parts AS $a_nid_part) { ?> </p> <p><b><a href="user_profile.php?username=<? echo $a_nid_part; ?>"><? echo $a_nid_part; ?></a></b></p> <p> <? if (mysql_fetch_assoc($result3) == 0) { echo "You Currently Have No Network Connections"; } //echo "$a_nid_part "; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/ Share on other sites More sharing options...
soycharliente Posted May 21, 2008 Share Posted May 21, 2008 Hope this helps: <?php require("config.php"); $tbl_name3 = "user"; $sql3 = "SELECT * from $tbl_name3 WHERE uname = '{$_SESSION['username']}' ORDER BY id ASC LIMIT 0,1000"; $result3 = mysql_query($sql3) or die (mysql_error()); if (mysql_fetch_assoc($result3) > 0) { while ($row3 = mysql_fetch_assoc($result3)) { $network_id = $row3['network']; $network_id_parts = explode(",", $network_id); if (!empty($network_id)) { echo "<table>"; $count = 1; $limit = 4; // how many results per row $early = 0; foreach ($network_id_parts AS $a_nid_part) { $mod = $count % $limit; switch ($mod) { case 0: echo "</tr>"; break; case 4: echo "<tr>"; break; } echo "<td><strong><a href=\"user_profile.php?username={$a_nid_part}\">{$a_nid_part}</a></strong></td>"; $count++; $early = $limit - $mod; // tracking exiting the table early } // if we left on the $limit column, then just close the row if (!$mod) { echo "</tr>"; $early = 0; } // if we left before the $limit column, fill in blank cells to have a proper table if ($early) { for ($i = 1; $i <= $early; $i++) { echo "<td> </td>"; } echo "</tr>"; } echo "</table>"; } else { echo "You Currently Have No Network Connections"; } } } else { echo "You Currently Have No Network Connections"; } ?> I changed a few things too, just my $0.02: 1. include to require since config.php seems to be your db connection. You don't want to keep processing the page if you can't connect and require will stop. 2. move the check for no connections to before making the table. if you don't have any, no need to start trying. 3. few other little things. should be fairly obvious. Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546560 Share on other sites More sharing options...
revraz Posted May 21, 2008 Share Posted May 21, 2008 From the FAQ section http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546566 Share on other sites More sharing options...
jasonhardwick Posted May 21, 2008 Author Share Posted May 21, 2008 Thanks charlie and rev, I took charlies code and tried to implement it but I'm not seeing any results now. Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546593 Share on other sites More sharing options...
soycharliente Posted May 21, 2008 Share Posted May 21, 2008 I didn't test it. I just kind of wrote it. Is there any HTML being output? Or nothing? Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546594 Share on other sites More sharing options...
soycharliente Posted May 21, 2008 Share Posted May 21, 2008 Change this if (mysql_fetch_assoc($result3) > 0) to if (mysql_num_rows($result3) > 0) as a start. Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546596 Share on other sites More sharing options...
jasonhardwick Posted May 21, 2008 Author Share Posted May 21, 2008 thanks guys that worked... Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546614 Share on other sites More sharing options...
soycharliente Posted May 21, 2008 Share Posted May 21, 2008 No problem. Glad I could help. Quote Link to comment https://forums.phpfreaks.com/topic/106631-solved-display-php-return-in-a-table/#findComment-546674 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.