如何在php mysql中使用限制查询?

时间:2018-04-16 08:07:27

标签: php mysql

首席会员数据库值: -

 member_id = 1;
 member_no= 001;
 status = '2';

第二个会员数据库值

 member_id = 2;
 member_no= 002;
 status = '1';

第三个会员数据库值

member_id = 3;
member_no= 003;
status = '2';

我的Php查询

$select_query_sender = "select * from member where status='1' ORDER BY member_id ASC LIMIT 1";
   $run_sender = mysqli_query($con,$select_query_sender);
   while ($row_sender = mysqli_fetch_array($run_sender)) {        
    $member_no_sender = $row_sender['member_no'];
    echo $member_no_sender;    }

我尝试使用限制查询来回复状态1成员列表,除了输出到 member_no = 002; ,但输出什么都不显示,我错过了请帮助任何一个。

2 个答案:

答案 0 :(得分:1)

您的代码没问题,但请检查您的查询是否从db获取任何行。

 $select_query_sender = "select * from member where status='1' ORDER BY 

 member_id ASC LIMIT 1";

 $run_sender = mysqli_query($con,$select_query_sender);

 if($run_sender->num_rows > 0 ){

    while ($row_sender = mysqli_fetch_array($run_sender)) {  

        echo $row_sender['member_no']; // echo member_no
   }

 }else{
   echo "no row";
 } 

答案 1 :(得分:0)

...试

$select_query_sender = "select * from member where status='1' ORDER BY member_id ASC LIMIT 1";
$run_sender = mysqli_query($con,$select_query_sender);
$row_sender = mysqli_fetch_object($run_sender);
echo $row_sender->member_no ;