Forum Moderators: coopster

Message Too Old, No Replies

how to display 3 mysql data in one html table row

         

abanana

9:40 pm on Dec 27, 2008 (gmt 0)

10+ Year Member



Hi all,

I'm tring to output a mysql table data and display them using html table. It's easy to display one data per row, but what I really need to display 3 different data in one html table row. I know it will need some kind of increment operator inside the While loop, could you please tell me how? thanks

henry0

10:10 pm on Dec 27, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This should do it if your data are coming from the same table
if not then you need a "join" query
but it calls for your tables to have some common grounds to perform a good or a few "WHERE"
to extract all required rows

// Here echo some table stuffs but no TD and TR

//$num= num of rows to work with
$num=mysql_numrows($result);

$i=0;
while ($i <$num)
{
$username= mysql_result($result,$i,"username");
$id= mysql_result($result,$i,"id");
$email= mysql_result($result,$i,"email");
echo"<tr>";
echo"
<td width='33%'>$username</td>
<td width='33%'>$id</td>
<td width='33%'>$email</td></tr>
";

$i++;
}
echo"</table>";

<edit>
You might want to review Extracting data from MySQL [webmasterworld.com]
</edit>

abanana

11:20 pm on Dec 27, 2008 (gmt 0)

10+ Year Member



thanks Henry0, sorry I didn't explain well. what I want to do is to display three different data in one table row, like:
<tr><td>username1, id1, email1</td><td>username2,id2, email2</td><td>username3, id3, email3</td></tr>, then next table row displays username 4, 5, 6 and so on. To put it another way, I want to display 3 rows of mysql table data into one html table row.

henry0

1:17 am on Dec 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



OK I see then what you need is called "pagination"
since you need to set a limit of what's displaid.
then go to the next one etc...

review Pagination [webmasterworld.com]

henry0

1:27 am on Dec 28, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The above might not be what you expect
I am thinking that you may try to set your query in the loop
but add LIMIT 3