Page 1 of 1

Questing regarding list(), arrays and mysql_get_array

Posted: Wed Jan 29, 2003 10:21 am
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.

Posted: Thu Jan 30, 2003 11:26 am
by TheTestUser
Any opinions on this?