Save values of a query in php

0

I need this occasion, know how to save the values of c.cat_name , sc.idSub and i.numFile , of the query, to use them later.

 $query1  = 'SELECT c.cat_name,sc.idSub,i.numFile from inventory_list as i
                inner join category as c on  id_category =fkCategory
                inner join sub_category as sc on idSub =fkSubCat where numFile = ?';
    
asked by Pato 21.11.2018 в 19:10
source

1 answer

1

Greetings you could do in a foreach as follows:

$query = "SELECT c.cat_name,sc.idSub,i.numFile from inventory_list as i
                inner join category as c on  id_category =fkCategory
                inner join sub_category as sc on idSub =fkSubCat where numFile = ?";
$data = [];
foreach($DB->query($query) as $row) {
    $element = [];
    $element['cat_name'] = $row['cat_name'];     
    $element['idSub'] = $row['idSub'];   
    $element['numFile'] = $row['numFile'];
    array_push($data, $element);   
}

Explanation, what I do is go through the array that returns my query and I'm adding one by one the elements in the $ data array which will contain my desired result:

finally you could get something like this, I suggest you check the PHP documentation: Push Array

    
answered by 21.11.2018 / 19:33
source