0

Hi Guys!

I want to know how to limit the no of records to be shown in dropdown list from mysql.Below is my code. I just want to list 4 records from colum name 'department_name'. The colum has 11 records in total.

<select class="ac" name="area" >
<?php
$qry = mysql_query("SELECT department_id, department_name FROM departments");
while($db = mysql_fetch_array($qry)){
?>
<option value="<?=$db['department_id']?>">
<?=$db['department_name']?>
</option>
<?php
}
?>
</select>

Plus want to know how to pull out the already stored vlaue for yes/no dropdown list and checkbox. I want to know php syntax. I can insert the values into database from my form but for edit page, I want the already stored value to be shown to users who intend to modify a user details.

Thanks

4
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by zia zia
0

also like this

SELECT department_id, department_name FROM departments LIMIT 4,0

I'm not sure what this is trying to achieve: return 0 rows, starting at the 4th offset (5th record). Stick with the first example. If you want a simple limit on the number of records returned (first 4 records for example) - just use the one value for the LIMIT keyword. However if you want to return 4 records, but starting at the third record:

SELECT department_id, department_name FROM departments LIMIT 2,4

Note '2' not '3' - this is because records start at Record #0.

Edited by diafol: n/a

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.