Maximum execution time problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Maximum execution time problem

Post by m2babaey »

Hi
I have a table with 3 fields: id, product_id and subcategort_id
I have repeated data in that table. I wrote the code below to delete the repeated data
but I got this error:

Fatal error: Maximum execution time of 60 seconds exceeded in G:\programs\xamp\xampp\htdocs\carat\test.php on line 9
could you please have a look at the code and suggest how I can avoid this error and do what I need?
this is the code:

Code: Select all

 
<?php
include 'connect.php';
 
$wasbefore=mysql_query("SELECT * FROM prod_subcat ")or die(mysql_error());
$wasbeforenum=mysql_num_rows($wasbefore);
echo $wasbeforenum;
$id=0;
while($wasbeforenum-$id){
$wasbefore=mysql_query("SELECT * FROM prod_subcat WHERE id='$id' ")or die(mysql_error());
$row=mysql_fetch_array($wasbefore);
$prod=$row['productID'];
$sub=$row['subcategoryID'];
$wasbefore=mysql_query("SELECT * FROM prod_subcat WHERE subcategoryID='$sub' AND productID='$prod' ")or die(mysql_error());
$wasbeforenum=mysql_num_rows($wasbefore);
if($wasbeforenum>1){
mysql_query("DELETE FROM `prod_subcat` WHERE `id`='$id' ") or die(mysql_error());
}
$id++;
}
 
?>
 
User avatar
The_Anomaly
Forum Contributor
Posts: 196
Joined: Fri Aug 08, 2008 4:56 pm
Location: Tirana, Albania

Re: Maximum execution time problem

Post by The_Anomaly »

I'm no expert in loops, and have never touched the mysql_* functions (I'm a PDO fanatic), but if all you're doing is a simple database query, you probably have an infinite loop going on there or something.

However, if you're asking how to increase your maximum execution time, you can easily do that in your php.ini.
m2babaey
Forum Contributor
Posts: 364
Joined: Sun May 20, 2007 9:26 am

Re: Maximum execution time problem

Post by m2babaey »

solved!
i used the same variable in while loop and while statement.
Post Reply