Jump to content

[SOLVED] displaying 2 rows of results


runnerjp

Recommended Posts

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.

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.