Jump to content

retrieve top 5 most recent added entries in sql table?


H-Fish

Recommended Posts

i\'ve got an id field, but do i like put id field 1 in there.....

 

heres a what my table looks like from phpmyadmin

 

sql.gif

 

btw you can see it at www.clansr.co.uk/cs/hctabs

 

it just a little selection of scripts where me and my friends can share guitar tabs

Link to comment
Share on other sites

cheers i did it with this code

 


  ///////// READS INFO FROM DATABASE  ///////

mysql_connect("localhost","clanrryoy","");

@mysql_select_db($DB_DBName) or die( "Unable to select database");

$query="SELECT artist, title FROM tabs order by id desc limit 5";

$result=mysql_query($query);



$num=mysql_numrows($result);



$i=0;

while ($i < $num) {



$artist=mysql_result($result,$i,"artist");

$title=mysql_result($result,$i,"title");



?>

<? // ADDS READ DATA INTO PAGE ?>

<p> </p>

<div align="center">

<p><? echo "$artist"; ?><br>

   <? echo "$title"; ?> 



<?

++$i;

}





echo "</table>";

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.