-3

Update: if sched_id = 2 {Output user1,user2,user4,user5 }

Can you help me with this guys..Bcoz Now when i run the code only the 1st number can be found using WHERE IN .. or is there another way to get / search value in array sql to use in WHERE.. Thank you!

Click to view the IMAGE

     <?php

 $dbServername = "localhost"; //servername
 $dbUsername = "root"; //database username
 $dbPassword = ""; //database password
  $dbName = "test_db"; //database name

 //Create connection
 $conn = mysqli_connect($dbServername, $dbUsername, $dbPassword, $dbName);

  if(isset($_POST["sched_id"]))  
  { 

 $sched_id = $_POST["sched_id"];

?>
  <!-- Col-12 -->
        <div class="col-md-12">

          <?php

           $sql = "SELECT user.Schedule_ID, user.FullName FROM user

            WHERE $sched_id IN (Schedule_ID) AND user.UserType = 0";
           $results = mysqli_query($conn, $sql);
           $row = mysqli_fetch_assoc($results);

            ?>
           <div class="row">
           <?php
           foreach ($results as $i => $result) :
             $rows = ceil(count($result) / 3); 
           ?>
             <?php if($i % $rows === 0 && $i !== 0): ?>
             </div><div class="row">
           <?php endif;?>

           <div class="col-sm-4">
            <?php echo $result['FullName']; ?>
           </div>
           <?php endforeach;?>

        </div>

      </div>

   <?php } ?>

where Schedule_ID is compose of array values.

Jun
  • 138
  • 1
  • 9

1 Answers1

2

Try with FIND_IN_SET(str,strlist):

SELECT user.Schedule_ID, user.FullName 
FROM user 
WHERE 
FIND_IN_SET($sched_id, user.Schedule_ID) > 0
AND user.UserType = 0
double-beep
  • 5,031
  • 17
  • 33
  • 41
Tính Ngô Quang
  • 4,400
  • 1
  • 33
  • 33