Hi
I have got my query close to what I need but I want to try and include a couple of other conditions:
I would like is 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).
The data gets timestamped as in goes into the
table with $today
and [B]$today = date(“U”);
So if the result from this query::
[code=php]
$today = date(“U”);
$days7ago = $today-604800;
$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”;
would have been:
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 sql query or
would it be easier / more efficient to do it with php
after the query ( or maybe use a second query ) ?
Thanks for any advice ?