PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
There's JOINs as ~volka noted, which I would pursue first. If a JOIN isn't possible or prohibitive, which is rare, there's the cached data method where you store all the resultant data that would be in the inner loop into an array so you aren't fetching from the database all the time. The last, and quite often worst, is the nested loop.
To keep the inner loop from short circuiting during the second iteration of the outer loop, you must use mysql_data_seek().
I spoke of them in order of general preference from most preferred, to least.
mmm... i see...
in my case i am fetching at the most 3 rows in the inner loop and an average of 2 in the outer one, i think using dataseek would only increase the complexity and the amout of execptions to catch.
In a situation with larger that handling i guess dataseek would be more eficient
$storage = array();
$result1 = mysql_query($sql);
while($array1 = mysql_fetch_assoc($result1))
{
$storage[] = $array1['whatever_you_need'];
}
$result2 = mysql_query($sql);
while($array2 = mysql_fetch_assoc($result2))
{
//the storage array can now be referenced in here
//instead of doing another loop
}
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Good advice from scottayy there. Avoid nesting wherever possible. I've drowned in it before.
Also you can do a lot of your join like stuff without an actual join using a WHERE clause