Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2008
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Need code for Drop Down selections

    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!

    PHP Code:
    <?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' ?>
    Last edited by Inigoesdr; 04-30-2008 at 11:57 PM.

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    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() redirect with PHP. Also, please remember to read the stickies for this forum. In particular the one about using [php][/php] tags when posting code.

  • #3
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    Quote Originally Posted by librarygal View Post
    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!

    PHP Code:
    <?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!

  • #4
    Regular Coder
    Join Date
    Sep 2007
    Location
    Grahamstown, South Africa
    Posts
    237
    Thanks
    6
    Thanked 17 Times in 17 Posts
    Hmm, what you are possibly looking for is javascript and the onClick handler.

    PHP Code:
    <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...
    Last edited by idalatob; 05-01-2008 at 08:20 AM.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •