Jump to content

Recommended Posts

Hello,

 

I am using PHP to create some filter and i have a SELECT problem...

 

I have a table with 2 fields: id_filter, id_product

 

how can i make a selection like this:

 

SELECT id_product FROM filters WHERE id_filter='5' and id_filter='7'

 

Is it possible to use multiple values for id_filter in the same query? because i have products that have 3 filters values applied to them and i want to select them by that certain filters!

 

is there a multiple mysql select function that i'm missing?

 

any ideas would be grat... thanks in advance

Link to comment
https://forums.phpfreaks.com/topic/145564-is-it-possible-to-select-like-this/
Share on other sites

Yes here solution

 

 


<?php

$idfilters = array (1,3,5,7)

foreach ($idfilters as $idfilter)

{
$dbquery = mysql_query("SELECT id_product FROM filters WHERE id_filter= '$idfilter'")
or die ("Error in select query") ;
}


?>
other solution too use or 

SELECT id_product FROM filters WHERE id_filter= 2 or id_filter=3

Expanding on what Mchl said:

 

<?php
$idfilters = array (1,3,5,7)

$idfilters = implode(", ", $idfilters);
$query = mysql_query("SELECT id_product FROM filters WHERE id_filter IN($idfilters)") or die ("Error in select query") ;

?>

 

A tad bit easier and a ton less MySQL server load.

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.