...

Simple quiestion...

HormonX
08-24-2002, 12:51 AM
well .. it's not that simple to me ... ok ... where it is ...

my problem is very simple .. am pulling some things from database and display them in the table. but i want only newest for example 5 items to appear. Well i did pull all the items form the database ... and that's cool, now how do i count them and stop after 5 items ?

can anyone help,

I have tried i think just about anything i could find and try.. and still could not get it right.

Please help me :) ...

Here is piece of code i have written up ...

----------------------------------------------


$query = "SELECT * FROM links ORDER BY id DESC";
$result = mysql_query( $query, $link );

while ($counter < 5)
{
while($r=mysql_fetch_array($result))
{
$cat=$r["cat"];
$url=$r["url"];

echo "<span class='body'><a href='http://$url' target='_blank'>$url</a> - $cat<br></span>";
}
$counter ++;
break;
}



--------------------------------

What am i doing wrong ?

thanks in advance :)

The Wizzard
08-24-2002, 12:56 AM
Use this...

mysql_query("SELECT * FROM links ORDER BY total DESC")

The Wizzard
08-24-2002, 12:58 AM
of course you have to have "total" in your database, someone else in here can help you from here, i am pretty weak past this point.

Spookster
08-24-2002, 01:11 AM
Ok for starters you obviously did not read the announcement I posted at the top of this forum. Post SQL questions in the MySQL forum.

http://www.codingforums.com/showthread.php?s=&threadid=4181


As for the answer to your question you simply need to use the LIMIT function.


$query = "SELECT * FROM links ORDER BY id DESC LIMIT 5";

And now I will move this thread to the proper forum.

HormonX
08-24-2002, 01:15 AM
thank you all for such prompt answers .. and to Spookster i thought it the answer would lie more in php than mysql thats why i posted here.

my appolgies.

HormonX



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum