Sayuj Raghavan

Sayuj Raghavan

  • NA
  • 52
  • 6.5k

How to use array values in Where Clause in MySQL?

Apr 18 2016 4:45 AM
Hi , this is the code which i am working on,
  
  
          <?php
               public function Welcome_Students($uid)
                  {


                    $q=mysqli_query($this->db,"SELECT School_Name FROM school_teacher_reg WHERE csr='$uid'")or die(mysqli_error($this->db));
               while($row1=mysqli_fetch_array($q,MYSQLI_ASSOC))
                    {
                 $Schoolname=$row1[School_Name];
                        }
                 $q1=mysqli_query($this->db,"SELECT csr FROM school_student WHERE               sch_name='$Schoolname'")or die(mysqli_error($this->db));

                  while($row3=mysqli_fetch_array($q1,MYSQLI_ASSOC))
                     {
                      $csr[]= $row3;     //till here i am getting the output
                      foreach($csr as $key){
                      $query=mysqli_query($this->db,"SELECT U.username,U.uid,U.bio FROM users U WHERE U.status='1' AND U.uid='$key' ORDER BY RAND() LIMIT 10")or die(mysqli_error($this->db));
                  while($row=mysqli_fetch_array($query,MYSQLI_ASSOC))
                   {
                     $data[]=$row;
                      }
                   }
                return data;
          } }
?>
 
     I have been successfull  executing till $csr[]= $row3; where i am able to fetch $csr[] array values .But when i try to fetch each values of that array in $csr[], I am unable to retrieve values from the table using  the following query inside the foreach loop
   "SELECT U.username,U.uid,U.bio FROM users U WHERE U.status='1' AND U.uid='$key' ORDER BY RAND() LIMIT 10").
     

Answers (12)