Current location: Hot Scripts Forums » Programming Languages » PHP » [SOLVED] Only pulling last entry in the table with fetch_array, why?


[SOLVED] Only pulling last entry in the table with fetch_array, why?

Reply
  #1 (permalink)  
Old 08-16-08, 08:03 PM
ProxyTise ProxyTise is offline
New Member
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Arrow [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,$errstr20);
}             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
Reply With Quote
  #2 (permalink)  
Old 08-17-08, 06:15 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
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

Reply With Quote
  #3 (permalink)  
Old 08-17-08, 10:48 AM
ProxyTise ProxyTise is offline
New Member
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Yeah it was a problem with my bracket

PHP Code:

$churl fsockopen($link,$port,$errno,$errstr20);


Last edited by UnrealEd; 08-18-08 at 04:34 AM. Reason: please use the [php]tag when posting php code
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
MYSQL database countll Database 2 06-19-07 04:20 PM
Selecting only the second entry of a table anarchoi Database 4 06-19-07 02:15 PM
What do you think of my database structure? Oskare100 Database 5 12-27-06 07:43 AM
PHP: Different table entry from same form? Stormrider Script Requests 3 05-07-05 08:19 AM
Deleting one entry on dynamic table Bonzo PHP 1 04-19-04 02:36 PM


All times are GMT -5. The time now is 07:53 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.