Jump to content

[SOLVED] Selecting all users where .... Please help


xcali

Recommended Posts

Hi gang

For my school project we have to build a website for a modeling agency.

Now when a costumer wants to browse models he/she can do two things:

1) enter the name and hit search - then get the results displayed on the page... or

2) he can search by criteria.

The search criteria basically consists of:

- choose gender (male female both)

- choose body type

- choose ethnicity

- choose ... so on so on

 

now my problem is the sql query

$data = mysql_query("SELECT * FROM users WHERE registered_as='model' and gender='$gender'" and ethnicity='$ethnicity' and btype='$btype');

so now it chooses all the models with criteria the costumer chose.

how would i choose all the genders? in my database users are either registered as males or females so the query still has to choose from all users. 

Is it possible to like type in gender=all or gender=* or something ?

Link to comment
Share on other sites

Thank you for your response

 

I was afraid someone would say omit this from your query - now my problem is that the search criteria consists of many options user can choose from. Once he chooses everything he hits submit results would display.

 

The thing is though that in my script theres only 1 query which is the one i have posted before:

$data = mysql_query("SELECT * FROM users WHERE registered_as='model' and gender='$gender'" and ethnicity='$ethnicity' and btype='$btype');

 

now if i was to omit gender i would have to make a new query like you said

<?php $data = mysql_query("SELECT * FROM users WHERE registered_as='model' and ethnicity='$ethnicity' and btype='$btype'); ?>

but what if the user would want all ethnicities? now i would have to another query

<?php $data = mysql_query("SELECT * FROM users WHERE registered_as='model' and gender='$gender' and btype='$btype'); ?>

if i want all body types

$data = mysql_query("SELECT * FROM users WHERE registered_as='model' and gender='$gender'" and ethnicity='$ethnicity');

if i want to have all genders and all ethnicities then another query and so on. Since the form consists of many different options i would have to have 10, 20 or even more queries - you see where im getting?

Maybe im not getting this or my understanding of mysql is... bad - but i guess what i want is to have to have everything in 1 query, thus i thought that there was a way to just say "select * from users where gender='Male' or 'Female' or 'All?' '*?')" or something universal like that. But thank you so much for going through my post and reading it!  Appreciate it :)

 

If someone knows a way to write it or a different way to do it please post it - thank you!

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.