0

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

1
  • Data is stored in database and not in phpmyadmin. Also I would suggest you to use mysqli. mysql_* are deprecated. Commented Mar 12, 2013 at 11:42

1 Answer 1

1

Assuming following query :

$sql = "select * from locations where county=" . $_POST['county'] . " and name='" .     $_POST['county'] . "'"; 
$query = mysql_query($sql);

echo '<select name="country" size="1">'
while ($row = mysql_fetch_array($query)) { 
echo '<option value="' . $row['id'] . '">' . $row['county'] . '</option>';
}
echo '</select>';

Note : mysql_* are deprecated.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.