# Simple PHP/MySQL question

**URL:** <https://forum.kirupa.com/t/simple-php-mysql-question/132991>\
**Category:** Uncategorized\
**Created:** [January 4, 2005, 2:52pm UTC](https://forum.kirupa.com/t/simple-php-mysql-question/132991 "2005-01-04T14:52:46Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![w\_digital](https://avatars.discourse-cdn.com/v4/letter/w/35a633/32.png) [@w\_digital](https://forum.kirupa.com/u/w_digital)\
**Post date:** [January 4, 2005, 2:52pm UTC](https://forum.kirupa.com/t/simple-php-mysql-question/132991/1 "2005-01-04T14:52:46Z")

</div>

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**
