Have an account? Sign in
Login  Register  Facebook
How to display at least 10 data from MySQL Database?
Hi Guys,

Can anyone help me out about displaying 10 data from my database?My codes goes like this. I have 4 fields (id, local_title, local_desc, local_date )

$last_date = "";
$result = mysql_query("SELECT * FROM tbl_localnews ORDER BY local_date DESC"); 

	while ($row = mysql_fetch_array($result)) {
	for($i=0; $i<10; $i++){
    if ($row['local_date'] != $last_date) {
        print("<h2>News for ".date('F j, Y',strtotime($row['local_date']))."</h2>");
        $last_date = $row['local_date'];


It was arrange by date. If the dates similar it will display in one category. I want to display at least 10 data from my database. But my code doesn't work. Can Anyone help me out?Thanks.
Started: September 22, 2011 Latest Activity: September 22, 2011 phpdatabase
1 Answer
to limit your result you have to use "Limit - MySQL Command"
This will display the first 10 results from the database.
 SELECT * FROM `your_table` LIMIT 0, 10 
This will show records 6, 7, 8, 9, and 10
 SELECT * FROM `your_table` LIMIT 5, 5 

Posted: MacOS
In: September 22, 2011

Your Answer

xDo you want to answer this question? Please login or create an account to post your answer