dongyishen5796
2017-02-23 16:57
浏览 65
已采纳

使用PDO使用php从mysql数据库中提取特定值

This is the PHP code am using. I want to extract only details of userProfession = "Teacher" from the database how do I achieve that?

$stmt = $DB_con->prepare('SELECT userID, userName, userProfession, userPic FROM tbl_users ORDER BY userID DESC');
$stmt->execute();

if($stmt->rowCount() > 0)
{
    while($row=$stmt->fetch(PDO::FETCH_ASSOC))
    {
        extract($row);
        ?>
        <div class="col-xs-3">
            <p class="page-header"><?php echo $userName."&nbsp;/&nbsp;".$userProfession; ?></p>
            <img src="user_images/<?php echo $row['userPic']; ?>" class="img-rounded" width="250px" height="250px" />
            <p class="page-header">
            <span>
            <a class="btn btn-info" href="editform.php?edit_id=<?php echo $row['userID']; ?>" title="click for edit" onclick="return confirm('sure to edit ?')"><span class="glyphicon glyphicon-edit"></span> Edit</a> 
            <a class="btn btn-danger" href="?delete_id=<?php echo $row['userID']; ?>" title="click for delete" onclick="return confirm('sure to delete ?')"><span class="glyphicon glyphicon-remove-circle"></span> Delete</a>
            </span>
            </p>
        </div>       

图片转代码服务由CSDN问答提供 功能建议

这是我正在使用的PHP代码。 我想从数据库中仅提取userProfession =“Teacher”的详细信息,如何实现?

  $ stmt = $ DB_con-&gt; prepare('SELECT userID  ,userName,userProfession,userPic FROM tbl_users ORDER BY userID DESC'); 
 $ stmt-&gt; execute(); 
 
if($ stmt-&gt; rowCount()&gt; 0)
 {
 while(  $ row = $ stmt-&gt; fetch(PDO :: FETCH_ASSOC))
 {
 extract($ row); 
?&gt; 
&lt; div class =“col-xs-3”&gt; 
  &lt; p class =“page-header”&gt;&lt;?php echo $ userName。“&amp; nbsp; /&amp; nbsp;”。$ userProfession;  ?&gt;&lt; / p&gt; 
&lt; img src =“user_images /&lt;?php echo $ row ['userPic'];?&gt;”  class =“img-rounded”width =“250px”height =“250px”/&gt; 
&lt; p class =“page-header”&gt; 
&lt; span&gt; 
&lt; a class =“btn btn  -info“href =”editform.php?edit_id =&lt;?php echo $ row ['userID'];?&gt;“  title =“click for edit”onclick =“return confirm('确保编辑?')”&gt;&lt; span class =“glyphicon glyphicon-edit”&gt;&lt; / span&gt; 编辑&LT; / A&GT;  
&lt; a class =“btn btn-danger”href =“?delete_id =&lt;?php echo $ row ['userID'];?&gt;”  title =“click for delete”onclick =“return confirm('肯定要删除?')”&gt;&lt; span class =“glyphicon glyphicon-remove-circle”&gt;&lt; / span&gt; 删除&lt; / a&gt; 
&lt; / span&gt; 
&lt; / p&gt; 
&lt; / div&gt;  
   
 
  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

1条回答 默认 最新

  • dqqfuth6736 2017-02-23 17:00
    最佳回答
    SELECT userID, userName, userProfession, userPic FROM tbl_users WHERE userProfession = "Teacher" ORDER BY userID DESC
    

    is what you need.

    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题