Hi there,
I have this query that I need 3 times in my PHP script. Currently I am getting arround this by doing 3 duplicate queries as follows:-
$result1 = mysql_query(“SELECT * FROM users WHERE id = ‘$id’”);
$result2 = mysql_query(“SELECT * FROM users WHERE id = ‘$id’”);
$result3 = mysql_query(“SELECT * FROM users WHERE id = ‘$id’”);
Then I access data with 3 while loops using 3 different results (as above): -
while ($row = mysql_fetch_object($result1)) {
echo $row->user_id;
echo $row->fullname;
}
while ($row = mysql_fetch_object($result2)) {
echo $row->user_id;
echo $row->fullname;
}
while ($row = mysql_fetch_object($result3)) {
echo $row->user_id;
echo $row->fullname;
}
I believe this to be not good practice. But if I try and do this with 1 query e.g. use only $result1 I get no data back in the second and third while loop. Its like the mysql query result can only be used once!
Anyone got a more tidy approach?
Maybe I should store in arrays, if so how?
Thanks in advance.
W Digital