Reputation: 67
Maximum execution time of 120 seconds exceeded in C:\wamp64\www....
I hope my loop is not infinite.
if(isset($_POST['del']))
{
$id = $_GET['id'];
$st = "Y";
$stmtp = $user_home->runQuery('SELECT * FROM invoice WHERE BRN = :inv ORDER BY Sr ASC ');
$stmtp->bindParam(':inv',$id);
$stmtp->execute();
$rowcd = $stmtp->fetch(PDO::FETCH_ASSOC);
if($stmtp->rowCount() > 0)
{
while($rowcd)
{
extract($rowcd);
$stmtd = $user_home->runQuery('UPDATE invoice
SET State=:uname
WHERE Sr = :crn');
$stmtd->bindParam(':crn',$Sr);
$stmtd->bindParam(':uname',$st);
$stmtd->execute();
}
}
}
Select statement has 5 rows. (sometime it may have less)
Upvotes: 0
Views: 2786
Reputation: 2885
From your usage of bindParam()
, I'm assuming you're using PDO that you've abstracted into a class.
You're only calling the fetch()
once which returns a single row, then using a while statement on that. That never gets updated in the loop, so it always evaluates to TRUE
, thus continuing the loop.
To test this theory, you can run a simple loop on an array, which runs until a break point:
<?php
while(array(1,2,3)){
echo date('H:i:s');
}
I'm not entirely sure where the $Sr
variable is coming from, but based on the ORDER BY
clause in your first query, it's returned in the first query.
Therefore, you need to loop through and fetch the next row each time like so:
...
while ($row = $stmtp->fetch()) {
$stmtd = $user_home->runQuery('UPDATE invoice
SET State=:uname
WHERE Sr = :crn');
$stmtd->bindParam(':crn',$row['Sr']);
$stmtd->bindParam(':uname',$st);
$stmtd->execute();
}
...
Upvotes: 1
Reputation: 1182
It is an infinite loop.
You're doing:
$rowcd = $stmtp->fetch(PDO::FETCH_ASSOC);
and then evaluating it:
while($rowcd)
When it should be:
while($rowcd = $stmtp->fetch(PDO::FETCH_ASSOC))
Instead of both lines
Upvotes: 0