The Arcive of vBulletin Modifications Site. |
|
"MySQL Query" query ;-) Details »»
|
|||||||||||||||||||||||||
I've got a loop in my script that will find out a bunch of ID numbers, each of these numbers will need to be queried and the results pulled out of the database.
I could put a seperate query within each each loop to get the results, but this has two problems, first one is that it will create way too many queries on that page (up to 30 un-needed extra queries), and the second problem is that the results will be in reverse (because of the way the loop works, and the loop can't be reversed, that won't work). what I promise to do insted is take all these ID, and run one query to get them all, and just have mysql put them into the order I want. Problem is that I don't now what the query should look like ![]() Below is an example of what I think it should look like to give you an idea of what I mean, maybe you can point me in the right direction? Code:
SELECT * FROM table WHERE id = 8,4,2,1 Thanx Show Your Support
|
|||||||||||||||||||||||||
| Comments |
|
#2
|
||||
|
||||
|
BTW, just so you know, if this is going to make it any easier (I know it will for me) the results of the loop are going to be put into an array, i.e.
PHP Code:
|
|
#3
|
||||
|
||||
|
I've just been talking to someone that suggested I used one of he two below, neither worked
![]() Code:
"SELECT * FROM table WHERE id = 8 OR id = 4 OR id = 2 OR id = 1" "SELECT * FROM table WHERE id = 8 AND id = 4 AND id = 2 AND id = 1" |
|
#4
|
||||
|
||||
|
the or part is correct, be sure your table has an id column
|
|
#5
|
||||
|
||||
|
yes, it has an id column, the OR one is only returning one result.
|
|
#6
|
||||
|
||||
|
OK, you can hit me now, i was being a pratt, it's true that I did have an id column, but it was not the id column that wanted to call.
Lets put this down to the typo LOL ![]() anyway, if anyone knows how to do this via an array, i'm still interested in finding out, cheers. |
|
#7
|
|||
|
|||
|
Have you tried this yet?
Code:
SELECT * FROM table WHERE id IN ( 8,4,2,1 ) Code:
SELECT * FROM table WHERE id IN ( 8,4,2,1 ) ORDER BY id |
|
#8
|
||||
|
||||
|
I learnt about that a few days ago, very userful indeed. Thank you.
|
![]() |
|
|