471,319 Members | 1,613 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,319 software developers and data experts.

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

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
3 1490
Markus
6,050 Expert 4TB
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
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
6,050 Expert 4TB
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.

Similar topics

17 posts views Thread by Newbie | last post: by
3 posts views Thread by ven | last post: by
2 posts views Thread by ven | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.