[SOLVED] Only pulling last entry in the table with fetch_array, why?
I have a database that has two columns. One being 'email' and the other being 'url' from sites. I have trying to make this script to test if a site is down and to send an email if it is, which it is. The problem I am having is, the code is only pulling the last entry in the table. It will not query all entries. Basically I need the code to check the last row and continue on and not just stop.
I have been racking my brains with this for two days now, any help would be wonderful.
PHP Code:
<?php include 'includes/opendb.php'; $result = mysql_query("SELECT * FROM sites"); while ($row = mysql_fetch_array($result)) {
$link=$row["url"]; $email=$row["email"]; $port="80"; $s_link = str_replace("::", ":", $link); list($addr,$port)= explode (':',"$s_link"); //Test the server connection $churl = fsockopen($link,$port,$errno,$errstr, 20); } if (!$churl){ $to = $email; $from ="Site Monitor"; $subject = "$link Is Down"; $body = "My Message"; mail($to, $subject, $body); } else die () ?>
Last edited by UnrealEd; 08-17-08 at 06:10 AM.
Reason: please use the [php]wrapper when posting php code
the reason why it isn't working is because you're looping over the data in your database, but you only check if the site is up and running after the loop. You need to move the if (!$churl) part into the while loop. Don't forget to remove the else die (); part, otherwise your script will stop working as soon as a working site is found
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks