Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8978589
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:39:02+00:00 2026-06-15T19:39:02+00:00

I want to loop multiple times through my query results, and I have 2

  • 0

I want to loop multiple times through my query results, and I have 2 ways in mind:

1-        
while($data = mysql_fetch_array($res ,  MYSQL_ASSOC)
{
array_push($new_arr , $data);
}
foreach($sites as $s){
  foreach($new_arr as $d)
  {
  //some code
  }
}

2-
foreach($sites as $s){
  while($data = mysql_fetch_array($res ,  MYSQL_ASSOC)
  {
  //some code
  }
mysql_data_seek($res,0);//set the pointer 
}

My question: I think option 2 is more efficient but what if I lose connection to db during the mysql_fetch_array(option 2)? I get allot of results; this will take around 10-20 minutes. Will that affect the query results($res) or are they safe?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T19:39:04+00:00Added an answer on June 15, 2026 at 7:39 pm

    The data is mapped into a buffer assigned by the mysql client when you execute mysql_query() therefore losing the connection is irrelevant. The first method you cite will create a further copy of the data as a PHP array – which is not very efficient.

    Also, WTF is the nested loop ($sites) doing? It looks like either your data is not mormalized or you’ve got a very bad algorithm.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have multiple records received as string through a query. I want to store
I want to loop through the rows of a data.table and calculate an average
I want to loop through the checkboxgroup 'locationthemes' and build a string with all
I want to loop through the controls on a UserControl and set a property
I want to loop through a database of documents and calculate a pairwise comparison
Introduction: I want to loop through XML files with flexible categories structure. Problem: I
I have the following HTML that I want to repeat 5 times within a
I have a WSDL which has multiple operations. For each op i want a
I have a query that attempts to select cases/clients (clients.id) based on multiple conditions
I want to loop over a range of numbers from 1:n , when n

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.