auto drop down list

Ask about general coding issues or problems here.

Moderators: egami, macek, gesf

Post Reply
celcomgirl
php-forum Active User
php-forum Active User
Posts: 29
Joined: Tue Sep 02, 2008 7:16 pm

Tue Sep 02, 2008 10:17 pm

i... i have another problem.... how to make drop down list auto select. for example i want select all event for year 2008 when i select s2008 the list of event for year 2008 will listed without need to click button search.before this i can make the selection. but only after i click search button.

Code: Select all

if (isset($_POST['year']))
{
	$year=$_POST['year'];
	
	if($year=='2008-')
	{
		$query = "SELECT * FROM cldr WHERE startDate  like '2008-%' and startDate like '%-01-%'";
		$result = mysql_query($query);
		$total = mysql_num_rows($result);	
	}
}

tq :help:
User avatar
gesf
Moderator
Moderator
Posts: 1716
Joined: Sun Dec 29, 2002 5:03 am
Location: Portugal / Sweden
Contact:

Thu Sep 04, 2008 2:51 am

Hey celcomgirl,

I'm not sure about what you're trying to accomplish... here goes an example anyways:

Code: Select all

<?php
// rest of the code

print "<select multiple="multiple">\n";
while($row = mysql_fetch_array($result)) {
     $extra = ($row['date'] == '2008') ? ' selected="selected"' : '';
     print '<option value="' . $row['whatever'] . '"'. $extra . '></option>' . "\n";
}
print "</select>\n";

// rest of the code
?>
Sincerely,
Gonçalo "gesf" Fontoura
Post Reply