Jump to content

question on php/mysql efficiency - which method?


DamienRoche

Recommended Posts

I am using a while loop to run through rows and extract the data. The data is being presented and fancied up using html.

 

My question is: would it be more efficient to use the while loop or put the data into an array and use a for each on the array?

 

NOTE: there is only 1 row below for example purposes - assume all works, there may be some typos. Actual version works and has over 1000 cols/variables with up to 10,000 rows of data.

 

Method 1:

 

while($fetch=mysql_fetch_array($data)){

    $t = mysql_real_escape_string($fetch['title']);

    echo "<h1>$t</h1>";
}

 

Method 2:

 

while($fetch=mysql_fetch_array($data)){

    $t[] = mysql_real_escape_string($fetch['title']);
}
foreach($t as $t2){
echo "<h1>$t</h1>";
}

 

....no doubt there are other ways, but which do you think is more efficient.

 

Thanks.

Thanks, and I don't know why I run mysql_real_escape_string on this....I seen somebody else use it on the output, so I copied their logic. I just thought "the more, the better". So I don't need it for output? just for user input?

 

Thanks again.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.