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

Popular posts from this blog

java - pagination of xlsx file to XSSFworkbook using apache POI -

Unlimited choices in BASH case statement -

apache - How do I stop my index.php being run twice for every user -