Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

The Database Forum


You are currently viewing our The Database Forum as a guest. Please register to participate.
Login



Reply
mysql query - is within range
Old 07-03-2007, 04:00 PM mysql query - is within range
Extreme Talker

Posts: 182
Trades: 0
I have a 'user_id' column in my 'user' table. All users with user ids from 1900 up to 2500 experienced a glitch when registering. When a user logs in, if their user id is within that range, i let them click a button to change something. The way I did this was just simply hard code the values in with php:

PHP Code:
if ( $user_id >= 1900 && $user_id <= 2500 ) { // if within glitched user id range
    /* show button */

This works fine but I'm just curious if there would be a way to do something like this using just sql. Like...if I wanted to check to see if something is in a column in between row 30 and row 100 of my table. I can picture situations where this might be useful.

Sorry if this is confusing.

chris
bhgchris is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-03-2007, 06:16 PM Re: mysql query - is within range
ChancesAre's Avatar
Skilled Talker

Posts: 84
Trades: 0
SELECT COUNT(*) FROM user WHERE user_id BETWEEN 1900 AND 2500
ChancesAre is offline
Reply With Quote
View Public Profile
 
Old 07-03-2007, 09:58 PM Re: mysql query - is within range
Extreme Talker

Posts: 182
Trades: 0
That wasn't what I was talking about but no worries. There would really never be a need to do what I was talking about.
After posting my question I realized that it was stupid and actually made no sense. I guess a hectic morning at work along with being sick was clouding my mind.

I did learn someting though I knew nothing about BETWEEN and now I do.

Thank you!
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 07-06-2007, 03:54 PM Re: mysql query - is within range
Learning Newbie's Avatar
Defies a Status

Latest Blog Post:
Astounding Republican Paranoia
Posts: 5,662
Name: John Alexander
Trades: 0
You could use BETWEEN which is more convenient and less typing, but it gets processed as OR when your query runs. You could also just move the if to your WHERE clause in MySQL. Probably wouldn't do anything in this case 'cause you're only getting one record, but in a big table when you only want some data, evaluating that in the database instead of the web server will make your code run faster.
__________________

Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
Learning Newbie is offline
Reply With Quote
View Public Profile
 
Old 07-06-2007, 08:13 PM Re: mysql query - is within range
Novice Talker

Posts: 10
Name: nathan
Trades: 0
if it's just rown numbers you wanted, you could always use the limit/offest.. that way your always going to select X rows from offset Y... there are uses I'm sure
nathanr is offline
Reply With Quote
View Public Profile
 
Old 07-09-2007, 02:24 PM Re: mysql query - is within range
Extreme Talker

Posts: 182
Trades: 0
nathanr that is exactly what i was talking about.

I haven't tried it yet but I'm sure it works great. I built a pagination function a while back using offset and completely forgot about that clause.

SELECT * FROM table LIMIT 10 OFFSET 20

That would select rows 21 - 31 I'm guessing

thanks!
bhgchris is offline
Reply With Quote
View Public Profile
 
Old 07-10-2007, 09:05 PM Re: mysql query - is within range
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,898
Name: Keith Marshall
Location: Connecticut
Trades: 0
Actually I think it should be written as:

SELECT * FROM table LIMIT 10, 20

I'm not sure if OFFSET is valid sql or not.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is online now
Reply With Quote
View Public Profile
 
Reply     « Reply to mysql query - is within range
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24134 seconds with 12 queries