爆炸,然后内爆,然后在表中显示复选框为选中状态


explode then implode then show in table with checkbox as checked

我在SQL中有一个列,我使用odbc连接它,它的数据格式如下

1|2|3|4|5

每个数字表示每个工作者的id。顺便说一下,这个问题与我之前的问题有关。参见下方的链接

编辑内爆字符串

因此,如果我选择该列,它将返回类似上面的输出。在编辑中,我需要先将其分解,然后将其分解为某种字符串,就像一样

1,2,3,4,5

现在的问题是,我将如何创建一个循环,根据字符串(1,2,3,4,5)中的每个字符串来选择工作人员的名字和姓氏,然后回显一个表,如果列表中包括他们的ID,则会选中他们各自的复选框。这是我的代码,

$que = "SELECT assignedto FROM PROJECTS where projectname = '$projname'";
$queres = odbc_exec($conn,$que);
$res = odbc_result($queres, 1);
$analysts_arr = explode("| ", $res);
$analysts = implode(",", $analysts_arr);
//die($analysts);
$que2 = "DECLARE @s VARCHAR(MAX)
         DECLARE @d VARCHAR(MAX)
         SET @s='$analysts'
         set @d = 'select id, firstname, lastname from Accounts where id in('+@s+')'
         exec (@d)";
//die($que2);
$query = odbc_exec($conn,$que2);
echo odbc_result_all($query);
$result = odbc_result_all($query);
echo "<table class='table table-striped table-bordered table-hover' id='dataTables-example' style='margin-top:10px;'>
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Last Name</th>
                                        <th>First Name</th>
                                    </tr>
                                </thead>;";
foreach($result as $val){
   $user_id = $val['id'];
   $users[$id] = $val;
        echo "<tbody>
            <tr class='odd gradeX'>
                <td><input type='checkbox' value='<?php echo odbc_result($queres, 1); ?>' name='analyst[]'/></td>
                <td></td>
                <td></td>
            </tr>
        </tbody>";
}

我的代码返回下方的错误显示

警告:odbc_result_all():此结果索引中没有可用的元组

警告:odbc_result_all():此结果索引中没有可用的元组;

警告:为foreach()提供的参数无效

找到了解决问题的方法。为其他人发布它,也可以作为他们的指南。

这是我做的变通方法。

$que = "SELECT assignedto FROM PROJECTS where projectname = '$projname'";
$queres = odbc_exec($conn,$que);
$res = odbc_result($queres, 1);
$analysts_arr = explode("| ", $res);
//print_r($analysts_arr);
echo "<table class='table table-striped table-bordered table-hover' id='dataTables-example' style='margin-top:10px;'>
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Last Name</th>
                                        <th>First Name</th>
                                    </tr>
                                </thead>";
foreach($analysts_arr as $analysts) {
    //foreach($analysts_arr as $idan){
        $quean = "SELECT lastname,firstname FROM ACCOUNTS where id = '$analysts'";
        $queresan = odbc_exec($conn,$quean);
        $resas = odbc_result($queresan, 1);
        $resasf = odbc_result($queresan, 2);
        echo "<tbody>
            <tr class='odd gradeX'>
                <td>";
                echo $analysts;
                echo "</td>
                <td>";
                echo $resas;
                echo "</td>
                <td>";
                echo $resasf;
                echo "</td>
            </tr>
        </tbody>";
    //}
}