By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
425,749 Members | 1,615 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 425,749 IT Pros & Developers. It's quick & easy.

MySQL display multiple rows in a table using PHP

P: 2
I was working on project page where I required to get the row data from mySql db in side the table cells. I knew how to use the php script to get the row data into the table cells like.

Id | Name | Exame | Nos
1 | Nasir | Maths | 25
2 | Abdulla | Maths | 50
3 | Fazalull | Maths | 41
4 | Jaraba | Maths | 05

But what If I want list of students in this order

List of Students4

Nasir | Abdulla
Fazalull | Jaraba


I couldn't do the multi rows even I search alot but couln't find a solution.
But then I found a solution by my self. So here how to do it may be it can help some buddy.

Lets create a table

[PHP]
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td></td>
<td></td>
</tr>

<?php
$query=" SELECT * FROM table order by id ASC";
$result=mysql_query($query);
echo mysql_error();
?>

<tr>

<?php while($ezkez = mysql_fetch_array($result)) { ?>

<td width="41%" ><a href="student.php?Name=<?php echo "$ezkez[Name]" ?>" class="sublink"><?php echo "$ezkez[Name]" ?></a></td>

<?php next($ezkez = mysql_fetch_array($result)); ?>

<td width="41%" ><a href="student.php?Name=<?php echo "$ezkez[Name]" ?>" class="sublink"><?php echo "$ezkez[Name]" ?></a></td>

</tr>
<?php
}

$anymatches=mysql_num_rows($result);
if ($anymatches == 0)
{
?>
<tr >
<td class="sublink" colspan="2" align=left><div align='center'><b>Sorry, no record found</b></div></td>
</tr>

<?php
}
?>
<tr>
<td></td>
<td></td>
</tr>
</table>[/PHP]
Jan 24 '08 #1
Share this Question
Share on Google+
1 Reply


Markus
Expert 5K+
P: 6,050
You would post this in the 'howtos' section, as this is for questions ;)

Also, that code is ok but not great as you are constantly opening and closing the php parser.

take a look here.

I had the same problem once and pbmods helped me out greatly.
Jan 24 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.