2015-02-22, 03:16 AM
So basically I have an SQL simple select query, and a fetch_array statement, and then the results (Facebook & Yahoo ID's) are displayed in the postbit of each user's post.
Here's the problem:
For every single post by the same user, it fetches the arrays again and again. So if the same user posted 10 times on the page, it would fetch the arrays 10 times (10 for Facebook, and 10 for Yahoo). I need it to just fetch 1 array for Facebook & 1 array for Yahoo.
How can I fetch the arrays only once for each user, but still show the result in the postbit?
Here is my code:
So if a user posts 10 times on a thread page, print_r() displays 10 Arrays for Yahoo, and 10 Arrays for Facebook.
How can I reduce it to 1 query instead of 10, for the same users posts?
Here's the problem:
For every single post by the same user, it fetches the arrays again and again. So if the same user posted 10 times on the page, it would fetch the arrays 10 times (10 for Facebook, and 10 for Yahoo). I need it to just fetch 1 array for Facebook & 1 array for Yahoo.
How can I fetch the arrays only once for each user, but still show the result in the postbit?
Here is my code:
$query = $db->simple_select("socialusers", "yahoo,facebook", "uid='".$post['uid']."'");
while ($result = $db->fetch_array($query)) {
print_r($result); //Testing to see how many arrays it fetches
$facebook_id = '<a href="'.$result['facebook'].'">Facebook Profile</a>';
$yahoo_id = '<a href="'.$result['yahoo'].'">Yahoo Address</a>';
}
}
So if a user posts 10 times on a thread page, print_r() displays 10 Arrays for Yahoo, and 10 Arrays for Facebook.
How can I reduce it to 1 query instead of 10, for the same users posts?