简体   繁体   English

使用while和foreach进行PDO提取

[英]PDO Fetch with while and foreach

I used all both of your tipps: Changed to that but the Mysql Statement doesnt get the value... 我都使用了所有的提示:更改为该提示,但Mysql语句未获取值...

Look that: 看那个:

try {
  $sql = "SELECT a_idname FROM t_users WHERE a_zone_num <> -1;";
  $users = $conn3->query($sql);
  while ($row = $users->fetch()) {
    $result = $users->fetch(PDO::FETCH_ASSOC);
    foreach($result as $value) {
      echo $value;
      $Add_Cash = $conn1->prepare("UPDATE bg_user SET cash = cash + ':cash' WHERE user_id = ':result';");
      $Add_Cash->bindParam(':cash', $cash);
      $Add_Cash->bindParam(':result', $value);
      $Add_Cash->execute();
      $Count++;
    }
  }
  $conn3 = null;
}
catch (PDOexception $e) {
  echo "Error is: " . $e-> etmessage();
}

将$ sql更改为

$sql = "SELECT a_idname FROM t_users WHERE a_zone_num <> -1;";

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM