数组中的位置 SQL
WHERE IN Array SQL
更新:if sched_id = 2 {输出 user1,user2,user4,user5 }
你能帮我解决这些问题吗..Bcoz 现在当我 运行 代码时,只能使用 WHERE IN .. 找到第一个数字,或者是否有另一种方法来获取/搜索数组中的值 sql 用于 WHERE.. 谢谢!
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 } ?>
其中 Schedule_ID 由数组值组成。
SELECT user.Schedule_ID, user.FullName
FROM user
WHERE
FIND_IN_SET($sched_id, user.Schedule_ID) > 0
AND user.UserType = 0
更新:if sched_id = 2 {输出 user1,user2,user4,user5 }
你能帮我解决这些问题吗..Bcoz 现在当我 运行 代码时,只能使用 WHERE IN .. 找到第一个数字,或者是否有另一种方法来获取/搜索数组中的值 sql 用于 WHERE.. 谢谢!
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 } ?>
其中 Schedule_ID 由数组值组成。
SELECT user.Schedule_ID, user.FullName
FROM user
WHERE
FIND_IN_SET($sched_id, user.Schedule_ID) > 0
AND user.UserType = 0