Is it possible to integrate an array to a mysql query?

0

given the following arrangement:

$tablas= array("honda_firme","honda_service_parts","honda_oe");

It is possible to record it to a query and with a FOR cycle to traverse it and in each iteration change the query table, I have a vague idea but I can not make it concrete I'm going back to the program and I'm a bit rusty I have this advance.

   $cuentaParts=1;
   $tablas= array("honda_firme","honda_service_parts","honda_oe"); // contador y arreglo
   $contador=0;
   for($i=1; $i<=(3*$numModel); $i++){
     if($contador==count($model)){
         $contador=0;
     }
    list ($nombre,$nopart)=explode("_",$model[$contador]);
    $contador++;

    // consulta 
    $qryhondamulti=mysql_query("SELECT * FROM ".$tablas[$contador]." WHERE CAST(fecha_entrega_xml AS DATE)= '$fechaMod' ORDER BY fecha_entrega_xml ASC, id_archivo DESC")or die(mysql_error());
    
asked by JrojasE 13.03.2018 в 16:11
source

1 answer

0

Hello! What you already have is going well, but the mysql_query must be included in the FOR cycle that you say:

  // consulta 
  for ($i = 0; $i < count($tablas); $i++)
  {
    $qryhondamulti=mysql_query("SELECT * FROM ".$tablas[$i]." WHERE CAST(fecha_entrega_xml AS DATE)= '$fechaMod' ORDER BY fecha_entrega_xml ASC, id_archivo DESC")or die(mysql_error());
  }

Of course if you have that die (), I'm afraid that if one of the queries falls, you would leave the FOR? That's not clear to me, since I never use the die () -_-...

You can also do the cycle with a FOREACH that is more friendly:)

    
answered by 13.03.2018 в 17:27