Jump to content

[SOLVED] Mysql / PHP Hanging after first run through


doa24uk

Recommended Posts

Hi guys,

 

Here's my script. The script is working as it should apart from the fact it's hanging on the first result. When I refresh the page (to re-run the script) it runs perfectly fine.

 

Why?? Could this code be optimised? Pretty sure it could!!

 

 


<?php
// CONNECT TO DB


// Select everything from DB
$result = mysql_query("SELECT * FROM table")
or die(mysql_error());  

// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {

//Define variables
$new = $row['linkurl'];
$url = $row['linkservice'];
$emailstatus = $row['emailstatus'];
$email = $row ['email'];
$origpage = $row['origpage'];



switch ($url){

        case "mysite.com":       
$file = file_get_contents($new);
$split = explode('Error',$file);
if (count($split) > 1 AND $emailstatus==N)
{

$headers = "From: ASite.com\r\n" .
    "X-Mailer: php";
$subject = "Email Subject";
$body = "Email body text";
mail($email, $subject, $body, $headers);

$result = mysql_query("UPDATE table SET emailstatus ='S', linkstatus ='D' WHERE linkurl='$new' AND email='$email'")
or die(mysql_error());
}
elseif (count($split) > 1 AND $emailstatus == Y) 
{
// Email already sent, update link status to be dead
$result = mysql_query("UPDATE table SET linkstatus ='D' WHERE linkurl='$new' AND userid='$userid'")
or die(mysql_error());

}
else {
// Link is live ... no action necessary
}
        break;
        
}
}
?>

Archived

This topic is now archived and is closed to further replies.

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