How to join several variables in one in php and pass to JQuery in a link

0

I consulted on the subject and I even managed to find some forms but nothing that could solve my case, I will try to be direct to facilitate. I have a table where some visits of some companies, I have the visits of the types RTV and ATV and I am adding the visits and putting in that table in the respective fields in the dates, each sum represents the visits made, in the example below the day 09/09 had 3 ATV visits.

EachvisitofthishasaID,thatis,3IDsandwhatI'mtryingtodoistojointheseID´stothesamevariable,Imadethenecessaryselectsandcreatedthisstructuretostorethem,butnotdynamically,I'mdoingthisselectwithinloopandit'slikethat,inthecaseoftheATVvisit:

$sqlMontaLinkATV="SELECT supVisitaRtv.IdVisita FROM supVisitaRtv WHERE Tipo = 'ATV' AND supVisitaRtv.Data = ? AND IdEmpresa = ? ";   
     $arrayParamLinkATV = array($DataInc, $IdEmpresa);  
     $ResultadoLinkATV  = $crud->getSQLGeneric($sqlMontaLinkATV, $arrayParamLinkATV, TRUE); 

The result of this search I'm seeing thus with a print_r($ResultadoLinkATV) :

Array ( [0] => stdClass Object ( [IdVisita] => 33 ) [1] => stdClass Object ( [IdVisita] => 34 ) [2] => stdClass Object ( [IdVisita] => 37 ) )

Where I have the IDs of the visits I need, I tried to insert them into a variable like this:

 $IdVisita = array();
 array_push($IdVisita, $ResultadoLinkATV[0]->IdVisita); 

I hope I have been able to explain it satisfactorily.

    
asked by anonymous 27.09.2017 / 15:16

2 answers

3

Based on the question data, the result of your SQL query is as follows:

$ResultadoLinkATV = [
    (object) ["idVisita" => 33],
    (object) ["idVisita" => 34],
    (object) ["idVisita" => 37]
];

You can get the list of ids through the array_column function of PHP:

$ids = array_column($ResultadoLinkATV, "idVisita"); // [33, 34, 37]

Thus,% w_of% will be an array of the $ids form. If you need values like string , you can convert to JSON:

$ids_string = json_encode($ids); // "[33,34,37]"

Or use [33, 34, 37] .

  

See working at Ideone .

    
27.09.2017 / 15:32
0

This problem could be solved by using the SQL COUNT function

SELECT COUNT(supVisitaRtv.IdVisita) AS qnt FROM supVisitaRtv WHERE Tipo = 'ATV' AND supVisitaRtv.Data = ? AND IdEmpresa = ?;

In this way, the bank itself calculates how many visits have been made of the type ATV by the company and at a certain date informed;

    
27.09.2017 / 15:25