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 ) <?php $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']; } print("<p><b>".$row['local_title']."</b></p>"); print("<p>".$row['local_desc']."</p>"); } } mysql_free_result($result); ?> 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.
1 Answer
to limit your result you have to use "Limit - MySQL Command"
Examples: This will display the first 10 results from the database. SELECT * FROM `your_table` LIMIT 0, 10This will show records 6, 7, 8, 9, and 10 SELECT * FROM `your_table` LIMIT 5, 5 Posted: MacOS 1 of 1 people found this answer helpful. Did you? Yes No |
© Advanced Web Core. All rights reserved