Displaying data limit list

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
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Displaying data limit list

Post 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 :)
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post by Ward »

Code: Select all

select * from mos_content ORDER BY `id` DESC LIMIT 5
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

thats not working. I have tried that just there n doesnt work. its driving me crazy,
Ward
Forum Commoner
Posts: 74
Joined: Thu Jul 13, 2006 10:01 am

Post 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>";
}
blade_922
Forum Contributor
Posts: 132
Joined: Wed Jul 12, 2006 4:57 pm

Post by blade_922 »

thanks working :p
Post Reply