zintani Posted August 29, 2011 Share Posted August 29, 2011 Hello, While I am working on my code I faced this problem, which is Fatal error: Maximum execution time of 30 seconds exceeded in C:\wamp\www\factory1.php on line 100 Call Stack # Time Memory Function Location 1 0.0062 379160 {main}( ) ..\factory1.php:0 Any help to come over this problem. My database is quite large (600 MB). Thanks in advance. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted August 29, 2011 Share Posted August 29, 2011 Post the relevant code. Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted August 29, 2011 Share Posted August 29, 2011 well you can use set_time_limit to increase a scripts maximum execution time.. however you should not experience this issue..what is the code on line 100.. and the relevant surrounding code Quote Link to comment Share on other sites More sharing options...
zintani Posted August 29, 2011 Author Share Posted August 29, 2011 Here is the code after some enhancements <?php if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Book", $con); $sender = $_POST['email']; $result = ("SELECT * FROM employeelist"); $messenger = mysql_query("SELECT * FROM employeelist WHERE Email_id = '$sender'"); $message = mysql_fetch_array($messenger); $fname = $message ['firstName']; $lname = $message ['lastName']; $query = mysql_query ($result); $num_rows = mysql_num_rows($query); echo "<br/>"; while($row = mysql_fetch_array($query)) { $receiver = $row['Email_id']; $first = $row['firstName']; $last = $row['lastName']; echo "<br />"; if ($sender != $receiver) { $sql =( "SELECT * FROM message JOIN recipientinfo ON message.mid = recipientinfo.mid WHERE message.sender = '$sender' AND recipientinfo.rvalue = '$receiver' AND recipientinfo.rtype = 'TO' "); $done = mysql_query ($sql)or die("Query:<br>{$query}<br>Error:<br>".mysql_error()); $show = mysql_num_rows($done); if ($show != 0) { echo "The number of ties between the sender $fname $lname and the receiver $first $last is : " ; echo $show; } else{ } } else{ } } mysql_close($con); ?> Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 29, 2011 Share Posted August 29, 2011 Never EVER run queries in loop!!! 99% of the time you can get the information you want with a single query. The other 1% of the time you are doing something you shouldn't. You need to learn how to do JOINs. Your code is very unorganized making this difficult to resolve. But, it comes down to the fact that you only need ONE query to get all the relationships between the sender and the receiver (without having to do a loop of all employees). I think the following will work based upon what I think I am able to understand of your database structure. If this isn't correct ,please post the full details of the tables involved along with an explanation of exactly what you are trying to achieve. if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("Book", $con); $sender_email = mysql_real_escape_string(trim($_POST['email'])); $query = "SELECT firstName, lastName FROM employeelist WHERE Email_id = '$sender'"; $result = mysql_query($query); if(!$sender = mysql_fetch_assoc($messenger)) { echo "No user found for the email adrress: {$_POST['email']}"; } else { $sender_fname = $message ['firstName']; $sender_lname = $message ['lastName']; $query = "SELECT firstName, lastName, count(recipientinfo.rvalue) as `count` FROM employeelist JOIN message ON employeelist.Email_id = .sender JOIN recipientinfo ON message.mid = recipientinfo.mid WHERE message.sender = '$sender_email' AND recipientinfo.rtype = 'TO' GROUP BY recipientinfo.rvalue"; $result = mysql_query($query) or die("Query:<br>{$query}<br>Error:<br>".mysql_error()); echo "<br/>"; while($row = mysql_fetch_array($result)) { $receiver_fname = $row['firstName']; $receiver_lname = $row['lastName']; $count = $row['count']; echo "The number of ties between the sender {$sender_fname} {$sender_lname} and the receiver {$receiver_fname} {$receiver_lname} is: {$count}<br>\n"; } } mysql_close($con); Quote Link to comment 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.