Jump to content

Recommended Posts

I'm having a horrible time trying to figure out how to do this.

I have a form with several search options. I'm trying to build the search criteria. Here's a very simplified example of what I'd like to do:

 

I have a table with data like this:

 

userid qid   answer

24         8   Female

32         8   Male

50         8   Female

24         29   Arizona

32         29   California

50         29   California

 

I would like to query this table to find userids that are Female (24 and 50) AND from California (32 and 50). So the result should be userid 50. I can't do this in one query (unless I'm mistaken) so I would need to first get a list of userids who are females, like this:

 

$query1 = "SELECT userid from myTable WHERE qid = 8 AND answer = 'Female'"

 

But then, after getting that result set, how do I go through the results to find users from California?

 

If I'm looking at this all wrong please point me in the right direction.

 

 

Link to comment
https://forums.phpfreaks.com/topic/152455-solved-querying-a-resultset/
Share on other sites

UID = unique ID -- I mean, a unique identifier for each row.

 

And you're missing my point -- how do you know to look for 8 specifically?

 

My apologies. There is a unique id, answerid.

8 comes from a multiple select box in the search form. In this case there are options Male, Female and all. There's actually 7 select boxes in total.

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.