Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

jrock2004

macrumors 6502
Original poster
May 4, 2008
375
0
PA
What I am trying to do is pull all the records in a table that have a value of 0 in the Seen column. Now in the database there is multiple times you see 0 in the see column. The way it is pulling it, it is giving the last instance when it sees it. I want the first record that shows the instance of 0 in Seen

Code:
$sql = "SELECT * FROM " .$table_name. " WHERE Seen = 0";
	$results = @mysql_query($sql) or die(mysql_error());
	while ($row = mysql_fetch_array($results))
    {
    	$subID = $row['subscriber_id'];
        $fname = $row['realtor_fname'];
        $lname = $row['realtor_lname'];
        $phone1 = $row['realtor_phone1a'];
        $phone2 = $row['realtor_phone1b'];
        $phone3 = $row['realtor_phone1c'];
        $timedate = $row['time_created'];
        $sugar = $row['sugarcrm_imported'];
    }

Thanks
 
Not sure if I completely understand what you're wanting, but how about this,
Code:
$sql = "SELECT * FROM $table_name WHERE Seen = 0 ORDER BY time_created DESC LIMIT 1";
I simply added an ordering based on creation time in descending order, and limited it to one result. I removed some of the concatenation as it wasn't necessary. Also, for the zero, depending how it's stored you may need "0" rather than just 0. And make sure the Seen column has an uppercase S as it may be case sensitive.
 
@OP:

BTW, instead of "mysql_fetch_array($results)" since you're obviously referencing the result set by an associative array, use either "mysql_fetch_assoc($results)" or "mysql_fetch_array($results,MYSQL_ASSOC)" (which is the same as the former).

Otherwise your version will return both an associative array and number indices which is inefficient, unless desired.

-jim
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.