Mysql database to listbox need help
1.<html>
2. <head>
3. <title>List Box Form Data</title>
4. </head>
5. <body>
6. <p>Form data passed from the form</p>
7. <?php
8. require("./resources/globals.php") ;
9. $query="SELECT DISTINCT * FROM Garant GROUP BY Location";
10. $stmt= substr($query, 0, strlen($query)-4) ;
11.// Connect to the Database
12.$link=mysql_connect($location,$userName,$passwo rd) or die (mysql_error());
13.mysql_select_db($dbname) or die (mysql_error());
14.$result=mysql_query($query) or die (mysql_error());
15.// Select the Database
16.if (!mysql_select_db($dbname, $link)) {
17. DisplayErrMsg(sprintf("Error in selecting %s database", $dbname)) ;
18. DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error
19.($link))) ;
20. exit() ;
21.}
22.// Execute the Statement
23.if (!($result =mysql_query($query, $link))) {
24. DisplayErrMsg(sprintf("Error in executing %s stmt", $query)) ;
25. DisplayErrMsg(sprintf("error:%d %s", mysql_errno($link), mysql_error
26.($link))) ;
27. exit() ;
28.}
29.echo"<form method="post" action="<?php echo $_SERVER['PHP_SELF'] ?>">';
30.echo '<select name="areasearch" onChange="submit();">';
31.while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
32.echo "<option value=$nt[Town]>$nt[Location]</option>";
33.}
34. echo"</select>";
35. echo" </form>";
36. echo $areasearch;
37. mysql_free_result($result) ;
38. ?>
39. </body>
40. </html>
The above code pulls the Location field records from database Garant. What I need to do is when a town is selected from the listbox, a new search thats finds all the places with that Location name. I can do the search stuff but how to get $areasearch valid?
Thanks for any help.
F
|