kranthi117 Posted January 24, 2008 Share Posted January 24, 2008 herez my code <?php //function to fetch all the rows function mysql_fetch_all($result) { while($ret[] = mysql_fetch_assoc($result)){} return $ret; } $connection = @mysql_connect("localhost","user","pass"); @mysql_selectdb("db"); $sql = "SELECT DISTINCT year FROM table ORDER BY year"; $query = mysql_query($sql); $user = mysql_fetch_all($query); foreach($user as $val) { $year[] = $val["year"]; } function display($arr,$index,$check) { $length = count($arr); $limit = intval($length/$index); for($counter = 0; $counter < $limit; $counter++) { echo "<tr>\n"; for($i = 0; $i < $index; $i++) { $val = $arr[$counter * $index + $i]; if(empty($val)) continue; if($val == $check) echo "<td><input type=\"checkbox\" value=\"" . $val . "\" checked=\"checked\"></td>\n<td>" . $val . "</td>\n"; else echo "<td><input type=\"checkbox\" value=\"" . $val . "\"></td>\n<td>" . $val . "</td>\n"; } echo "</tr>\n"; } $i = ($counter) * $index; echo "<tr>\n"; while($i < $length) { $val = $arr[$i]; if(empty($val)) continue; if($val == $check) echo "<td><input type=\"checkbox\" value=\"" . $val . "\" checked=\"checked\"></td>\n<td>" . $val . "</td>\n"; else echo "<td><input type=\"checkbox\" value=\"" . $val . "\"></td>\n<td>" . $val . "</td>\n"; $i++; } echo "</tr>"; } var_dump($year); display(array("1","2","3","4","5","6"),5,2); //exit(); -- point 1 display($year,5,2); ?> this is executing without ny probs and giving the expected results but my problem is when i remove exit at point 1 the extcution time shoots up to 60 seconds, and with exit is in place the exuction is is less than 2 seconds. plz note that $year has no more than 5 elements in it simply put 1. $year is an array(result from a database query). 2. there is a function named display both 1 & 2 r working individually faster but they r very slow when put together Quote Link to comment https://forums.phpfreaks.com/topic/87492-solved-execution-delay/ Share on other sites More sharing options...
pdkv2 Posted January 24, 2008 Share Posted January 24, 2008 herez my code <?php //function to fetch all the rows function mysql_fetch_all($result) { while($ret[] = mysql_fetch_assoc($result)){} return $ret; } $connection = @mysql_connect("localhost","user","pass"); @mysql_selectdb("db"); $sql = "SELECT DISTINCT year FROM table ORDER BY year"; $query = mysql_query($sql); $user = mysql_fetch_all($query); foreach($user as $val) { $year[] = $val["year"]; } function display($arr,$index,$check) { $length = count($arr); $limit = intval($length/$index); for($counter = 0; $counter < $limit; $counter++) { echo "<tr>\n"; for($i = 0; $i < $index; $i++) { $val = $arr[$counter * $index + $i]; if(empty($val)) continue; if($val == $check) echo "<td><input type=\"checkbox\" value=\"" . $val . "\" checked=\"checked\"></td>\n<td>" . $val . "</td>\n"; else echo "<td><input type=\"checkbox\" value=\"" . $val . "\"></td>\n<td>" . $val . "</td>\n"; } echo "</tr>\n"; } $i = ($counter) * $index; echo "<tr>\n"; while($i < $length) { $val = $arr[$i]; if(empty($val)) continue; if($val == $check) echo "<td><input type=\"checkbox\" value=\"" . $val . "\" checked=\"checked\"></td>\n<td>" . $val . "</td>\n"; else echo "<td><input type=\"checkbox\" value=\"" . $val . "\"></td>\n<td>" . $val . "</td>\n"; $i++; } echo "</tr>"; } var_dump($year); display(array("1","2","3","4","5","6"),5,2); //exit(); -- point 1 display($year,5,2); ?> this is executing without ny probs and giving the expected results but my problem is when i remove exit at point 1 the extcution time shoots up to 60 seconds, and with exit is in place the exuction is is less than 2 seconds. please note that $year has no more than 5 elements in it simply put 1. $year is an array(result from a database query). 2. there is a function named display both 1 & 2 r working individually faster but they r very slow when put together Inside your while loop replace if(empty($val)) continue; With if(empty($val)){ $i++; continue; } you forget to increment the $i; Regards Sharad Quote Link to comment https://forums.phpfreaks.com/topic/87492-solved-execution-delay/#findComment-447561 Share on other sites More sharing options...
kranthi117 Posted January 24, 2008 Author Share Posted January 24, 2008 hmmmmmm.......... tnkz a lot.... that explains every thing.... 1. it worked individually coz null is not encountered. 2. it gave expected result coz null is at the end of the array and script is terminated aft 60 secs by the apache server, the earlier elements of the array r sent to the output... tnkz for correcting me...(i intended to use break insted of continue).. Quote Link to comment https://forums.phpfreaks.com/topic/87492-solved-execution-delay/#findComment-447564 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.