doa24uk Posted September 22, 2009 Share Posted September 22, 2009 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; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/175125-solved-mysql-php-hanging-after-first-run-through/ Share on other sites More sharing options...
JonnoTheDev Posted September 22, 2009 Share Posted September 22, 2009 How many records are returned from the initial query? Quote Link to comment https://forums.phpfreaks.com/topic/175125-solved-mysql-php-hanging-after-first-run-through/#findComment-922986 Share on other sites More sharing options...
kickstart Posted September 22, 2009 Share Posted September 22, 2009 Hi You are using $result for both the result set you are looping round and the result of your update queries. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/175125-solved-mysql-php-hanging-after-first-run-through/#findComment-922994 Share on other sites More sharing options...
doa24uk Posted September 22, 2009 Author Share Posted September 22, 2009 I am SUCH an idiot .... stupid obvious thing! Thanks, all working now! Quote Link to comment https://forums.phpfreaks.com/topic/175125-solved-mysql-php-hanging-after-first-run-through/#findComment-923001 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.