valleydr Posted May 28, 2006 Share Posted May 28, 2006 Hello. I am somewhat familiar with php, I am learning more as I go. I have come up with an issue I can't figure out. I am setting up a script that uses a search form that searches a mysql db for the keyword and show the results. I have it set up to search a specific field in the db, but I want it to search more than one. what I have so far is:[code]if(!isset($HTTP_GET_VARS["keyword"])) $keyword = "";else $keyword = $HTTP_GET_VARS["keyword"];$filterKeyword = "AND (c.features LIKE '%$keyword%' OR '$keyword'='')";[/code]keyword is the text box from the form, and c.features is the field it is currently searching from the c table. This works, but what I need is for it to basically search c.features and c.engine and c.drive, etc. For whatever reason, i cannot figure out the correct formatting for this. I'd appreciate any help I can get. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/10634-php-search-mysql/ Share on other sites More sharing options...
wild_dog Posted May 28, 2006 Share Posted May 28, 2006 [!--quoteo(post=377774:date=May 28 2006, 03:36 AM:name=valleydr)--][div class=\'quotetop\']QUOTE(valleydr @ May 28 2006, 03:36 AM) [snapback]377774[/snapback][/div][div class=\'quotemain\'][!--quotec--]Hello. I am somewhat familiar with php, I am learning more as I go. I have come up with an issue I can't figure out. I am setting up a script that uses a search form that searches a mysql db for the keyword and show the results. I have it set up to search a specific field in the db, but I want it to search more than one. what I have so far is:[code]if(!isset($HTTP_GET_VARS["keyword"])) $keyword = "";else $keyword = $HTTP_GET_VARS["keyword"];$filterKeyword = "AND (c.features LIKE '%$keyword%' OR '$keyword'='')";[/code]keyword is the text box from the form, and c.features is the field it is currently searching from the c table. This works, but what I need is for it to basically search c.features and c.engine and c.drive, etc. For whatever reason, i cannot figure out the correct formatting for this. I'd appreciate any help I can get. Thanks.[/quote]If you are using MySQL then try use the array mysql_fetch_assoc() function.You can use it to search several columns, tables etc and then store that in an array Quote Link to comment https://forums.phpfreaks.com/topic/10634-php-search-mysql/#findComment-39656 Share on other sites More sharing options...
valleydr Posted May 28, 2006 Author Share Posted May 28, 2006 I am using mySQL. There isn't any way to just somehow do smething like:[code]AND (c.features, c.engine, c.drive LIKE '%$keyword%' OR '$keyword'='')[/code]or something like that? (I realize the above is incorrect.) This would just be much easier for to update the pages. Thanks for the input. Quote Link to comment https://forums.phpfreaks.com/topic/10634-php-search-mysql/#findComment-39752 Share on other sites More sharing options...
Barand Posted May 29, 2006 Share Posted May 29, 2006 [code]AND ((c.features LIKE '%$keyword%') OR (c.engine LIKE '%$keyword%') OR (c.drive LIKE '%$keyword%' ))[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10634-php-search-mysql/#findComment-39811 Share on other sites More sharing options...
valleydr Posted May 29, 2006 Author Share Posted May 29, 2006 Hello Barand,I tried that, but it stopped my other search functions from working properly. Below is my full search code I have. You can see what search info I am gathering, and how I am searching the db. I tried what you mention, and it worked great for the keywords field, but none of my other search fields worked properly.[code]if(!isset($HTTP_GET_VARS["model"])) $model = "";else $model = $HTTP_GET_VARS["model"]; if(!isset($HTTP_GET_VARS["min_price"])) $min_price = "";else $min_price = $HTTP_GET_VARS["min_price"]; if(!isset($HTTP_GET_VARS["max_price"])) $max_price = "";else $max_price = $HTTP_GET_VARS["max_price"]; if(!isset($HTTP_GET_VARS["min_year"])) $min_year = "";else $min_year = $HTTP_GET_VARS["min_year"]; if(!isset($HTTP_GET_VARS["max_year"])) $max_year = "";else $max_year = $HTTP_GET_VARS["max_year"];if(!isset($HTTP_GET_VARS["type"])) $type = "";else $type = $HTTP_GET_VARS["type"];$filterType = "AND (c.type LIKE '%$type%' OR '$type'='')";if(!isset($HTTP_GET_VARS["keyword"])) $keyword = "";else $keyword = $HTTP_GET_VARS["keyword"]; if(!isset($HTTP_GET_VARS["engine"])) $engine = "";else $engine = $HTTP_GET_VARS["engine"]; if(!isset($HTTP_GET_VARS["drive"])) $drive = "";else $drive = $HTTP_GET_VARS["drive"];$filterKeyword = "AND (c.features LIKE '%$keyword%' OR '$keyword'='') AND (c.drive LIKE '%$drive%' OR '$drive'='') AND (c.engine LIKE '%$engine%' OR '$engine'='') ";if(!isset($HTTP_GET_VARS["year"])) $year = "";else $year = $HTTP_GET_VARS["year"];$sqlCnt = "SELECT COUNT(c.id) FROM ".$db_prefix."cars AS c INNER JOIN ".$db_prefix."dealers AS d ON d.id=c.member_id WHERE d.status='Active' AND (c.model LIKE '$model%' OR '$model'='') AND (c.price >= '$min_price' OR '$min_price'='') AND (c.price <= '$max_price' OR '$max_price'='') ".$filterType." ".$filterKeyword." AND (c.year >= '$min_year' OR '$min_year'='') AND (c.year <= '$max_year' OR '$max_year'='') AND (c.member_id='$dealer_id' OR '$dealer_id'='')";[/code] Quote Link to comment https://forums.phpfreaks.com/topic/10634-php-search-mysql/#findComment-39867 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.