0
      $Brand=$_POST['Brand'];
         if(isset($_POST['Brand']))
          {
          $Brand = implode(",", $_POST['Brand']);   
           } else {
            $Brand = "";
          }
       echo "brands are :" .$Brand;
       echo "<br>";
       $sql2= "SELECT * FROM brand_master1 WHERE brand_name in ('$Brand')";
       $result2 = mysql_query($sql2);
       $row = mysql_fetch_array($result2,MYSQL_BOTH);
       $bid=$row['id'];
       echo "brand id is:";      
        print_r($bid);

in the below code am trying to get ids of brands by giving brand values to the query.... but it is giving only single id.... please anyone help me... my tables are... brand_master1(id,brand_name)

siri
  • 17
  • 5

1 Answers1

0

Try this $Brand = implode("','", $_POST['Brand']);

if(isset($_POST['Brand']))
      {
      $Brand = implode("','", $_POST['Brand']);   
       } else {
        $Brand = "";
      }
   echo "brands are :" .$Brand;
   echo "<br>";
   $sql2= "SELECT * FROM brand_master1 WHERE brand_name in ('$Brand')";

Note this line of code "','"

it is not only appending the elements with , comma but also with ' single quotes

Now what will be the output of this

brand_name in ('$Brand')"

OUTPUT

brand_name in ('a','b','c')

But in your case it was

brand_name in ('a,b,c')

WARNING

Also mysql_* functions are deprecated you must have to look at this Why shouldn't I use mysql_* functions in PHP?

Community
  • 1
  • 1
zzlalani
  • 22,960
  • 16
  • 44
  • 73