How to display contents from mysql database in Order?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
ashfaqbinnazar
Forum Newbie
Posts: 5
Joined: Thu Apr 29, 2010 1:02 am

How to display contents from mysql database in Order?

Post 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>
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

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

Post 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>
?>
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

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

Post by rahulzatakia »

Hi, just give reply that it is working fine with you or not.
ashfaqbinnazar
Forum Newbie
Posts: 5
Joined: Thu Apr 29, 2010 1:02 am

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

Post by ashfaqbinnazar »

Wow,
its working..
Thanks alot brother.
but how can i stop displaying friends when it complete dispalying 3 columns and 3 rows ?
rahulzatakia
Forum Commoner
Posts: 59
Joined: Fri Feb 05, 2010 12:01 am
Location: Ahmedabad

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

Post 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..
Post Reply