Questing regarding list(), arrays and mysql_get_array

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!

Moderator: General Moderators

Post Reply
User avatar
TheTestUser
Forum Newbie
Posts: 9
Joined: Sat Dec 14, 2002 9:25 pm

Questing regarding list(), arrays and mysql_get_array

Post by TheTestUser »

I'm looping through a large amount of data and I'm trying to keep overhead down and speed up things as much as I can. Which is the preferred method for grabbing info from a database?
Below is how I'm grabbing the information currently.

Code: Select all

$result = mysql_query('SELECT x,y,z
  FROM SampleTable
  WHERE x BETWEEN 0 AND 10000
     AND y='.$someusersubmittednumber);
if (mysql_num_rows($result)==0)
{  die('No records available.');
}
while (list($X,$Y,$Z) = mysql_get_row($result))
{  // process information
}
I am using quite a lot of these statements on each of my pages and on each I'm giving each result a variable. Would it be better if I simply stored them all in the same array like this?

Code: Select all

$result = mysql_query('SELECT x,y,z
  FROM SampleTable
  WHERE x BETWEEN 0 AND 10000
     AND y='.$someusersubmittednumber);
if (mysql_num_rows($result)==0)
{  die('No records available.');
}
while ($row = mysql_fetch_assoc($result))
{  // process information
}

I've seen conflicting data on this issue where some people say it's better to use one array to keep overhead down, other say to minimize the use of arrays.
I'm not certain how php allocates memory. Would it be better to use the same array over and over in statements like this rather than storing each in a seperate variable? Would it be faster? Less strain on the server with multiple users?

Any help is appreciated.
User avatar
TheTestUser
Forum Newbie
Posts: 9
Joined: Sat Dec 14, 2002 9:25 pm

Post by TheTestUser »

Any opinions on this?
Post Reply