I've been searching and racking my head over this. I'm new to AJAX/PHP, and cannot figure out why, a simple while loop for an SQL query takes soo long to iterate through. What I am trying to do, is a simple query against a table, single column, using DISTINCT, to remove duplicate values. What I end up with from thousands of entries, is 39. The query itself takes less then a second to complete, timed it. However, the while loop to gather the information takes on average 2.5 seconds, even if I am doing nothing in the loop, just iterating.
I am calling this in an 'window.onload' event within 'index.php', uses '<script src="ajax_doctracking.js" type="text/javascript"></script>', which calls one of two PHP files, that only does the connections to a DB, and creates the new select to return.
The loop below is storing the select value in a variable to be used later, even when I comment out this line, it does not speed things up.
while (odbc_fetch_row($rs))
{
$list .= '<option value='.odbc_result($rs,"TransactionID").'>'.odbc_result($rs,"TransactionID").'</option>';
}
Below is the time it takes for each iteration:
While2 Took 0.000 seconds
While2 Took 0.000 seconds
While2 Took 0.001 seconds
While2 Took 0.000 seconds
While2 Took 0.000 seconds
While2 Took 0.001 seconds
While2 Took 0.000 seconds
While2 Took 0.039 seconds
While2 Took 0.000 seconds
While2 Took 0.000 seconds
While2 Took 0.000 seconds
While2 Took 0.012 seconds
While2 Took 0.000 seconds
While2 Took 0.009 seconds
While2 Took 0.000 seconds
While2 Took 0.000 seconds
While2 Took 0.000 seconds
While2 Took 0.005 seconds
While2 Took 0.001 seconds
While2 Took 0.000 seconds
While2 Took 0.202 seconds
While2 Took 0.050 seconds
While2 Took 0.000 seconds
While2 Took 0.050 seconds
While2 Took 0.150 seconds
While2 Took 0.003 seconds
While2 Took 0.050 seconds
While2 Took 1.296 seconds
While2 Took 0.050 seconds
While2 Took 0.050 seconds
While2 Took 0.050 seconds
While2 Took 0.050 seconds
While2 Took 0.000 seconds
While2 Took 0.411 seconds
While2 Took 0.001 seconds
While2 Took 0.150 seconds
While2 Took 0.051 seconds
While2 Took 0.002 seconds
While2 Took 0.106 seconds
Any thoughts, greatly appreciated. Also, when I run two separate queries, this time doubles for the while loops.
PHP SQL While Loop speed help
Moderator: General Moderators
Re: PHP SQL While Loop speed help
Apparently, all I had to do we recycle Apache.