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

时间:2017-02-23 16:57:09

标签: php mysql

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

$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>       

1 个答案:

答案 0 :(得分:1)

SELECT userID, userName, userProfession, userPic FROM tbl_users WHERE userProfession = "Teacher" ORDER BY userID DESC

是你需要的。