簡體   English   中英

從表中獲取價值…PHP / MySQL

[英]Get value from table… PHP/MySQL

我有以下從我的表返回數據的...

    $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值...

在此處輸入圖片說明

你需要;

  • 獲取所有結果
  • 遍歷結果集

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

要調試,請使用print_r

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM