Jump to content

Recommended Posts

Hi all.

 

I'm working on a project in PHP that requires users to fill out a profile about themselves, though I've got a mind blank when it comes to making this query as short as possible.

 

Basically I have 2 tables (accounts & dropbox). The users details are stored in the accounts table and the answers to some of the questions are just a value that matches up with a row found in the dropbox table.

 

I need to return valueA of a cell in dropbox where valueB equals that of the value in accounts AND where valueC = '4'. (valueC defines the question we're looking up, so it will be different for each time we run through this query, it would be 4,5,6,7)

 

This needs to be done for several different columns in the accounts table, is this possible to do with just a single query?

I could go about doing this with several individual queries but that would be messy and it would haunt me.

 

It's perhaps a little hard to explain without visualising it, so here's a link.. http://3es.com/RavenStar/table_structure.html

 

Any help would be greatly appreciated,

thanks in advance.

Basically I'm trying to combine all these queries into one, somehow.

SELECT * FROM dropbox WHERE type = '4' AND accounts.smoke = dropbox.value

SELECT * FROM dropbox WHERE type = '5' AND accounts.drink = dropbox.value

SELECT * FROM dropbox WHERE type = '6' AND accounts.drugs = dropbox.value

SELECT * FROM dropbox WHERE type = '7' AND accounts.country = dropbox.value

 

I tried to provide a list of my table in the link provided in my first post.

 

Maybe you would like something like this:

 

mysql_query("(SELECT * FROM dropbox d left join accounts a ON (a.smoke = d.value) where type = 4)
UNION
(SELECT * FROM dropbox d left join accounts a ON (a.drink = d.value) where type = 5)
UNION
(SELECT * FROM dropbox d left join accounts a ON (a.drugs = d.value) where type = 6)
UNION
(SELECT * FROM dropbox d left join accounts a ON (a.country = d.value) where type = 7)");

 

I might be able to come up with a better way later...

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.