I have a website where I am trying to display data from the database stored in mysql into comboboxes. Basically it is a location database so I want to display an area and then based on the selection I want the next combobox to show the shops in that location.
I am using php for this. I'm not too familiar with php. I've found loads of tutorials and examples but still I don't seem to be tweeking the code properly to get it to work. Also I'm not sure if I need a seperate php file with connection details or if I can put it all in the one file. I can't even populate one combobox at the minute so I am really trying to go back to basics.
Anyway this is the code so far (obviously I have html tags etc):
<form name="form1" method="POST" action="db.php">
<p>
<select name="users" onchange="showUser(this.value)">
<option selected="selected">Select county</option>
<p><input type="submit" name="Search" value="Search">
</form>
Then I have a db.php file where it stores my database details and sql query
<?php
resource mysql_connect ( [string server [, string username [, string password [, bool new_link [, int client_flags]]]]])
$host = "localhost";
$user = "";
$pass = "";
bool mysql_select_db ( string database_name [, resource link_identifier])
$dbname = "databseLocations";
mysql_select_db($dbname);
$sql = "select * from locations where county=" . $_POST['county'] . " and name='" . $_POST['county'] . "'";
echo $sql;
resource mysql_query ( string query [, resource link_identifier])
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)) {
echo "<p>",$row['id'],": ",$row['county'];
}
?>
I need this data to be displayed on a map too based on selection but I can worry about that later.
Thanks for any help
Best Answer
Assuming following query :
Note :
mysql_*
are deprecated.