Jump to content

[SOLVED] execution delay


kranthi117

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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)..

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.