【问题标题】:explode then implode then show in table with checkbox as checked爆炸然后内爆然后显示在表格中,选中复选框
【发布时间】:2016-03-23 14:17:45
【问题描述】:

我在 SQL 中有一个列,我使用 odbc 与之连接,其中包含这样格式的数据

1| 2| 3| 4| 5

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

Editing an imploded string

因此,如果我选择该列,它将返回与上述类似的输出。在编辑中,我需要先将其分解,然后将其内爆为某种字符串,如下所示

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() 提供的参数无效

【问题讨论】:

    标签: php loops odbc explode implode


    【解决方案1】:

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

    这是我所做的解决方法。

    $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>";
        //}
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-12-20
      • 1970-01-01
      • 2015-05-09
      • 1970-01-01
      • 2011-10-29
      相关资源
      最近更新 更多