By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,350 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,350 IT Pros & Developers. It's quick & easy.

Select statement using a second select statement from same input page to gather info

P: 36
Hey guys I have been checking the forum for a way to populate a second select field depending on the choice made from the first one. Basically i am working on projects and the delays that occur. The first select is project and i am asking user to select it by using

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.           $sql = "SELECT ProjectName
  3.                   FROM   ProjectDetails";
  4.                  "ORDER BY ProjectName";
  5.                 $rs = mysql_query($sql);
  6.                 while($row = mysql_fetch_array($rs))
  7.                 {
  8.                   echo "<option value=\"".$row['ProjectName']."\">";
  9.                 }
  10. ?>
  11.  
then for my second select statement i want it to be populated by using

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.                 $sql = "SELECT Task
  3.                         FROM   Delay
  4.                         WHERE  ProjectName = (the problem) ".
  5.                        "ORDER BY Task";
  6.                 $rs = mysql_query($sql);
  7.                 while($row = mysql_fetch_array($rs))
  8.                 {
  9.                   echo "<option value=\"".$row['Task']."\">";
  10.                 }
  11. ?>
  12.  
I have seen a forum that says to use AJAX (http://bytes.com/forum/thread790663.html) but i dont have enough time to learn this. Is it possible to call the result found from the first select as a variable so i can then use it in the second query? where (the problem) = var1?

Any1 any ideas on this?
Sep 16 '08 #1
Share this Question
Share on Google+
3 Replies


Markus
Expert 5K+
P: 6,050
If you don't want a page refresh, you're going to have to learn AJAX (It seriously takes no longer than 1 hour to learn.) Otherwise, you will have to submit the dropdown list to the same page (as a form - using GET possibly) and then $_GET the selected projectName and use this in your second WHERE clause to show the related projects.
Sep 16 '08 #2

P: 36
thanks for the quick reply appreciated. Ill have another look at some tutorials on AJAX if u say it easy to understand. Thanks for clarifying it.
Sep 16 '08 #3

Markus
Expert 5K+
P: 6,050
thanks for the quick reply appreciated. Ill have another look at some tutorials on AJAX if u say it easy to understand. Thanks for clarifying it.
No problem. Once you've had a go, post the code you used (if you have a problem with it) and we'll give you more help!
Sep 16 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.