Jump to content

PHP code for selecting from drop down box


librarygal

Recommended Posts

I want to direct the user to correct list depended on which dropdox box/selection they make. Clueless.  :'(

 

 

// 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' ?>

 

Try to ve more verbose and specific about your problems, It's hard to guess if so little information is given.

 

Looking at your code It looks like you want to display a list of $events picked according to the $type and $agegroup selected in the drop menus.

 

I see your form is also using the GET attribute, so the variables are sent in the $_GET array to the action page defined in the form (which is empty)... In that action page you must define a query according to the $_GET['agegroup'] and $_GET['type'] variables you passed from the form.

 

There's really not much to say if you don't provide more info, like the database structure, or the page that recieves the submited form, for example.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.