View Full Version : Organizing database output.

10-31-2007, 02:21 AM
How do I format my data into a table?
This sounds simple enough but I can't figure it out.

You see I've got a lot of table space to use, but can't get the data to format into only a few table rows.
The code I'm using now looks like this:

$result1 = mysql_query ('select * from friends where p_id="'.$user_id.'" order by uf_id desc limit '.$f_num.'') or dbError();
$fc =1;


while($fr = mysql_fetch_assoc($result1))
echo' <tr>';
echo '<td '.getColor($fc).'><a class="usnav" href="'.$url.'/eldemonio/profiles/'.$fr['username'].'.php">'.$fr['username'].'</a></td>';
echo' </tr>';

I'd like that code above too be able to out put that same variable about three times or so with in the same <tr> but I want it to be the next one in line after the first one.
So it would end up like so:

name1 / name2/ name3/

Sure thats simple to do also, but how do i get it to create new row after the first three names?

Hope I was clear enough for you guys to get what I mean, this ones kinda complicated for me.

10-31-2007, 02:31 AM
while($fr = mysql_fetch_assoc($result1)){
if ($fc == 1) echo ' <tr>';

// Removed this to make it easier to see

if ($fc == 3){
echo ' </tr>';
$fc = 0;
if ($fc != 1) echo ' </tr>';

10-31-2007, 06:12 AM
Thanks very much. That did the job just right. :)