Jump to content

[SOLVED] showing friends images in two colums


runnerjp

Recommended Posts

here is my script

 

<? include'../../settings.php';

$sql="SELECT friends.friendname, users.image FROM friends INNER JOIN users ON (users.friendname=friends.friendname) WHERE friends.username='Admin' GROUP BY friends.friendname ORDER BY users.friendname ";

// Showing
$res = mysql_query($sql) or die(mysql_error());
echo '<table><tr><th>Name</th><th>Picture</th></tr>'; 

while($row = mysql_fetch_assoc($res)){
  echo "<tr><td>" . $row['friendname'] . "</td><td><td>". $row['image"] ."</td></tr>";
}
echo "</table>"; 

?> 

 

but i would like to change it as users only have 1 profile picture and i would like to have it like this

 

Untitled.jpg

try this

$sql="SELECT friends.friendname, users.image FROM friends INNER JOIN users ON (users.friendname=friends.friendname) WHERE friends.username='Admin' GROUP BY friends.friendname ORDER BY users.friendname ";

// Showing
$res = mysql_query($sql) or die(mysql_error());
define('NUMCOLS', 3);	
	$count = 0;
	$counter = 1;
echo '<table><tr><th>Name</th><th>Picture</th></tr>'; 

while($row = mysql_fetch_assoc($res)){
	if($count % NUMCOLS == 0)
	echo '<tr>';
	echo '<td>';
   		echo "<tr><td>" . $row['friendname'] . "</td><td><td>". $row['image'] ."</td></tr>";

	$count++;
	$counter++;
	if($count % NUMCOLS == 0)
	echo '</tr>'; //end row
}
echo "</table>"; 

$sql="SELECT friends.friendname, users.image FROM friends INNER JOIN users ON (users.friendname=friends.friendname) WHERE friends.username='Admin' GROUP BY friends.friendname ORDER BY users.friendname ";

// Showing
$res = mysql_query($sql) or die(mysql_error());
define('NUMCOLS', 2);	
	$count = 0;
	$counter = 1;
echo '<table><tr><th>Name</th><th>Picture</th></tr>'; 

while($row = mysql_fetch_assoc($res)){
	if($count % NUMCOLS == 0)
	echo '<tr>';
	echo '<td>';
   		echo $row['friendname'] . "<br />". $row['image'] ."</td>";

	$count++;
	$counter++;
	if($count % NUMCOLS == 0)
	echo '</tr>'; //end row
}
echo "</table>"; 

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.