...

View Full Version : Distinct & Limit Not Working



elabuwa
11-11-2011, 04:08 AM
Hi guys,

DB is mysql.
I have the below query which i'm trying to run through PHP.



$sql = "SELECT DISTINCT pid FROM campaign_details WHERE camp_id='$camp_id' LIMIT 7";
$newquery = mysql_query($sql) or die(mysql_error());


There are 10 distinct pid values but I want only 7.
The stupid thing returns all of them when I need to limit them at 7.

Any work around this?
Or Do I need to go and take a coffee break and have another look? haha.

Cheers

Old Pedant
11-11-2011, 06:40 PM
Ummm...so just limit it to 7 in the PHP code.



$cnt = 7;
while ( ...fetch one row ... )
{
...
if ( --$cnt == 0 ) break;
}

Old Pedant
11-11-2011, 06:42 PM
But now that I look at your query again, I don't see why it isn't working.

Try running the query *OUTSIDE* of PHP and see what you get.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum