list box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

list box

Post by shiranwas »

hi,

this is my coding to add dynamically to a list box

Code: Select all

<?php

function loadDept(){
include('Conn.php');
$sql="Select deptName from tblDepartments order by deptName";
$query=mysql_query($sql) or die ("Deparments can not be loaded.");
	while($row=mysql_fetch_assoc($query)){
		$arrDeparments[]=$row;
	}
foreach ($arrDeparments as $d) echo "<OPTION>{$d['deptName']}</OPTION>\n";
}
?>

<select name="cboDept" ><? loadDept() ?> </select>

when i do this the list box show the first value always in the text area of the list box even without selecting a value how to get rid from this since, sometimes i do not want to save the value from this list box.

thanks

shiran
webproject
Forum Newbie
Posts: 7
Joined: Mon Aug 07, 2006 4:07 pm

Post by webproject »

Hey shiran, you can always put a first "option" witch is empty =]

for example:

Code: Select all

<option value="">empty</option>
<option>value</option>
<option>value</option>
<option>value</option>
<option>value</option>
<option>value</option>
User avatar
shiranwas
Forum Commoner
Posts: 53
Joined: Fri Jul 07, 2006 10:41 pm
Location: Colombo

Post by shiranwas »

it works
thanks
Post Reply