I have got my query close to what I need but I want to try and include a couple of other conditions:
I want the result to contain:
a minimum of 2 rows that contain the same cb_id (but different ip_adr).
and
a maximum of 4 rows that contain the same cb_id (but different ip_adr).
So if the result from this query:
Expand|Select|Wrap|Line Numbers
- $sql = "SELECT distinct ip_adr, cb_id FROM cb_promo WHERE link_dt BETWEEN '$days7ago' and '$today' ORDER BY cb_id";
- $result = mysql_query($sql) or die("could not find PROMO". mysql_error());
- while($row = mysql_fetch_assoc($result)){
- $cb_promo_id = $row['cb_id'];
- $ipadd = $row['ip_adr'];
- echo "<br> ID: $cb_promo_id, IP add: $ipadd";
- }
ID: EBFORTUNE, IP add: 55.167.889.182
ID: EBFORTUNE, IP add: 78.167.109.182
ID: FEDYDE, IP add: 85.106.68.197
ID: FEDYDE, IP add: 85.176.68.227
ID: FEDYDE, IP add: 89.106.68.127
ID: FHHHH45, IP add: 78.167.109.182 // only one - not enough
ID: P97GFRH, IP add: 56.107.9.182 // only one - not enough
ID: RSEDE38M, IP add: 78.167.17.182
ID: RSEDE38M, IP add: 78.167.109.182
ID: RSEDE38M, IP add: 23.167.109.182 // 7 the extra 3 rows must be filtered out
ID: RSEDE38M, IP add: 78.16.143.182
ID: RSEDE38M, IP add: 78.19.109.102
ID: GGG72FHH, IP add: 178.7.109.18 // only one - not enough
ID: RSEDE38M, IP add: 17.167.19.2
ID: RSEDE38M, IP add: 712.17.39.182
Then the result I want to get is (min 2, maz 4):
ID: EBFORTUNE, IP add: 55.167.889.182
ID: EBFORTUNE, IP add: 78.167.109.182
ID: FEDYDE, IP add: 85.106.68.197
ID: FEDYDE, IP add: 85.176.68.227
ID: FEDYDE, IP add: 89.106.68.127
ID: RSEDE38M, IP add: 78.167.109.182
ID: RSEDE38M, IP add: 78.167.109.182
ID: RSEDE38M, IP add: 78.167.109.182
ID: RSEDE38M, IP add: 78.167.109.182
Is there a way to put this into my query
or do I need to use if's to walk through the result array ?
Thanks for any advice :)