jakeoh Posted October 21, 2007 Share Posted October 21, 2007 Hi, I have a section on my page where I want to display the avatar and name of users currently logged on. The following code works perfect, but I want to format it a certain way and do not know how; in this section I would like to display each entry (avatar + username) in a 2 column table: User #1 User #2 User #3 User #4 Here's the code I have right now, which will display the users one after the other in a single column table: elseif($num_rows > 0){ /* Display active users, with link to their info */ echo "<table width=\"213\" align=\"left\" border=\"0\" cellspacing=\"0\" cellpadding=\"3\">\n"; echo "<tr><td><font size=\"2\">\n"; for($i=0; $i<$num_rows; $i++){ $uname = mysql_result($result,$i,"username"); $avatarQuery = "SELECT avatarID, last_name, first_name FROM ".TBL_USERS." WHERE username = '$uname'"; $resultAvatar = $database->query($avatarQuery); $uAvatar = mysql_result($resultAvatar, 0); $first_name = mysql_result($resultAvatar, 0, "first_name"); $last_name = mysql_result($resultAvatar, 0, "last_name"); $initial = $last_name[0]; echo '<img src="get_avatar.php?pid='.$uAvatar.'"width="60" height="60">'; echo "<br>"; echo "<a href=\"userinfo.php?user=$uname\">$first_name $initial</a>"; echo "<br>"; echo "<br>"; } echo "</font></td></tr></table><br>\n"; } How can I format the info in two columns? Quote Link to comment https://forums.phpfreaks.com/topic/74223-solved-displaying-results-of-a-query-in-two-columns/ Share on other sites More sharing options...
pocobueno1388 Posted October 21, 2007 Share Posted October 21, 2007 Take a look at this post http://www.phpfreaks.com/forums/index.php/topic,95426.0.html Quote Link to comment https://forums.phpfreaks.com/topic/74223-solved-displaying-results-of-a-query-in-two-columns/#findComment-374915 Share on other sites More sharing options...
chronister Posted October 21, 2007 Share Posted October 21, 2007 Here is another way to do it.. This is a Karaoke Song List that is displayed in 2 colums. <?php $result = mysql_query("SELECT * FROM tracks ORDER BY artist,track LIMIT $offset, $setlimit "); while($row = mysql_fetch_object($result)) { $track[]='$row->artist .' -- '. $row->track; // I set each result in an array called $track[] }; ?> <table width="90%" align="center" cellpadding="5" cellspacing="0"> <tr><td colspan="2" align="right" class="smaller">Showing Page <?=$page ?> of <?=$pages ?></td> </tr> <? $x=0; $row_count = "0"; while($x < count($track)) { $row_color = ($row_count % 2) ? $color1 : $color2 ; ?> <tr bgcolor="<?=$row_color ?>" align="left" valign="middle"> <td height="20" > <?=$track[$x++] ?><!-- First Column --> </td> <td height="20" ><?=$track[$x++] ?><!--Second Column --></td> </tr> <? $row_count++; } ?> </table> To me this is easier, Loop through the results and turn it into an array with all the results, then do another loop to display it in columns. Nate Quote Link to comment https://forums.phpfreaks.com/topic/74223-solved-displaying-results-of-a-query-in-two-columns/#findComment-374937 Share on other sites More sharing options...
jakeoh Posted October 23, 2007 Author Share Posted October 23, 2007 Thanks, that lead me to the solution! Quote Link to comment https://forums.phpfreaks.com/topic/74223-solved-displaying-results-of-a-query-in-two-columns/#findComment-375924 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.