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:

Making a dynamic select option is actually quite simple

<SELECT>
<?
@ $db = mysql_connect("localhost", "smth", "smth");
mysql_select_db("database_name");
$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>";
}
?>
</SELECT>

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

<?php

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

if(!$link_id)
{
     echo "Connection Failed";
} 

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

$query = "SELECT * FROM tablename 
              WHERE
              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";

}

else

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

?>

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

ok thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.