Jump to content

Urgent Help! Shouldn't be this hard.... :)


wglenn01

Recommended Posts

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]

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

 

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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;

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.