cascading dropdown menus

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • yo123
    New Member
    • May 2007
    • 1

    cascading dropdown menus

    Hello everyone:
    I need to make a dropdown menu that shows information depending on what the user chooses in the first one. I am using PHP and MySql.
    I am new!

    I looked for tutorials and I am trying to understand the code... however it is not clear enough. I will say what I understand so you can tell me where I am wrong.
    [CODE=php]
    <?PHP
    require_once('c onnection.php') ;
    require_once('o pen_db.php');

    $query1=mysql_q uery("SELECT Route_From as Desde FROM route") or die(mysql_error ());
    $query2=mysql_q uery("SELECT * FROM route WHERE Route_From=".$_ POST["Desde"]."&quot;") or die(mysql_error ());
    ?>

    <form name="check" method="post">
    <!-- First Drop Down starts here -->
    <select name="select1" onchange="this. form.submit()">
    <?PHP
    while ($row = mysql_fetch_ass oc($query1))
    {
    echo ("<option>{$ row['Route_From']}</option>");
    }
    ?>
    </select>

    <?PHP
    if (isset($_POST["select1"]))
    ?>
    <select name="select2">
    <?PHP
    while($row = mysql_fetch_ass oc($query2))
    {
    echo("<option>{ $row['Route_To']}</option>");
    }
    ?>
    </select>
    </form>
    [/CODE]
    Ok, so what I understand is:
    - I connect to MySql (that works fine)
    - I create the queries
    - I create the first menu and start filling it up and with the "onchange", when a user selects an option, what he chose is submitted.
    - When the first option is submitted, this info is captured with:
    <?PHP
    if (isset($_POST["select1"]))
    ?>
    - The the second query is done and the second menu is filled.

    When I execute the page the error that is shown is the following:
    You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"' at line 1

    I hope someone can help me!
    Bye
    Last edited by Atli; May 15 '07, 04:05 AM. Reason: Added code tags
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Replace this line and let me know the status.

    [PHP]$query2=mysql_q uery('SELECT * FROM route WHERE Route_From='.$_ POST['Desde'].'') or die(mysql_error ());[/PHP]

    Comment

    • rohitsavalia
      New Member
      • Apr 2007
      • 8

      #3
      Just replace your $query2 line with this :

      $query2=mysql_q uery("SELECT * FROM route WHERE Route_From='".$ _POST["Desde"]."'") or die(mysql_error ());

      Comment

      • wish
        New Member
        • May 2007
        • 65

        #4
        Hello,
        I had faced same problem..if user select the item in <select> then the below got one textarea to display the description of item..what should i write the code..

        from <select> i retrieve all the item from db and then i want based on the user select the item then show the description of the item that what user was selected..

        Can some one guide me...

        Comment

        • ak1dnar
          Recognized Expert Top Contributor
          • Jan 2007
          • 1584

          #5
          wish,
          After getting the result set row values print it in side the teaxarea.

          [PHP]<textarea name="descripti on" cols="5" rows="5"><? echo $the_descriptio n ?></textarea>[/PHP]

          Comment

          • wish
            New Member
            • May 2007
            • 65

            #6
            Thank you my friend...
            One problem is settle but another problem prompt out..
            because based on the above example, the <form name="change" method="post"> the action property is no use then when i click button to submit..it can not work..if i add action property in the form tag then when i select the item then it direct go to another page...then what should i write the code...

            Can you guide me again..

            Comment

            • ak1dnar
              Recognized Expert Top Contributor
              • Jan 2007
              • 1584

              #7
              Originally posted by wish
              Thank you my friend...
              One problem is settle but another problem prompt out..
              because based on the above example, the <form name="change" method="post"> the action property is no use then when i click button to submit..it can not work..if i add action property in the form tag then when i select the item then it direct go to another page...then what should i write the code...

              Can you guide me again..
              Its better to post a new thread for this question,Its not a good idea to continue with this tread here after.because this is not related to the thread of yo123.

              Comment

              Working...