runnerjp Posted April 14, 2009 Share Posted April 14, 2009 im making a friends list for my profile page and want to display random friends on there profile like so 1 2 3 4 5 6 but i have no idea how to do this.... can any 1 help? Quote Link to comment https://forums.phpfreaks.com/topic/154031-solved-displaying-2-rows-of-results/ Share on other sites More sharing options...
MasterACE14 Posted April 14, 2009 Share Posted April 14, 2009 try something like... <?php session_start(); $query = mysql_query("SELECT * FROM `friends` WHERE `friendid`='".$_SESSION['userid']."'") or die(mysql_error()); $row = mysql_fetch_array($query); echo $row['friendid'][rand(1,count($row))]; ?> ...not entirely sure if that would work. Quote Link to comment https://forums.phpfreaks.com/topic/154031-solved-displaying-2-rows-of-results/#findComment-809682 Share on other sites More sharing options...
runnerjp Posted April 14, 2009 Author Share Posted April 14, 2009 ok i did this <?php require_once '../settings.php'; $q = mysql_query("SELECT friendname FROM friends WHERE username='Admin' ORDER BY friendname"); $count = mysql_num_rows($q); $results = array(); while ($line = mysql_fetch_array($q)) $results[] = $line; $split = ceil($count / 2); // then you can display it in a table echo "<table>"; for ($i = 1; $i <= $split; $i++) { $left = $i; $right = $i + $split; echo "<tr>"; echo "<td>{$results[$left][friendname]}</td>"; if ($right == $count) { // odd number of results (left column has the extra) echo "<td></td>"; } else { echo "<td>{$results[$right][friendname]}</td>"; } echo "</tr>\n"; } echo "</table>"; ?> but i only get runnerjp putputted even though my db loos like this id friendname username Edit Delete 25 runnerjp Admin Edit Delete 24 Admin runnerjp Edit Delete 23 Princessemma Admin Edit Delete 22 Admin Princessemma Quote Link to comment https://forums.phpfreaks.com/topic/154031-solved-displaying-2-rows-of-results/#findComment-809748 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.