Searching an item that is stored with multiple names concatenated with ** in mysql using PHP -
i'm trying perform search of database in php using values containing ** separate different values. 1 illustration database is:
gs 300**gs3000
i want search values in db either gs 300 or gs3000.
my script is:
$query = "select distinct(parts_cats.part_type) parts_cats stock.item_specifics_type in ('$ids') , stock.stock_item!='' , make='$make' , model '%" . mysql_real_escape_string($model) . "%'" currently search works fine non-double asterick values (e.g. if searching g3 500) returns no results gs 300**gs3000.
if want find either 1 or other model should (although expensive). don't know ** , how have stored things in database...
"select distinct(parts_cats.part_type) parts_cats stock.item_specifics_type in ('$ids') , stock.stock_item!='' , make='$make' , ( model '%" . mysql_real_escape_string($modelone) . "%' or model '%" . mysql_real_escape_string($modeltwo) . "%')" or resulting query
select distinct(parts_cats.part_type) parts_cats stock.item_specifics_type in ('$ids') , stock.stock_item!='' , and='$make' , ( model '%gs 300%' or model '%gs3000%') edit:
ok have table fields id concatnames , have entries 5, gs 300**gs3000 in it.. whatever user inputs , utilize query wrote above.. did seek yet?
you can have user input string one:
$str = "something**something2**something3"; then can array using
$array = explode("**",$str) or have multiple <input>s user set things separately in.
in either case have $array of different values..
then build dynamically part of query as
"and (model '%".$array[0]."%' or model '%".$array[1]."%' or model '%".$array[2]."%')" this work if user inputs gs300,gs3000 lone or gs 300**gs3000 or gs3000**gs 300
php mysql search
No comments:
Post a Comment