PHP从数据库中选择多个选择选项中获取多个值

时间:2019-02-13 07:17:15

标签: php html mysql

我正在尝试从数据库中的多个选择选项中获取多个选择的值。我得到了结果,但是它在多个选择框中重复出现。任何帮助深表感谢。谢谢。 这是我的代码:

<?php

    $query = "select pf_no,name from programmer order by name";
    $results=mysqli_query($con, $query); 
    if (mysqli_num_rows($results)>=0) 
    {
        while($row=mysqli_fetch_array($results))
        {
            $main_query="select p.name from programmer p,transaction t  where p.pf_no = t.pf_id  and t.owner = '0' and t.project_id = '$pr_id' group by p.name";
            $main_results=mysqli_query($con, $main_query);
            if (mysqli_num_rows($main_results)>=0) 
            {
                while($row1=mysqli_fetch_array($main_results))
                {
?>
                <option value="<?php echo $row['pf_no']; ?>"<?php if($row1['name']==$row['name']) {echo 'selected="selected"';} ?>><?php echo $row['name']; ?></option>
<?php

                }
            }
        }
    }

0 个答案:

没有答案