Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- array(2) {
- ["area1"] => array(3) {
- [0] => string(5) "item1"
- [1] => string(5) "item2"
- [2] => string(5) "item3"
- }
- ["area2"] => array(2) {
- [0] => string(5) "item1"
- [1]=> string(5) "item2"}
- }
- }
- "select nombre, tipo from tabla1 where area1 in(item1, item2, item3) and area2 in (item1, item2)"
- $array = array("area1"=> array("item1","item2","item1") , "area2"=> array("item1","item2"));
- $area1 = "'".implode("','", $array['area1'])."'";
- /* Convertimos a String ,separado por comas*/
- $area2 = "'".implode("','", $array['area2'])."'";
- $sentencia = $mbd->prepare("SELECT nombre,tipo from tabla1 where area1 in ( $area1 )
- and area2 in ($area2)"); /* Le pasamos la colección*/
- $sentencia->execute(); /* Ejecutamos la Sentencia */
- $fila = $sentencia->fetchAll();
- print_r($fila);
- $paramsIn1 = [10, 203, 4, 6];
- $paramsIn2 = [10, 203];
- $strParams1 = implode(',', array_fill(0, count($paramsIn1), '?'));
- $strParams2 = implode(',', array_fill(0, count($paramsIn2), '?'));
- $sqlQuery = "select nombre,tipo from tabla1 where area1 in($strParams1) and area2 in ($strParams2)";
- $sth = $dbh->prepare($sqlQuery);
- $sth->execute(
- array_merge(
- $paramsIn1, $paramsIn2
- )
- );
- public function procesarDestinatarios($array){
- $consulta = "select nombre,tipo from datosusuarios where ";
- $aux1 = 1;
- $aux2 = 1;
- $count1 = count($array);
- $count2 = 0;
- foreach ($array as $key => $value) {
- $count2 = count($array[$key]);
- $consulta .= $key ." in (";
- foreach ($value as $valor) {
- if($aux2 < $count2){
- $consulta .= "'".$valor ."',";
- $aux2++;
- }else{
- $consulta .= "'".$valor."'";
- $aux2 = 1;
- }
- }
- if($aux1 < $count1){
- $consulta .= ") and ";
- }else{
- $consulta .= ")";
- }
- $aux1++;
- }
- return $consulta;
- }
- select nombre,tipo from datosusuarios where area1 in ('zona2','zona3') and grupo in ('a','c','d','h')
Add Comment
Please, Sign In to add comment