Hi! I have a table.. Structure is: -- -- Table structure for table `database` -- CREATE TABLE `database` ( `ID` varchar(255) default NULL, `Quote` varchar(255) default NULL, `Name` varchar(255) default NULL, KEY `Name` (`Name`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1; PHP: And for example few entries.. INSERT INTO `database` VALUES ('12714', '"Do what thou wilt" shall be the whole of the law.', 'Aleister Crowley'); PHP: I'm using this code, to call my database values into my site. $result = mysql_query("SELECT * FROM database ORDER BY ID") or die(mysql_error()); echo "<table border='0'>"; echo "<tr> <th>ID</th> <th>Quote</th> <th>Author</th> </tr>"; while($row = mysql_fetch_array( $result )) { echo "<tr><td>"; echo $row['ID']; echo "</td><td>"; echo "<cite>".$row['Quote']."</cite>"; echo "</td><td>"; echo $row['Name']; echo "</td></tr>"; } PHP: It throws me all entries in one page.. Can i have for example 10 entries in one page, and 10 in the other & so on... thanks in advance
SELECT * FROM database ORDER BY ID LIMIT 0 , 10 would show you the first 10 SELECT * FROM database ORDER BY ID LIMIT 10 , 10 would show you the next 10 and so on.
The above method is OK for small database. For a larger database, it will have performance problems. I suggest you always save the id first and the last record of each page and then use where id > last_id order by id limit 10 , same idea for paging the other way.
$max=50; if (!$page) $page=1; $alt=($page - 1) * $max; $q=mysql_query("Select * from home where cat ='2' order by hit desc limit $alt,$max"); $r= mysql_fetch_array($q); PHP: this like 123456789 <? $ss=$nr2/$max; $ss=ceil($ss); for ($i=1;$i<=$ss;$i++) { if ($page == $i) echo "<FONT class=\"link2 underline ucwords\">$i</font> "; else echo "<A href=$site/cat/$id-$i.html>[$i]</A> "; } ?> PHP: Before I learn I looked for it to much. and I want to share it