mysql - Pass values from php array as param in UNION query -
i want pass values array individual parameter in query , use them below
array ( [0] => [1] => text ) i want kind of function
public function getdata($some,$text) { $sql = " select * table field1 = '{$some}' or field3 = {$some} "; $union = " union "; $sql = " select * table field2 = '{$text}' or field4 = {$text} "; } note: array may have nth number of index.
you can use following:
public function getquery($dataarray) { $queryarray = array(); foreach($dataarray $data) { $query = "select * `table`"; $conditionarray = array(); foreach($data $key => $value) { $conditionarray[] = "`$key` = `$value`"; } if (!empty ($conditionarray)) { $query .= " ". implode(" or ", $conditionarray); } $queryarray[] = $query; } return implode(" union ", $queryarray); }
Comments
Post a Comment