duanhui1869 2016-08-16 06:55
浏览 18

使用以下条件从数据库中选择值

<select name="sample" class="form-control" id='select'>
  <?php 
    $sam1="attingal"; $sam2="kollam"; 
    $getstd="SELECT stdid,firstname,lastname FROM student WHERE centre='$sam1' AND centre='$sam2' ORDER BY firstname ASC"; 
    $qs=$conn->query($getstd); 
    $qs->setFetchMode(PDO::FETCH_NUM); 
    while($getstd=$qs->fetch()) { 
  ?>
    <option value='<?php echo $getstd[0]; ?>'>
      <?php echo $getstd[1]." ".$getstd[2]; ?>
    </option>
    <?php } ?>
</select>

Nothing is displaying when I run the above code

  • 写回答

1条回答 默认 最新

  • dongtiran7769 2016-08-16 07:34
    关注

    Your problem is here:

    WHERE centre='$sam1' AND centre='$sam2'
    

    That condition can never be true. a field can't hold 2 different values at once. You supposedly wanted OR, so change it to

    WHERE centre='$sam1' OR centre='$sam2'
    
    评论

报告相同问题?

悬赏问题

  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题