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

  • Home
  • SEARCH
  • 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 356655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T12:07:56+00:00 2026-05-12T12:07:56+00:00

Below is just a mockup of 2 codes in php/mysql. The first one returns

  • 0

Below is just a mockup of 2 codes in php/mysql.
The first one returns a mysql result and run a while loop to iterate the results, the second one does almost the same thing but instead puts the result into a query and then puts it to screen. Now for a more OO approach the second method would be better I think (not sure, i’m learning) however where I am confused is, wouldn’t using the second method below use twice as much memory? Isn’t it basicly creating 2 arrays instead of 1?

Putting it into an array seems a lot more flexible, please give me your tips/advice. Keep in mind it would not be a simple thing ran 1 time on a page either, a real world example on a page on my site that array might contain 5,000 usernames and userID number in the array and multiple queries might be made on the same page all with different data.

<?PHP
// first method without using array
$url = "http://www.google.com/";
$sql = "SELECT user_id, nickname FROM `".TABLE_USERS."`
          WHERE referrer LIKE '".$db->escape($url)."%'
          ORDER BY nickname DESC
          LIMIT 0,10";

$rows = $db->query($sql);

while ($record = $db->fetch_array($rows)) {
    echo "<tr><td>$record[user_id]</td>
          <td>$record[nickname]</td></tr>";
}
//////////////////////////////////////////////////////////////////////
//second method using array
$url = "http://www.google.com/";
$sql = "SELECT user_id, nickname FROM `".TABLE_USERS."`
          WHERE referer LIKE '".$db->escape($url)."%'
          ORDER BY nickname DESC
          LIMIT 0,10";

// feed it the sql directly. store all returned rows in an array
$rows = $db->fetch_all_array($sql);

// print out array later on when we need the info on the page
foreach($rows as $record){
    echo "<tr><td>$record[user_id]</td>
          <td>$record[nickname]</td></tr>";
}

?>
  • 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-05-12T12:07:56+00:00Added an answer on May 12, 2026 at 12:07 pm

    The second method will use a lot more than twice as much memory. The first method is only fetching a single row at a time and sending it to STDOUT. The second method reads in every row into an array. If you have 5000 rows, it’s going to use approximately 5000 times the memory (not accounting things like PHP’s internal output buffering, etc).

    The second method does allow you to manipulate the data much more, but it definitely uses a lot more memory. If you are really dealing with that much data on a page, you might have to find ways to break it down if you start to run into resource problems.

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

Sidebar

Ask A Question

Stats

  • Questions 251k
  • Answers 251k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer If this is in a LAN and will never be… May 13, 2026 at 9:34 am
  • Editorial Team
    Editorial Team added an answer If you change the PHP query bits to... $new_rows_data['fname'][] =… May 13, 2026 at 9:34 am
  • Editorial Team
    Editorial Team added an answer It's an array of one element. In this case containing… May 13, 2026 at 9:34 am

Related Questions

Essentially, what I want to do (in DirectX) is to take two partially-transparent images
Below is a block of code that runs in a separate thread from my
Based on the following XML, what is the best way to achieve an alphanumeric
I have a .php file with HTML code also in it. Through this file

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.