php - 获取特定列并比较值 php

标签 php mysql pdo

您好,我想比较两列中的两个值,但它无法正常工作。我需要转换结果吗?我做错了什么?

$query = "SELECT `columm1`, `columm2` FROM `table` WHERE `id` = ? ";
$stmt = $conn->prepare($query);
$stmt->bindParam(1,$eventID);
$stmt->execute();
$currentJoin = (int)  $stmt->fetchColumn();
$maxParticipants = (int) $stmt->fetchColumn(1);

if($currentJoin >= $maxParticipants){
    return;
}
else{

最佳答案

Warning There is no way to return another column from the same row if you use PDOStatement::fetchColumn() to retrieve data. - fetchColumn()

您可以使用fetch()相反

$stmt->execute();
$result = $stmt->fetch();
if($result[0] >= $result[1] ){
    // ...
}

关于php - 获取特定列并比较值 php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56500744/

相关文章:

php - Codeigniter htaccess 不工作

javascript - 使用 php 导航到不同的 html 页面

php - 正则表达式 If Else

mysql - SQL查询列出数据库中所有表的内容

php - Mysql全文帮助

php - 选择在包含多个以逗号分隔的 id 的列中搜索某个 id 的行

php - 如何使用pdo驱动程序从php中的本地文件加载数据

php - SQL查询帮助请求

mysql - 尝试将 varchar 转换为 decimal 时的奇怪行为

php - PostgreSQL 迁移失败,错误消息为 'Could not find driver'