tags:

views:

17

answers:

3

Im doing a simple mysqli query with code ive used many times before but have never had this problem happen to me. I am grabbing an entire table with an unknown number of columns (it changes often so i dont know the exact value, nor the column names). I have some code that uses metadata to grab everything and stick it in an array.

This all works fine, but the output is messed up:

$stmt -> execute();  //the query is legit, no problems there
$meta = $stmt->result_metadata();
while ($field = $meta->fetch_field())
{
    $params[] = &$row[$field->name];
}
call_user_func_array(array($stmt, 'bind_result'), $params);

while ($stmt->fetch())
{
    $pvalues[++$i] = $row; //$pvalues is an array of arrays. row is an array
    //print_r($row);
    print_r($pvalues[$i-1]);
}
$stmt -> close();

I would assume that $pvalues has the results that I am looking for. My table currently has 2 rows. $pvalues has array length 2. Both rows in $pvalues are exactly the same. If i use the:

print_r($row)

it prints out the correct values for both rows, but if later on i check what is in $pvalues it is incorrect (1 row is assigned to both indices of $pvalues).

If i use the

print_r($pvalues[$i-1])

it prints exactly as I expect, the same row in the table twice.

Why isnt the data getting assigned to $pvalues? I know $row holds the right information at one point, but it is getting overwritten or lost.

A: 

fuck i left in something for the printing $i-1 that was before i changed things around. forget that aspect of, thats obviously crap.

but later on, if i use $pvalues in any sort of loop all the values are still the same.

asdasdsa
A: 

Shouldn't it be

while ($row = $stmt->fetch())

?

a1ex07
A: 

no, ive never used that before and jsut tried it, doesnt work at all. this is very strange.

i can print_r($pvalues[0]) right after I assign it and its correct.

but if i do it again after the stmt->close its incorrect.

asdasdas