从表中获取价值... PHP / MySQL

时间:2014-10-03 15:58:23

标签: php mysql sql

我有以下内容从我的表中返回数据......

    $query = dbConnect()->prepare("SELECT * FROM users a INNER JOIN actions b ON a.id = b.user_id WHERE a.id=:user_id");
    $query->bindParam(':user_id', $_SESSION['user_id']);
    $query->execute();


    if($row = $query->fetchAll()){
        $row['id'] = $_SESSION['user_id'];
    }

我想打印出当前登录用户的'check_id'列中的每个值...

我试过......

 if($row = $query->fetchAll()){
        $row['id'] = $_SESSION['user_id'];
        $checkValue = $row['check_id'];
    }

只有我收到......

Notice: Undefined index: check_id in /home/index.php on line 24

打印数组显示我的check_id值...

enter image description here

2 个答案:

答案 0 :(得分:2)

你需要;

  • 获取所有结果
  • 遍历结果集

$arrResults = $query->fetchAll();
foreach($arrResults as $result) {
   echo $result['user_id'] . PHP_EOL;
}

答案 1 :(得分:0)

调试使用print_r

if($row = $query->fetchAll()){
    print_r($row);
}