tags:

views:

36

answers:

2

i get some data from mysql.

$result = $forum_model->get_info($_SESSION['group_id']);

// step 1

while($user = mysqli_fetch_assoc($result))
{
    some code
}

but when i later some lines beneath want to use the same data pulled out from mysql it doesnt work.

// step 2

while($user = mysqli_fetch_assoc($result))
{
    some code
}

is the $result emptied? do i have to make another

$result = $forum_model->get_info($_SESSION['group_id']);

to get the same data?

i have tried to do like this in the start

$result = $forum_model->get_info($_SESSION['group_id']);
$result2 = $result;

then in the second step use $result2 instead but it doesnt seem to work either.

how can i solve this easily?

A: 

It is not efficient to pull the same result set twice. I recommend you fix your code to make use of the fetched result rows. (It might help if you fetch them as objects also).

Xeoncross
+1  A: 

Yes, this code

while($user = mysqli_fetch_assoc($result)) {
   some code
}

iterates through the statement, moving the result pointer until it reaches the end of the result set.

In order to rerun your query (not sure why you can't store the results in a php array), you must do the following:

mysql_data_seek($result,0)
r00fus