Store query content in an array

0

Hello, I have a class that performs a query in the database:

$itemObra->listarItensObra($_GET['id'], 0);

I need to use this query several times and I would like the query to occur only once and the items to be stored in an array, and then use a foreach to list.

foreach ($itemObra->listarItensObra($_GET['id'], 0) as $item) {
//....
}

Any idea is welcome!

    
asked by anonymous 04.09.2015 / 20:28

2 answers

3

You have to see your architecture but theoretically if your list returns the array already does this:

$resultado = $itemObra->listarItensObra($_GET['id'], 0);

But it is not indicated to use parameters of the form that you are using I indicate use like this:

$id = mysql_real_escape_string($_GET['id']);
$resultado = $itemObra->listarItensObra($id, 0);
    
04.09.2015 / 20:59
1

If the query will occur several times and if the data in this query does not change easily, you can also store it in a session.

For example:

$_SESSION['OBRAS'] = $itemObra->listarItensObra($id, 0);

With this you can use any part of your code to $ _SESSION to do the listing.

    
04.09.2015 / 23:03