Page 1 of 1

How to display contents from mysql database in Order?

Posted: Thu Apr 29, 2010 1:05 am
by ashfaqbinnazar
This is a part of a Social community that i am going to build in php.
This is same as the My friend list frame in Orkut,facebook etc.
how can i display the content in mysql database order by 3 colums and 3 rows.
Please help me...
Thanks in advance.
here is my code of my friends frame
userreg is the table name
id<>$id means-select all id of users except the logged persons id.

Code: Select all

My Friends</h3>
<table width="29%" height="277" border="1">
<?php $result= mysql_query("SELECT * FROM userreg where id<>'$id'")
or die(mysql_error());
$count3=mysql_num_rows($result);
while($count3>0)
{
$count3--;
$row4= mysql_fetch_array($result);
$y=$row4['username'];
$id=$row4['id'];
$toid=$id;
?>
<tr>
<td height="89">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td height="89">&nbsp;</td>
<td>&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td width="35%" height="89">
<?php
echo "<a href='scrapbook.php?toid=$toid'>$y</a>";
?> </td>
<td width="33%">&nbsp;</td>
<td width="32%">&nbsp;</td>
</tr>
<?php }?>
</table>

Re: How to display contents from mysql database in Order?

Posted: Thu Apr 29, 2010 5:12 am
by rahulzatakia
Hi, you can try out the following code and i am sure you will get your output. And if you have any query in this please be free to ask...

Code: Select all

My Friends</h3>
<table width="29%" height="277" border="1">
<?php $result= mysql_query("SELECT * FROM userreg where id<>'$id'")
or die(mysql_error());
$count3=mysql_num_rows($result);
$i = 0; $j = 0;
while($count3>0 && $j < 3)
{
$count3--;
$row4= mysql_fetch_array($result);
$y=$row4['username'];
$id=$row4['id'];
$toid=$id;
if($i % 3 == 0)
{ ?> <tr> <?} ?>
<td width="35%" height="89">
<?php
echo "<a href='scrapbook.php?toid=$toid'>$y</a>";
?> </td>
<?php $i++; if($i % 3 == 0) { print "</tr>";  $j++; } }?>
</table>
?>

Re: How to display contents from mysql database in Order?

Posted: Fri Apr 30, 2010 2:07 am
by rahulzatakia
Hi, just give reply that it is working fine with you or not.

Re: How to display contents from mysql database in Order?

Posted: Fri Apr 30, 2010 7:38 am
by ashfaqbinnazar
Wow,
its working..
Thanks alot brother.
but how can i stop displaying friends when it complete dispalying 3 columns and 3 rows ?

Re: How to display contents from mysql database in Order?

Posted: Fri Apr 30, 2010 9:29 am
by rahulzatakia
Hi..
It will only display 3 columns and 3 rows after that it will stop..
I have tested it.. and if you find any problem then let me know..