WebProWorld Part of WebProNews.com
Page One Link To Us Edit Profile Private Messages Archives FAQ RSS Feeds  
 

Go Back   WebProWorld > Webmaster, IT and Security Discussion > Database Discussion Forum
Subscribe to the Newsletter FREE!


Register FAQ Members List Calendar Arcade Chatbox 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!

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 08-01-2005, 05:32 PM
richkoi's Avatar
WebProWorld Veteran
 

Join Date: Aug 2003
Location: Columbus, Ohio
Posts: 487
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
Reply With Quote
  #2 (permalink)  
Old 08-01-2005, 10:42 PM
WebProWorld Member
 

Join Date: Feb 2004
Location: New York
Posts: 73
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, 12: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
Tags: , , , ,



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

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


Search Engine Optimization by vBSEO 3.2.0