#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0

    query multiple selection boxes


    Hello everyone,

    I have been trying to struggle throughthis database thing for like 3 months, I am desperate for help.

    What I am wanting is a 2 dynamically populated selection boxes (drop down menus) to query with one submit button, basically a query in a query I guess.

    I can get one box at a time to work but not both at the same time with them on the same page.
    This is what I can get to work............

    $query = "SELECT DISTINCT vehicle_Make FROM Engines";
    $result = mysql_query($query)
    or die ("Couldn't execute query.");

    echo "<form action='process.php' method='post'>
    <select name='vehicle_Make'>\n";
    while ($row = mysql_fetch_array($result))
    {
    extract($row);
    echo "<option value='$vehicle_Make'>$vehicle_Make\n";
    }
    echo "</select>\n";
    echo "<input type='submit' value='Search'>
    </form>\n";


    But for the life of me I can not get it to work when I attempt to add a query to it. The second query I am wanting to add is "engine_Cid" I can get it to work by its self as well just not with both vehicle_Make and engine_Cid at the same time.

    I am very new to all this so please be descriptive I have read many other posts where people ask questions and the replies I don't understand so I am very php illiterate!

    Thanks so much everyone.
  2. #2
  3. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    18
    It might be useful for us to see the code which does not work and any errors etc. which you get then, since your description of the second query is verbal but hardly verbous enough.


    [edit]Edited for less grammar.[/edit]
    Last edited by realnowhereman; December 29th, 2003 at 06:32 AM.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0
    Thanks for your reply I really do appreciate any help.

    Well here is one of the hundreds of things I have tried. Please don't think I am complete dummy if it seems completely impossible.


    $query = "SELECT DISTINCT vehicle_Make FROM Engines";
    $result = mysql_query($query)
    or die ("Couldn't execute query.");

    echo "<form action='process.php' method='post'>
    <select name='vehicle_Make'>\n";
    while ($row = mysql_fetch_array($result))
    {
    extract($row);
    echo "<option value='$vehicle_Make'>$vehicle_Make\n";
    }

    $query = "SELECT DISTINCT engine_Cid FROM $Engines";
    $r = mysql_query($query)
    or die ("Couldn't execute query.");

    <select name='engine_Cid'>\n";
    while ($row2 = mysql_fetch_array($))
    {
    extract($row2);
    echo "<option value='$engine_Cid'>$engine_Cid\n";

    }

    echo "</select>\n";
    echo "<input type='submit' value='Search'>
    </form>\n";
    ?>


    Any help at all is appreciated I just feel completely over my head here. I have thought about trying to start over with something like perl but I just hate to think of everything I have learned being for nothing, and having to start back at square one somewhere else. That and I hate defeat. ..

    Thanks again sooo much!!
  6. #4
  7. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    18
    What happens if you remove the $ in front of Engines in the second query?
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0

    blank page still


    Oops I didn't mean to put that there nor realize it was there. But with that gone it still does nothing just returns a blank page.
  10. #6
  11. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    18
    Do you get anything if you view the source of the page in your browser?
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0

    blank


    no just the blank html tags, I don't get any errors
  14. #8
  15. No Profile Picture
    Not there when you need me
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Oct 2001
    Location
    Berlin, Germany
    Posts
    1,430
    Rep Power
    18
    Is the PHP code executed at all, then?
  16. #9
  17. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Location
    Hampshire
    Posts
    266
    Rep Power
    15
    You sure there is anything in the database?
  18. #10
  19. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0

    I am sure


    Yeah I am sure, if I run either one of the queries seperately I can get them to work. Like this one for the vehicle makes works fine by itsself, well besides the bad text formatting, ha ha. But the other query for engine_Cid works by itsself as well.
  20. #11
  21. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    20
    Rep Power
    0
    So the reason why this code isn't working is because you don't have a </select> for vehicle_Make. As well as a variety of typos. :P



    [QUOTE]Originally posted by zayin7232


    Code:
    $query = "SELECT DISTINCT vehicle_Make FROM Engines";
    $result = mysql_query($query) 
    or die ("Couldn't execute query."); 
    
    if (mysql_error()) {
       echo 'Error '.mysql_error();
       die();
    }
    
    echo '<form action="process.php" method="post">'."\n";
    echo '<select name="vehicle_Make">'."\n";
     
    while ($row = mysql_fetch_array($result)) { 
      extract($row); 
      echo '<option value="'.$vehicle_Make.'">'.$vehicle_Make."\n"; 
    } 
    
    echo '</select>'."\n";
    
    $query = "SELECT DISTINCT engine_Cid FROM Engines";
    $r = mysql_query($query) 
    or die ("Couldn't execute query."); 
    
    if (mysql_error()) {
       echo 'Error '.mysql_error();
       die();
    }
    
    echo '<select name="engine_Cid">'."\n"; 
    while ($row2 = mysql_fetch_array($r)) { 
       extract($row2); 
       echo '<option value="'.$engine_Cid.'">'.$engine_Cid."\n"; 
    } 
    
    echo "</select>\n"; 
    echo '<input type="submit" value="Search">'."\n"; 
    echo '</form>'."\n"; 
    ?>
    Code:
    
    
    Denise
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0

    Smile You just made my day!!


    IT WORKS!! Thanks so much you have no idea how releived and happy i am right now. This has been my nightmare for what seems like forever. I have one more question if you don't mind??? How would I make it where they could leave one of the selections empty if needed and it to query just the one they selected?

    Thank You again
  24. #13
  25. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2003
    Posts
    20
    Rep Power
    0
    For that you get much more complicated. You need javascript.

    Go to http://www.mattkruse.com
    Go to the Javascript section
    Download Dynamic Option List

    This script is kinda a pita to set up, but it works really well.
    The thing that you have to remember is that the section at the beginning is COMMENTED OUT, so don't just replace the text there with your own variables because it won't work. Add a new section at the bottom of the script or after */ and before //CONSTRUCTOR.

    If you can't figure it out post here again and I'll check back, but make a good effort first. It's not toooo complicated.

    Denise
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    kansas
    Posts
    13
    Rep Power
    0

    Thank You


    I just wanted to say Thank you again, I will attempt the next phase so wish me luck.

    I appreciate your help very much Thanks again

IMN logo majestic logo threadwatch logo seochat tools logo