So your first web page needs a <form> that (perhaps among other things) has a drop-down to select a zip code, and it needs another drop-down to select one of 2 possible choices: To West, or To South. When the form is submitted, a PHP script must accept the form data (normally as "Post" data), do a database lookup to find whichever of the 2 prices for the selected zip code and send that data back to another web page. Right?
For the first drop-down, your PHP will look something like this:
Code: Select all
...
<select name='zip'>
<?php
$sql="Select ZipCode From price Order By ZipCode";
$resource=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($resource)) {
$zip=$row[0];
echo "<option value='$zip'>$zip</option>";
}
?>
</select>
...
That will create your drop-down with zip codes, within your form, and when the form is submitted, the $_POST array index of the selected value will be 'zipcode', the name of the <select> element.
For the direction drop-down, all you need is this HTML:
Code: Select all
...
<select name='direction'>
<option value=1>To West</option>
<option value=2>To South</option>
</select>
..
That will create your drop-down with 2 choices. Here I suggest simply giving the values of 1 or 2 to the choices, but you can use whatever values you want, numeric or text. When the form is submitted, the $_POST array index of the selected value will be either 1 or 2 (or "To West" or "To South" if you prefer).
In your "action" PHP script, you will recover these selections like this:
Code: Select all
...
$zipcode = $_POST['zipcode'];
$direction = $_POST['direction'];
Then, of course, you will use those values to form your query to find the price. By using numeric values for the direction choice, it will make it simple to write your query:
Code: Select all
...
$sql="Select ZipCode, ToWest_Price, ToSouth_Price From prices Where ZipCode = '$zipcode' ";
$resource=mysql_query($sql) or die(mysql_error());
$row=mysql_fetch_array($resource);
$price=$row[$direction];
...