Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

For loops kill query

Status
Not open for further replies.

krisc13

Programmer
Jul 17, 2006
42
US
My program uses the following for loops to search customer records. $search_customers are the records being searched for and $g_u is the result set from mySQL query.

Code:
for ($i=0; $i<sizeof($g_u); $i++){
for ($x=0; $x<sizeof($search_customers); $x++){
if ($g_u[$i]['user_id'] == $search_customers[$x]['user_id']){
	$group_users[$count] = $g_u[$i];
	$count++;
	}
     }
  }

Without these loops the search doesn't work. However with these loops when the page loads I receive a mySQL Server has gone away error. If I remove these loops the page loads fine but the search is inoperative. Is there a faster way to loop thru these items and make the comparison?
 
$g_u is the entire result set? If such is the case, it looks to me as though your code copies data into an array only if a row of data from the resultset matches a row of data from a given array ($search_customers). This could be more efficiently performed by including that filtering in the SELECT query that populated $g_u.

If $g_u is not the entire result set, what does $i loop across?



Want the best answers? Ask the best questions! TANSTAAFL!
 
Yes $g_u is the entire result set. $search_customers is another result set. I'm comparing the two. I want my group users ($g_u) to contain my search results instead of the original list. I believe the original programmer was trying to sort of swap the original group users variable that held everyone with the new list based on the search.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top