Jump to content

Is it possible to SELECT like this?


stefffff

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.