Skip to content
WJunction - Webmaster Forum

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

Status
Not open for further replies.
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:
$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
 

4 comments

Status
Not open for further replies.

About the author

L
Active Member · Joined
I am a skilled programmer within PHP,HTML,CSS,MYSQL and also the owner of several websites Programming, Football...
1,367
Messages
1
Reactions
38
Points

Advertise on WJunction

Reach 1000's of webmasters, hosts & affiliates. Banner & sponsored-thread slots available.

Contact us
Back
Top Bottom