douweibeng5219 2016-01-26 19:55
浏览 13
已采纳

一个if里面的SQL列数据

I want to use the data of a mysql column inside an "if" but unfortunately I don't know how to do and I think i'm searching with the wrong terms.

So here is my code :

$reqcle=$bdd->prepare("SELECT * FROM clebeta WHERE cle='".$clebeta."'");
    $reqcle->execute();
    $countcle=$reqcle->rowCount();
    $askcleutil=$reqcle->fetchAll();
    //on vérifie d'abord que la clé existe en base de données
    if($countcle == 1){
        //on continue le traitement et on vérifie si la clé n'est pas déjà utilisée
        if($askcleutil[2] == "0"){
            //on continue le traitement et on vérifie l'existence du pseudo minecraft en base de données
        } else {
            //on affiche que la clé est déjà utilisée
        }
    } else {
        //on affiche une erreur : clé inexistante
    }

It's in my last if : if($askcleutil[2] == "0")

I want to test the value of the 'active' column inside my DB but I don't know how to do

Sorry if i'm not clear but I don't know how to explain this clearly

  • 写回答

1条回答 默认 最新

  • douyi1939 2016-01-26 20:04
    关注

    You use selectAll(), so you miss your loop.

    Returns an array containing all of the result set rows (http://php.net/manual/en/pdostatement.fetchall.php)

    You need like this:

    foreach ($askcleutil as $row) {
        if ($row['a_col_name_of_your_selected_row'] == 0) {
           // Handle
        }
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥60 pb数据库修改或者求完整pb库存系统,需为pb自带数据库
  • ¥15 spss统计中二分类变量和有序变量的相关性分析可以用kendall相关分析吗?
  • ¥15 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路