I've been trying to figure this out for a few days now so would appreciate a nudge in the right direction for solving it  I have a select/option dropdown populated with colours from a database, each colour has a unique ID.
Code:
<form method="get" action="index.php" enctype="multipart/form-data">
<select name="colour" id="colour">
<option value="0">Search By Colour</option>
<option value="1">Blue</option>
<option value="2">Green</option>
<option value="3">Red</option>
</select>
</form>
The search query works as follows:
Quote:
if ( isset($_GET['colour'] )
{
$query="SELECT C.*, I.* FROM colour_ids AS C INNER JOIN products_inventory AS I ON C.productId=I.productId where C.Colour_Id=".intval($_GET['colour'])." GROUP BY C.productId";
}
|
If the URL contains a colour ID it displays all products of that color.
The above works great, but what I would like to do is pass the colour name to the URL, instead of the ID. When I change the form as follows:
Code:
<option value="Blue">Blue</option>
The colour name is successfully passed to the URL, however the search fails because the query is looking for an ID in isset($_GET['colour']) - bold in above query.
I believe I have to pass the value as value="{NAME}" (like above), instead of using {ID}. If so, just prior to the query executing how do I go about changing {NAME} back to its equivelent {ID} for the query to be successful?
Any pointers or help appreciated  Thanks (above code clipped for easier reading)
Last edited by downliner; 06-26-2009 at 10:37 AM..
|