...

View Full Version : Need code for Drop Down selections



librarygal
04-30-2008, 11:02 PM
I am trying to create a form that will display events in my db, either all events, select by type or select by agegroup. I just used a=href for my all events. I have drop down lists for type and agegroup displaying those options. However, I don't know how to direct my user if they choose from one of the drop down menus. Help!:eek::confused:



<?php
// Query for event name
$sql = <<<EOD

SELECT * from event
ORDER by eventid

EOD;

$result = mysql_query($sql) or trigger_error("sql=$sql; " . mysql_error(),E_USER_ERROR);

$events= array();
while ($row = mysql_fetch_assoc($result)) {
$events[] = $event;
}

// Query for age groups
$sql = <<<EOD

SELECT * from event_agegroup
ORDER by agegroupid

EOD;

$result = mysql_query($sql) or trigger_error("sql=$sql; " . mysql_error(),E_USER_ERROR);

$agegroups = array();
while ($agegroup = mysql_fetch_assoc($result)) {
$agegroups[] = $agegroup;

}


$sql = <<<EOD

SELECT * from event_type
ORDER by typeid

EOD;

$result = mysql_query($sql) or trigger_error("sql=$sql; " . mysql_error(),E_USER_ERROR);

$types = array();
while ($type = mysql_fetch_assoc($result)) {
$types[] = $type;

}
?>


<?php include 'header.php' ?>
<?php include 'style.css' ?>

<div id="pagecontent">

<h1>Upcoming Events</h1>
<a class="neweventbutton" href="event_form.php">[new event]</a>

</div>

<dl>
<dd><a href="events.php?event=*">all events</a></dd>

</dl>

<form method="get" action="">

<select name="agegroup">
<?php foreach ($agegroups as $agegroup): ?>
<option value="<?php echo $agegroup['agegroupid'] ?>">
<?php echo htmlentities($agegroup['agegroup']) ?>
</option>
<?php endforeach ?>
</select>
<button>go</button>


<select name="type">
<?php foreach ($types as $type): ?>
<option value="<?php echo $type['typeid'] ?>">
<?php echo htmlentities($type['type']) ?>
</option>
<?php endforeach ?>
</select>
<button>go</button>

</form>



<?php include 'footer.php' ?>

Inigoesdr
05-01-2008, 01:00 AM
You're going to have to use Javascript to redirect users based on their "select" choice. Or you could submit the form, use some logic to determine the destination, and then do a header() (http://php.net/header) redirect with PHP. Also, please remember to read the stickies for this forum. In particular the one about using
tags (http://www.codingforums.com/showthread.php?t=68462) when posting code.

rafiki
05-01-2008, 01:23 AM
I am trying to create a form that will display events in my db, either all events, select by type or select by agegroup. I just used a=href for my all events. I have drop down lists for type and agegroup displaying those options. However, I don't know how to direct my user if they choose from one of the drop down menus. Help!:eek::confused:



<?php
// Query for event name
$sql = <<<EOD

SELECT * from event
ORDER by eventid

EOD;

$result = mysql_query($sql) or trigger_error("sql=$sql; " . mysql_error(),E_USER_ERROR);

$events= array();
while ($row = mysql_fetch_assoc($result)) {
$events[] = $event;
}

// Query for age groups
$sql = <<<EOD

SELECT * from event_agegroup
ORDER by agegroupid

EOD;

$result = mysql_query($sql) or trigger_error("sql=$sql; " . mysql_error(),E_USER_ERROR);

$agegroups = array();
while ($agegroup = mysql_fetch_assoc($result)) {
$agegroups[] = $agegroup;

}


$sql = <<<EOD

SELECT * from event_type
ORDER by typeid

EOD;

$result = mysql_query($sql) or trigger_error("sql=$sql; " . mysql_error(),E_USER_ERROR);

$types = array();
while ($type = mysql_fetch_assoc($result)) {
$types[] = $type;

}
?>


<?php include 'header.php' ?>
<?php include 'style.css' ?>

<div id="pagecontent">

<h1>Upcoming Events</h1>
<a class="neweventbutton" href="event_form.php">[new event]</a>

</div>

<dl>
<dd><a href="events.php?event=*">all events</a></dd>

</dl>

<form method="get" action="">

<select name="agegroup">
<?php foreach ($agegroups as $agegroup): ?>
<option value="<?php echo $agegroup['agegroupid'] ?>">
<?php echo htmlentities($agegroup['agegroup']) ?>
</option>
<?php endforeach ?>
</select>
<button>go</button>


<select name="type">
<?php foreach ($types as $type): ?>
<option value="<?php echo $type['typeid'] ?>">
<?php echo htmlentities($type['type']) ?>
</option>
<?php endforeach ?>
</select>
<button>go</button>

</form>



<?php include 'footer.php' ?>
I need the code facebook and bebo and myspace use. plz post!

idalatob
05-01-2008, 09:18 AM
Hmm, what you are possibly looking for is javascript and the onClick handler.



<form method="get" name="redirect_1" action="age_groups.php">

<select name="agegroup">
<?php foreach ($agegroups as $agegroup): ?>
<option value="<?php echo $agegroup['agegroupid'] ?>">
<?php echo htmlentities($agegroup['agegroup']) ?>
</option>
<?php endforeach ?>
</select>
<button onclick="javascript: this.form.submit();">go</button>


<select name="type">
<?php foreach ($types as $type): ?>
<option value="<?php echo $type['typeid'] ?>">
<?php echo htmlentities($type['type']) ?>
</option>
<?php endforeach ?>
</select>
<button onclick="javascript: this.form.submit();">go</button>

</form>


If you want it to only send one get variable then just split the form into two elements. If you send the GET variables to the same page then use the header("location: whateverYouWant.php?etc=etc"); function...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum