php - 对 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>");
解决方案
推荐阅读
- html - 如何使用 css 网格在第一行居中 1 列并将其他 3 列放在第二行?
- sql-server - SQL Server 中不会忽略重复项
- regex - 如何匹配彼此相邻的括号?
- api - 如何向 api 发送多个查询参数?
- javascript - Firebase功能分离线程?
- javascript - 如何使用 dom 选择器作为对象中的值迭代对象,然后使用它们来设置值?
- reactjs - 如何处理 Electron 应用程序中的数据库查询(使用 react-redux)?
- javascript - 我没有做任何事情就生成了一个 dist 文件夹
- bash - 如何从 tar.gz 文件中一次提取文件夹中的所有文件
- excel - 使用正确编码的 VBA 流式写入 XML 文件