iEntry 10th Anniversary Forum Rules Search
WebProWorld
Register FAQ Calendar Mark Forums Read
Database Discussion Forum This is the place to find help resolving those nagging questions you have about implementing and using all kinds of databases. Need help writing a query? Need an opinion on Oracle? Post here!

Share Thread: & Tags

Share Thread:

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2005, 06:32 PM
richkoi's Avatar
WebProWorld Veteran
 
Join Date: Aug 2003
Location: Atlanta, GA
Posts: 451
richkoi RepRank 0
Default Searching within a range - mySQL php

I set up a database to have a searchable range of numbers. I have table set up that has an X column and a Y column. The X equals the low side of the range and the Y the high side.

How do I create a mySQL query that will search for one number within that range?

For example:

ITEM = Item 1
X = 3
Y = 5

ITEM = Item 2
X = 2
Y = 3

Search Variable = 4

Results: Item 1

Let me know if this is unclear. Thanks,

Rich
__________________
Me
Reply With Quote
  #2 (permalink)  
Old 08-01-2005, 11:42 PM
WebProWorld Member
 
Join Date: Feb 2004
Location: New York
Posts: 82
JSeverson RepRank 0
Default

Hi,
Unless I'm misunderstanding your question, I think what you would want to do is this:

$result = mysql_query("SELECT ITEM FROM table WHERE X > $SearchVariable AND Y < $SearchVariable");

Hope that helps...
__________________
Jeff T. Severson
J.T.S. Design, Inc.
Reply With Quote
  #3 (permalink)  
Old 08-04-2005, 01:35 PM
Evic's Avatar
WebProWorld Pro
 
Join Date: Jul 2005
Location: Eielson AFB, AK
Posts: 174
Evic RepRank 0
Default

Actually JServerson, you were close - but got it backwards :)

$result = mysql_query("SELECT FROM table WHERE X < '" . $SearchVariable . "' AND Y > '" . $SearchVariable . "'");
__________________
Michael Wales

My Blog: GibThis: Video Game Blog
Reply With Quote
Reply

  WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum

Thread Tools
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 09:16 AM.



Search Engine Optimization by vBSEO 3.3.0