473,326 Members | 2,104 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Can I use max and minimums for row results ?

290 100+
Hi
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
  1. $sql = "SELECT distinct ip_adr, cb_id FROM cb_promo WHERE link_dt BETWEEN '$days7ago' and '$today' ORDER BY cb_id";
  2.  $result = mysql_query($sql)    or die("could not find PROMO". mysql_error());  
  3.  while($row = mysql_fetch_assoc($result)){
  4.  
  5.  $cb_promo_id = $row['cb_id'];
  6.  $ipadd = $row['ip_adr'];
  7. echo "<br> ID: $cb_promo_id, IP add: $ipadd";
  8.  }
  9.  
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 query
or do I need to use if's to walk through the result array ?

Thanks for any advice :)
Jan 16 '10 #1
1 1348
jeddiki
290 100+
Maybe I should show where I am getting
the date range values from.

The data gets timestamped as in goes into the
table with $today

and $today = date("U");

so:

Expand|Select|Wrap|Line Numbers
  1. $today = date("U");
  2. $days7ago = $today-604800;
  3.  
  4. $sql = "SELECT distinct ip_adr, cb_id FROM cb_promo WHERE link_dt BETWEEN '$days7ago' and '$today' ORDER BY cb_id";
  5.  $result = mysql_query($sql)    or die("could not find PROMO". mysql_error());  
  6.  while($row = mysql_fetch_assoc($result)){
  7.  
  8.  $cb_promo_id = $row['cb_id'];
  9.  $ipadd = $row['ip_adr'];
  10. echo "<br> ID: $cb_promo_id, IP add: $ipadd";  
Hope that makes it clearer.
Would appreciate any help from someone who knows how I can add the
extra conditions that I mentioned in my first post.
Jan 17 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Francisco | last post by:
I have this question: I have a simple search to a db, something like: "select description from games where year = '1990'" suppose I get 300 results, I would like to display this in pages of 30...
4
by: Aaron Reimann | last post by:
I am trying to build a table using results from a database query. Right now (code below), the code displays each result in a new <tr>. I am wanted to display 3 results in one <tr> </tr>, and then...
2
by: CharitiesOnline | last post by:
Hello, I have set this script up to add paging to a search results page. Which on the first page works fine. I calculates how many pages there should be depending on the number of results returned...
5
by: George | last post by:
Hi, Anyone has the background for explaining? I have made a search on my name and I have got a link to another search engine. The link's title was the search phrase for the other search engine...
15
by: JKop | last post by:
I've been searching the Standard for info about the minimum "bits" of the intrinsic types, but haven't been able to find it. Could anyone please point me to it? -JKop
1
by: Don | last post by:
I am new to Indexing Services, have been researching the MS Site as well as web articles on DevHood, etc. I have set up a seperate catalog ("KnowledgeBase") on Win XP with a number of files. I am...
0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
4
by: jaYPee | last post by:
I have downloaded some source code but I want this to convert the results into datagrid. dr = cmd.ExecuteReader() '**************************************** ' SHOW THE RESULTS...
1
by: oaklander | last post by:
Is it okay to keep creating queries with the same ResultSet Object reference (results)? Here is what I am currently using in my Database statements with Oracle and everything works but was wondering...
3
by: Bigalan | last post by:
Hello, i am relatively new to PHP and i am struggling with printing multiple search results on to different pages. The code below works ok but when you click on next page button, it brings up a blank...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.