Jump to content

[SOLVED] Combine Queries


hostfreak

Recommended Posts

I was wondering how I would combine queries that are stored in an array? The reason is to be able to order the multiple queries from the same "ORDER BY" which will be obtained from an url parameter.

 

Also, the reasons the queries are in an array is, because they use the "WHERE" clause to SELECT "WHERE year = '$year'", and there could be several years (the years are obtained from $_POST) and I don't think there is a way to do something like: WHERE year = '$year[0],$year[1]'. Thanks in advance.

Link to comment
Share on other sites

Got rid of the arrays, ran the modified query, no result. Could it be due to me doing this:

YEAR(time_stamp) IN ($yrs)

 

I am actually comparing the years against the year found from the field 'time_stamp' (0000-00-00 00:00:00) with the mysql YEAR() function. Not sure if that matters?

Link to comment
Share on other sites

BTW, in cases where this technique can't be used, the answer to your original question is

 

SELECT a,b,c FROM table WHERE something

UNION

SELECT a,b,c FROM table WHERE something_else

UNION

SELECT ..... etc

 

I had read about UNION and wanted to try it in this situation, but wasn't sure how to implement it where the queries were stored in an array then looped through as well as the results (as this is, or was if the other code works).

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.