My count is echoing the $count variable as 0 when it should be 1. When i run the MySQL Query myself in PHPMYADMIN it returns a row. So why when i echo $count is it showing as 0? Any help would be great. Thanks in advance!

Yep, if you take a look at the 2 images at the bottom of my first post you can see the query and then the value of $count under it. The photo after that is the same Query but ran in PHPMYADMIN and it returns a row a data.

The only thing i can think of off the top of my head is that you've got more than one database, and have filled the wrong table. This code should work. (Though it's inefficient - you should be running a single query to do all your pulling, and at most 3 queries to do all your updating. You're currently doing 1+2*N queries, instead of 4.)

First, i'd like to start with a blank page. We'll try it this way, and if you dont like it, you can always try and incorporate it into your code - but i'm going to try and streamline it as much as possible. Also not gonna give you the code straight out, want to see if you can follow my logic!

Establish your database link.

Here's the SELECT query i would use;

SELECT l.leadid,s.Status
FROM `leads` AS l
LEFT JOIN `ValidISP` AS s
ON l.IPISP = s.ISP AND l.IPCheck = 'NO';

Note the Left Join here. This makes sure all leads are pulled, even if they dont have a matching ISP. You probably want to add an ORDER BY too, but we're not overly stressed about the order of items atm.

foreach row in the result setAll rows should have one of three results in the 'Status' column; 'PASS', 'FAIL', or NULL.If status is null, make it MANUAL.assign the leadid to a new element one of three elements of a new array - i'm gonna call it $update. (hint: the keys of the elements should match your status). This will result in a 2-dimensional array.EFE; we are now done selecting our data.

Now to update it!foreach element of $update;if the count of elements of this key is greater than 0,

UPDATE leads
SET IPCheck = '&lt;elementname&gt;'
WHERE LeadID IN ('&lt;imploded list of elements of this element, seperated by commas. no quotes around this.&gt;');

EFE

Done.

EDIT: Added an if to counter the 0-updates, and formatting on the queries to make them more readable.I'm also moderately sure you could do this whole script in a single query, but i'm gonna have to tap @guido2004 and make sure i'm not sticking my foot in my mouth again.

You're on the right track.$new_array should be defined outside the loop, otherwise each time you loop through you'll blank out the loop.$new_array = array('PASS' => array(),'FAIL' => array(),'MANUAL' => array());

$query2 = "SELECT l.leadid,s.STATUS
FROM `leads` AS l
LEFT JOIN `ValidISP` AS s
ON l.IPISP = s.ISP AND l.IPCheck = 'NO';";
$result2=mysql_query($query2);
//Put this up here, because we need it to store the values we are about to get.
$new_array = array('PASS' =&gt; array(),'FAIL' =&gt; array(),'MANUAL' =&gt; array());
while($row2 = mysql_fetch_array($result2))
{
// $validisp=$row2['ISP']; This doesnt exist. Why do you need this?
$validispstatus=$row2['Status'];
$leadid=$row2['LeadID'];
if ( is_null($validispstatus) ) { //I prefer is_null to an equals condition, but you can do either. Keep in mind that NULL is not the same as 'NULL'.
$validispstatus="MANUAL";
}
//Scoot this up, and put the value into our array...
$new_array[$validispstatus][] = $leadid;
}
//Now we have the values in the array, time to make our updates..
foreach ($new_array as $key =&gt; $value) { //We need the key too.
if ( count($value) &gt;0 ) { //We only care about the current set of values.
$query3="UPDATE leads
SET IPCheck = '$key' //Here's where our key was needed.
WHERE LeadID IN (".implode(',',$value).");"; //Smash the values all together with commas between.
mysql_query($query3);
}
}
mysql_close();