Jump to content

How to make the search period longer


zintani

Recommended Posts

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.

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

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

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.