Activity Stream
48,167 MEMBERS
6831 ONLINE
besthostingforums On YouTube Subscribe to our Newsletter besthostingforums On Twitter besthostingforums On Facebook besthostingforums On facebook groups

Results 1 to 5 of 5
  1.     
    #1
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com

    Default Litewarez Tip : (Sql Selecting multiple ids with one query)

    Heya ,

    What ill show you now is just a simple tip that you should be using in your websites if you are already not!

    No the old fasioned way of selecting ids is to do a foreach loops like so

    Code: 
    foreach($ids as $id){
        //Delete $id or Select $id here
    }
    This causes multiple queries but the best way to do this with one query is by using the mysql WHERE IN Clause like below

    PHP Code: 
    $ids = array(22,47,121); // this can be from $_POST
    $query "SELECT title FROM mytable WHERE id IN (".implode(",",$ids).")";

    mysql_query($query); 
    No the mysql resource that is returned will have them rows in it and only taken 1 query

    Hope you all like this lil tip
    litewarez Reviewed by litewarez on . Litewarez Tip : (Sql Selecting multiple ids with one query) Heya :), What ill show you now is just a simple tip that you should be using in your websites if you are already not! No the old fasioned way of selecting ids is to do a foreach loops like so foreach($ids as $id){ //Delete $id or Select $id here } Rating: 5
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  2.   Sponsored Links

  3.     
    #2
    Member
    This would not work because implode($ids) would evaluate to 2247121

  4.     
    #3
    Member
    Website's:
    litewarez.net litewarez.com triniwarez.com
    lol whoops i forgot the first argument for implode!... fixed now lol
    Join Litewarez.net today and become apart of the community.
    Unique | Clean | Advanced (All with you in mind)
    Downloads | Webmasters


    Notifications,Forum,Chat,Community all at Litewarez Webmasters


  5.     
    #4
    Respected Developer
    Website's:
    X4B.org
    If you are doing less than 3 items it is more efficient to use multiple AND ... statements btw

  6.     
    #5
    Member
    Quote Originally Posted by litewarez View Post
    lol whoops i forgot the first argument for implode!... fixed now lol
    Ahh, cool. I never knew you could do that with mysql . I just thought 'IN' was for subqueries

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. help me in selecting a host
    By raisajid in forum General Discussion
    Replies: 4
    Last Post: 28th Feb 2012, 06:07 PM
  2. Replies: 3
    Last Post: 22nd Jan 2011, 02:57 AM
  3. Need Help Selecting a Wordpress Theme
    By persnalid in forum Community Cooperative
    Replies: 1
    Last Post: 3rd Nov 2010, 06:42 AM
  4. Litewarez Feture list (Reason why your site belongs on Litewarez)
    By litewarez in forum Webmaster Discussion
    Replies: 42
    Last Post: 15th May 2010, 05:58 PM
  5. need help in selecting a theme
    By xwarlordx in forum Community Cooperative
    Replies: 11
    Last Post: 11th May 2010, 10:31 AM

Tags for this Thread

BE SOCIAL