wglenn01 Posted November 5, 2010 Share Posted November 5, 2010 Ok all I need some help with this. I have been stuck for two days. Basically I have a form that asks a registrant their gender and age, then my script spits out a list of race categories they qualify for. The situation calls for the registrant to be able to register for any category YOUNGER than them, but not older. Screen Shot #1 shows my database setup (this can be changed if you have any better ideas...) that holds the race category information. Here is the sql statement I am using to pull a female racer information, where $race_age is their submitted age. "SELECT * from counts where female=1 and $race_age < age_end and $race_age > age_start" This works, but doesn't pull any categories YOUNGER Than their age. I'm stumpped Thanks for any help in advance. [attachment deleted by admin] Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/ Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 Are you running the query directly in phpMyAdmin? Or can you send your php and html processing query script? Are you echoing all the fields in your php/html? Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130799 Share on other sites More sharing options...
jcbones Posted November 5, 2010 Share Posted November 5, 2010 Try: (not sure if it will work). "SELECT * from counts where female=1 and $race_age > age_start" Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130800 Share on other sites More sharing options...
wglenn01 Posted November 5, 2010 Author Share Posted November 5, 2010 Are you running the query directly in phpMyAdmin? Or can you send your php and html processing query script? Are you echoing all the fields in your php/html? I'm not sure what you mean. I am running the query on my php page that outputs the results of the query into a select box. I'm just not sure how to get it to select the correct age categores, or if there is a better way to structure the database to make it work. Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130804 Share on other sites More sharing options...
OldWest Posted November 5, 2010 Share Posted November 5, 2010 Can you post your code please for the select box? Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130806 Share on other sites More sharing options...
wglenn01 Posted November 5, 2010 Author Share Posted November 5, 2010 Try: (not sure if it will work). "SELECT * from counts where female=1 and $race_age > age_start" Oh my gosh dude. This might have done it, I will report back I totally couldn't wrap my brain around this. Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130807 Share on other sites More sharing options...
Yucky Posted November 5, 2010 Share Posted November 5, 2010 I'd have one column 'gender' rather than two and do something like: 0 - male 1 - female 2 - both Then the query could be along the lines of: SELECT * FROM races WHERE gender = $user_gender OR gender = 2 AND $user_age > age_start AND $user_age < age_end; Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130808 Share on other sites More sharing options...
litebearer Posted November 5, 2010 Share Posted November 5, 2010 btw probably need to use the less than or = to / greater than or = to, as if the age matches either end of the span (ie 19 - 34 span - age =19 or 34) it will not show for on < or > - make sense? Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130809 Share on other sites More sharing options...
wglenn01 Posted November 5, 2010 Author Share Posted November 5, 2010 btw probably need to use the less than or = to / greater than or = to, as if the age matches either end of the span (ie 19 - 34 span - age =19 or 34) it will not show for on < or > - make sense? Will do, thank you all! I think we have it. Two days of scratching my head on that one. Mabey I need to leave the building for a bit Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130814 Share on other sites More sharing options...
DavidAM Posted November 5, 2010 Share Posted November 5, 2010 You could use IN for the gender and BETWEEN for the age. SELECT * FROM races WHERE gender IN ($user_gender, 2) AND $user_age BETWEEN age_start AND age_end; Note that BETWEEN includes both ends of the range (so it is >= and <=) If you use the code with the OR in it, you need to put parenthesis around that group or it will be evaluated differently than you think: SELECT * FROM races WHERE (gender = $user_gender OR gender = 2) AND $user_age > age_start AND $user_age < age_end; Quote Link to comment https://forums.phpfreaks.com/topic/217876-urgent-help-shouldnt-be-this-hard/#findComment-1130882 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.