Solved

Output data side by side in a tabular way

Posted on 2011-03-22
4
248 Views
Last Modified: 2013-12-13
Most explanation are included with the code excerpt
I would like getting three sets of each $un and $thumb_name side by side
then go to the next three
etc... etc...
This output data one one after the other one in a vertical table organized way

$num=$db->num_rows($result3);
$i=0;
while ($i <$num)
{	
	$un=mysql_result($result3,$i,"username");
	$thumb_name=mysql_result($result3,$i,"thumb_name");
	echo"<tr><td>$un</td><td>$thumb_name</td></tr>";
	
$i++;
}

What I am looking for is:
echo"<tr><td>$un</td><td>$thumb_name</td><td>$un</td><td>$thumb_name</td><td>$un</td><td>$thumb_name</td></tr>";	
where results will show three sets at a time side by side
then jump to the next three set etc...
and taking care of left over from $i%3 if it comes to an odd number
but I do not figure how to do that

Open in new window

0
Comment
Question by:array007
  • 3
4 Comments
 
LVL 14

Accepted Solution

by:
Scott Madeira earned 500 total points
ID: 35189627
Try this:

 
$num=$db->num_rows($result3);
$i=0;

// Start the first row
echo '<tr>';

while ($i <$num)
{	
	$un=mysql_result($result3,$i,"username");
	$thumb_name=mysql_result($result3,$i,"thumb_name");
	        
        // Spit out the data
	echo"<td>$un</td><td>$thumb_name</td>";
	if ( (( $i+1)%3) ==0 ) {
		// End of row
		echo '</tr>';
	} 


$i++;
}

if (! $i%3) {
    // Clean up last partial row
    echo '</tr>';
}

Open in new window


You may need to play with the last if statement to make sure it ends the row for partial cases.
0
 
LVL 1

Author Comment

by:array007
ID: 35189758
Thanks
But it is still outputting one above the other one
as:
<tr><td>aaa</td><td>bbb</td></tr>
<tr><td>aaa</td><td>bbb</td></tr>

instead of three results side by side as:

<tr><td>$un</td><td>$thumb_name</td> <td>$un</td><td>$thumb_name</td> <td>$un</td><td>$thumb_name</td></tr>
<tr><td>$un</td><td>$thumb_name</td> <td>$un</td><td>$thumb_name</td> <td>$un</td><td>$thumb_name</td></tr>

etc....
0
 
LVL 1

Author Comment

by:array007
ID: 35190696
Any idea on how to fix it?
0
 
LVL 1

Author Closing Comment

by:array007
ID: 35193937
I cleaned my OWN code error and now
it works fine
thanks
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
This article discusses how to create an extensible mechanism for linked drop downs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

920 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now