Guest User

Untitled

a guest
May 23rd, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.08 KB | None | 0 0
  1. array(2) {
  2. ["area1"] => array(3) {
  3. [0] => string(5) "item1"
  4. [1] => string(5) "item2"
  5. [2] => string(5) "item3"
  6. }
  7. ["area2"] => array(2) {
  8. [0] => string(5) "item1"
  9. [1]=> string(5) "item2"}
  10. }
  11. }
  12.  
  13. "select nombre, tipo from tabla1 where area1 in(item1, item2, item3) and area2 in (item1, item2)"
  14.  
  15. $array = array("area1"=> array("item1","item2","item1") , "area2"=> array("item1","item2"));
  16. $area1 = "'".implode("','", $array['area1'])."'";
  17. /* Convertimos a String ,separado por comas*/
  18. $area2 = "'".implode("','", $array['area2'])."'";
  19. $sentencia = $mbd->prepare("SELECT nombre,tipo from tabla1 where area1 in ( $area1 )
  20. and area2 in ($area2)"); /* Le pasamos la colección*/
  21. $sentencia->execute(); /* Ejecutamos la Sentencia */
  22. $fila = $sentencia->fetchAll();
  23. print_r($fila);
  24.  
  25. $paramsIn1 = [10, 203, 4, 6];
  26. $paramsIn2 = [10, 203];
  27.  
  28. $strParams1 = implode(',', array_fill(0, count($paramsIn1), '?'));
  29. $strParams2 = implode(',', array_fill(0, count($paramsIn2), '?'));
  30.  
  31. $sqlQuery = "select nombre,tipo from tabla1 where area1 in($strParams1) and area2 in ($strParams2)";
  32.  
  33. $sth = $dbh->prepare($sqlQuery);
  34. $sth->execute(
  35. array_merge(
  36. $paramsIn1, $paramsIn2
  37. )
  38. );
  39.  
  40. public function procesarDestinatarios($array){
  41. $consulta = "select nombre,tipo from datosusuarios where ";
  42.  
  43.  
  44. $aux1 = 1;
  45. $aux2 = 1;
  46.  
  47. $count1 = count($array);
  48. $count2 = 0;
  49.  
  50. foreach ($array as $key => $value) {
  51. $count2 = count($array[$key]);
  52. $consulta .= $key ." in (";
  53.  
  54. foreach ($value as $valor) {
  55. if($aux2 < $count2){
  56. $consulta .= "'".$valor ."',";
  57. $aux2++;
  58. }else{
  59. $consulta .= "'".$valor."'";
  60. $aux2 = 1;
  61. }
  62.  
  63. }
  64.  
  65. if($aux1 < $count1){
  66. $consulta .= ") and ";
  67. }else{
  68. $consulta .= ")";
  69. }
  70.  
  71. $aux1++;
  72. }
  73.  
  74. return $consulta;
  75.  
  76. }
  77.  
  78. 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