Jump to content

from array to SQL Query


Alechko

Recommended Posts

Hi folks,

I need some help with taking vars from array to the DB.

 

my array something like this:

Array ( [0] => 137 [1] => 800 [2] => 732 [3] => 198) 

 

The Array contains IDs of products in database.

 

I want to do something like this first:

 

$db->Query("SELECT catID FROM `products` WHERE `id` = '$VAROFARRAY'");

 

That the DB Query will loop the whole array variables.

 

And then:

$db->Query("SELECT `name` FROM `categories` WHERE `id= '$catID'");

 

I a little bit complicated with it..

 

thanks..

Link to comment
Share on other sites

thanks,

but maybe you didn't get me.

I have already the array of my products.

All I have to is to loop it on the query of categories to get the name.

 

Array => 1,3,5,7,8 (The ID's of the products)

 

and I want something like:

 

forearch($array as pID) ...
while($row = $db->Query("SELECT FROM `cats` WHERE `id` = '{$pID}'") ..

 

Something liike that..

 

thank you very much...

Link to comment
Share on other sites

That's what he's doing, but he's doing it in one query. He's also making sure they're integers before putting them in the query.

 

SELECT whatever FROM cats WHERE id IN (1,2,3,5,7,8)

 

Will select rows where id is 1,2,3,5,7 or 8

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.