PHP switch function help
Posted on
16th Feb 2014 07:03 pm by
admin
Hi, I am trying to create a search function for a directory website. On the search function on html page I have a dropdown menu. From this you can select one OF 3 options - shoes, handbags, shoes and handbags. I have a php process form page where it takes this infor before runninng a query in the sql database.
My question is that I would like the one option to have multiple values - when user clicks shoes, the query will search for a field containing shoes (this bit is fine) but also I want it to select another field to search for a value - this field will depend upon the what option the user picked in the question. The problem being, that unless i rename the fields in the table from lets say, Sbrand to Shoes and Hbrand to handbags i'm not sure how to action
Did you know?Explore Trending and Topic pages for more stories like this.
What I need is that if value on option was shoe then I need it linked to pick from Sbrand Now I think that I can use a switch function but the current issue is that I must have it in the wrong place as when I tried it as per below code, it appears that the search is looking for a field called the option value so the switch is not working. Perhaps I need to move the switch function from the php process page to the html page but I’m not sure
Any help much appreciated
HTML code………… this works on a method=â€getâ€
<select name="type">
<option value="none">-- Please Select --</option>
<option value="Shoes">Shoes</option>
<option value="Handbags">Handbags</option>
<option value="Shoes and Handbags">Shoes and Handbags</option>
</select>
Here’s the PHP code
$search_type=$db->escapeString($_GET['type']);
switch ($type){
case "Shoes":
echo "Sbrand";
break;
case "Handbags":
echo "Hbrand";
break;
case "Shoes and Handbags":
echo "SHbrand";
break;
}
$result=$db->query("SELECT Sbrand, Hbrand, SHbrand, SB, Retailer, Address, Town, County, Postcode, Postcode_code, Phone, Website FROM database WHERE SB LIKE 'type' AND $search_type LIKE '%$searchterm%'");
Any help much appreciated as i am new to this
No comments posted yet
Your Answer:
Login to answer
308
52
Other forums
Chat Box in PHP
I was thinking in doing a Chat Box in PHP. For that I would use a form with two fields, Nick and Mes
Fetching array then reversing it
Hi, I have a simple problem, I'll try to explain it as best I can:
News entries in my database ar
Gerenate tabel in Php
I whant to generate a tabel takeing data from database like this one so the results to be display on
Certain files upload, while others do not
I want to read the data from an uploaded file. Not sure why, but it only uploads for certain files.
Get value from Select menu
Hi!
Have tried to find the solution on the web. Don't know if there is an easy one. A descrip
help understanding hidden input w/ php
hello i'm doing a tutorial where there are multiple forms for an edit page for a user to update thei
Reg Ex
Im trying to search for the string: srv_9 (Dead ???)
I thought to use preg_match, however I d
Preventing blank or already entered values
Im trying to learn how to place a read file line by line and prevent duplicate entries and also BLAN
string to currency format
Hi guys...
Actually I chunk out some data from txtfile and one of the data contains amount va
Simple code help with redirects
I am trying to figure out a redirect script that detects if the browser is IE 7 and if it does, redi