Page 1 of 1

Displaying data limit list

Posted: Thu Jul 13, 2006 3:58 pm
by blade_922
aarrghhh im goin mad, php is very long when you dont know alot.

Code: Select all

<?php

$content=mysql_query("select * from mos_content ORDER BY `id` DESC LIMIT 0,5") or die(mysql_error());
while ($donnee = mysql_fetch_array($content))
{ $title= $donnee['title'];  
  }
?>


<?php 
echo  $title;
echo "</br>";
?>


ok i have that, I am trying to display the last 5 titles added to the database. Only one title is appearing on the page. I think im missing something to make it show 5.

anyone help me out :)

Posted: Thu Jul 13, 2006 4:14 pm
by Ward

Code: Select all

select * from mos_content ORDER BY `id` DESC LIMIT 5

Posted: Thu Jul 13, 2006 4:17 pm
by blade_922
thats not working. I have tried that just there n doesnt work. its driving me crazy,

Posted: Thu Jul 13, 2006 5:25 pm
by Ward
Wait, I didnt even notice your loop. Each time through, it sets $title, effectively overwriting the last one. You need to either store the titles in an array, and loop through the array. You could also put your output code in the while loop, like this:

Code: Select all

$content=mysql_query("select * from mos_content ORDER BY `id` DESC LIMIT 0,5") or die(mysql_error());
while ($donnee = mysql_fetch_array($content))
{
     $title= $donnee['title'];
     echo $title;
     echo "<br>";
}

Posted: Thu Jul 13, 2006 6:09 pm
by blade_922
thanks working :p