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

Member Avatar for rajarajan2017

Query using Limit:

SELECT department_id, department_name FROM departments LIMIT 4

also like this

SELECT department_id, department_name FROM departments LIMIT 4,0
Member Avatar for diafol

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.

Thanks Guys... I've got the basic idea.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.