Go Back   vb.org Archive > vBulletin Modifications > Archive > vB.org Archives > General > Member Archives
FAQ Community Calendar Today's Posts Search

Reply
 
Thread Tools
"MySQL Query" query ;-) Details »»
"MySQL Query" query ;-)
Version: , by Ninth Dimension Ninth Dimension is offline
Developer Last Online: Jun 2016 Show Printable Version Email this Page

Version: Unknown Rating:
Released: 08-21-2002 Last Update: Never Installs: 0
 
No support by the author.

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
(in this example I want it to pull id's 8, 4, 2 and 1)

Thanx

Show Your Support

  • This modification may not be copied, reproduced or published elsewhere without author's permission.

Comments
  #2  
Old 08-21-2002, 02:31 PM
Ninth Dimension's Avatar
Ninth Dimension Ninth Dimension is offline
 
Join Date: Oct 2001
Location: London, England.
Posts: 739
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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:
$array[] = 8;
$array[] = 4;
$array[] = 2;
$array[] = 1
so if it can be worked so that the query uses the array i'd really apprechate it.
Reply With Quote
  #3  
Old 08-21-2002, 03:15 PM
Ninth Dimension's Avatar
Ninth Dimension Ninth Dimension is offline
 
Join Date: Oct 2001
Location: London, England.
Posts: 739
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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"
please help :bunny:
Reply With Quote
  #4  
Old 08-21-2002, 03:20 PM
Xenon's Avatar
Xenon Xenon is offline
 
Join Date: Oct 2001
Location: Bavaria
Posts: 12,878
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

the or part is correct, be sure your table has an id column
Reply With Quote
  #5  
Old 08-21-2002, 03:25 PM
Ninth Dimension's Avatar
Ninth Dimension Ninth Dimension is offline
 
Join Date: Oct 2001
Location: London, England.
Posts: 739
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

yes, it has an id column, the OR one is only returning one result.
Reply With Quote
  #6  
Old 08-21-2002, 03:42 PM
Ninth Dimension's Avatar
Ninth Dimension Ninth Dimension is offline
 
Join Date: Oct 2001
Location: London, England.
Posts: 739
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

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.
Reply With Quote
  #7  
Old 08-29-2002, 11:38 AM
TeddyBare69 TeddyBare69 is offline
 
Join Date: Jun 2002
Location: CA, US
Posts: 93
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

Have you tried this yet?
Code:
SELECT * FROM table WHERE id IN  ( 8,4,2,1 )
You can also add this to put them in order
Code:
SELECT * FROM table WHERE id IN  ( 8,4,2,1 ) ORDER BY id
Reply With Quote
  #8  
Old 08-29-2002, 12:04 PM
Ninth Dimension's Avatar
Ninth Dimension Ninth Dimension is offline
 
Join Date: Oct 2001
Location: London, England.
Posts: 739
Благодарил(а): 0 раз(а)
Поблагодарили: 0 раз(а) в 0 сообщениях
Default

I learnt about that a few days ago, very userful indeed. Thank you.
Reply With Quote
Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 10:45 PM.


Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.
X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.04463 seconds
  • Memory Usage 2,269KB
  • Queries Executed 21 (?)
More Information
Template Usage:
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (1)ad_showthread_beforeqr
  • (4)bbcode_code
  • (1)bbcode_php
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)modsystem_post
  • (1)navbar
  • (6)navbar_link
  • (120)option
  • (8)post_thanks_box
  • (8)post_thanks_button
  • (1)post_thanks_javascript
  • (1)post_thanks_navbar_search
  • (8)post_thanks_postbit_info
  • (7)postbit
  • (8)postbit_onlinestatus
  • (8)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available:
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files:
  • ./showthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_post_thanks.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • forumjump
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • post_thanks_function_post_thanks_off_start
  • post_thanks_function_post_thanks_off_end
  • post_thanks_function_fetch_thanks_start
  • post_thanks_function_fetch_thanks_end
  • post_thanks_function_thanked_already_start
  • post_thanks_function_thanked_already_end
  • fetch_musername
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • post_thanks_function_can_thank_this_post_start
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • showthread_complete