首页 > 解决方案 > 对 Php PDO 中的所有数据进行排名

问题描述

我一直在努力按电话号码和预订状态对用户进行排名。例如,如果我今天有 5 个用户预订,我需要从 db 中获取所有用户,我使用 while 循环成功完成了这一操作,但是当我按用户的电话号码搜索时,排名不会起作用。我希望我的问题很清楚,并提前感谢。

下面的代码...

public function checkup($number){
    $pdo = $this->pdo;
    $checkUpDate = date('Y-m-d');
    $statsDate = date('Y-m-d');

    $get_all = $pdo->prepare('SELECT * FROM bookings WHERE booking_date =? AND booking_status = 0');
    $get_all->execute([$statsDate]);
    $stats = $get_all->rowCount();
    while($checkUpData = $get_all->fetch()){
    $chk_num = $checkUpData['phone'].',';
    $chk_id = $checkUpData['id'];

    $array = array($chk_num => $chk_id);
    $keys = array_keys( $array );
    $rank = array_search( $number, $keys );

    }
    printf( "You rank %d of %d", ++$rank, count($array) );
    print(" - Please check again after 15 minutes.<br>");

标签: phpwhile-loopranking

解决方案


推荐阅读