Hi all,

I'm trying to build a new search system for one of my sites. The idea is something like this:

1. Visitors choose something in dropdown1 (ex. seach staff, search students, seach grades) - all these choises should be extracted from mySQL db and could be updated from time to time with more or less values.
2. Depending of choise a dropdown2 should appear (ex. if the visitor choose search staff it will present search women, search men but if search grades are selected it will present search best grades, search medium grades, search bad grades) - all these choises should be extracted from mySQL db aswell
3. Depending of choise a dropdown3 should appear (ex. if visitor in dropdown1 choose search staff and in dropdown2 women it will show search in area1 and area3 - area2 and area4 will not appear becourse no women staffmembers are registered in those two areas).

I know it sounds very confusing but I think it'll make my users day much easier. My problem though is how to extract these data from mysql to the option fields in my code. I suppose that I'll need to use PHP as javascript is not able to communicate with mySQL by itself. But how to do it. I can't know how many option fields needed - that is different from time to time depending of what it finds in the database.

Anyone able to help me out in this for me quite advanced quest :rolleyes:

11 Years
Discussion Span
Last Post by ChiNko5

Making a dynamic select option is actually quite simple

@ $db = mysql_connect("localhost", "smth", "smth");
$strSQL = "SELECT * FROM select1options ORDER BY name";
$rs = mysql_query($strSQL);
$nr = mysql_num_rows($rs);
for ($i=0; $i<$nr; $i++) {
	$r = mysql_fetch_array($rs);
	echo "<OPTION VALUE=\"".$r["name"]."\">".$r["name"]."</OPTION>";

You could then make similar code for the next select option based on the submit value of this one.


$link_id = mysql_connect("localhost","username","password");

     echo "Connection Failed";

mysql_select_db("databasename",$link_id); // here write db name

$query = "SELECT * FROM tablename 
              filedname = '$listboxname' OR 
              filedname = '$listboxname' OR
              filedname = '$listboxname' "; // 

$result = mysql_query($query,$link_id);

$check = mysql_num_rows($result);

if($check <= 0 )


  echo "Result not found";



while($rows = mysql_fetch_object($result))
      echo $rows->feildname;
      echo $rows->feildname;
      echo $rows->feildname;
      echo $rows->feildname;


Edited by pyTony: fixed formating


hey, to the poster, i jut have a question on the type of project you're working on because im doing osmething simliar

if you wouldnt midn if i asked you a few questions, my email is
O_Nassar AT Hotmail DOT com

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.