Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old January 28th, 2004, 03:33 AM
Anonymous Anonymous is offline
Registered User
Codewalkers God 35th Plane (22000 - 22499 posts)
 
Join Date: Apr 2007
Posts: 22,309 Anonymous User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 24
How to generate this complicated query?

Pls do help out with this prob in generating a query..

I hav 'date of birth' column in a table.

I have two variables (lowerage and upperage) and have to generate a query that will return records in which the age is between these two limits.

Can someone pls generate a query statement for this... i have given up trying!

Thank uuuuu

Reply With Quote
  #2  
Old January 28th, 2004, 03:41 AM
nawlej nawlej is offline
Contributing User
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: Dallas, Tx. USA
Posts: 2,008 nawlej User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 11 h 7 m 51 sec
Reputation Power: 4
RE: How to generate this complicated query?

Try:
SELECT * FROM yourtable WHERE date_of_birth BETWEEN $lower AND $upper;

Reply With Quote
  #3  
Old January 28th, 2004, 03:45 AM
Nicky's Avatar
Nicky Nicky is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Neverland
Posts: 606 Nicky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 26 sec
Reputation Power: 2
RE: How to generate this complicated query?

Try this
php Code:
Original - php Code
  1.  
  2. <?php
  3.     $result = mysql_pconnect("localhost", DBUSERNAME, DBPASSWD)or die ('I cannot connect to the database because: ' . mysql_error());
  4.  $conn = mysql_select_db(DBNAME) or die ('I cannot select the database because: ' . mysql_error());
  5.  
  6.     $query = "select date_of_birth from tablename where (age<$upperage) and (age>$lowerage)";
  7.  $result = mysql_query($query);
  8.   if ($result)
  9.       $row = mysql_fetch_object($result);
  10.   else
  11.     return false;
  12.  
  13.  $age=$row->age;
  14. ?>


I haven't checked it for errors.

Reply With Quote
  #4  
Old January 28th, 2004, 03:47 AM
Nicky's Avatar
Nicky Nicky is offline
Contributing User
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Location: Neverland
Posts: 606 Nicky User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 3 m 26 sec
Reputation Power: 2
RE: How to generate this complicated query?

nawlej's solution has better syntax.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > How to generate this complicated query?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT