Jump to content

array <br> difficulties ????


shorty3

Recommended Posts

i have this code

 

              <? 
$query_friends=mysql_query("SELECT * FROM friends WHERE username='$viewuser' AND type='Friend'");

$rows=mysql_num_rows($query_friends);
if ($rows == "0"){ echo "<center>No friends</center>"; }
$friend = 0;
while($dip=mysql_fetch_object($query_friends)){
echo ($friend % 3 == 0)? "<br>" : ""; 
echo "  <a href='profile.php?viewuser=$dip->person'>$dip->person</a>,"; 
$friend++; }
?>	

 

at the moment this code will do a <br> at the start and at the end but i want it only at the end

 

example what its doin now

 

[table border=1]

<- i dnt want the <br> here

username, username, username

username, username, username

 

this is what i want

 

[table border=1]

username, username, username

username, username, username

 

If This Dont Make Sense Then I Dont No What To Do Because The Table On This Doesnt Show Up

Link to comment
https://forums.phpfreaks.com/topic/201660-array-difficulties/
Share on other sites

Move the echo statement after the counter is incremented:

<?php
while($dip=mysql_fetch_object($query_friends)){
     echo "  <a href='profile.php?viewuser=$dip->person'>$dip->person</a>,"; 
     $friend++;
     echo ($friend % 3 == 0)? "<br>" : ""; 
}
?>

 

Ken

Link to comment
https://forums.phpfreaks.com/topic/201660-array-difficulties/#findComment-1057873
Share on other sites

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.