douzhan5262 2014-04-22 14:23
浏览 58
已采纳

PDO从id获取结果

ive started updating my code from mysql to pdo, and im not very bright and get easily mad. which ive gotten now. i dont understand why this isnt working, and id like anyones help why. the mysql code is commented out of the section (it works, but want pdo). the pdo code isnt working however and i cant understand why.

can someone help me?

$result_bajs = "SELECT * FROM comments WHERE movie_id = :id ORDER BY post_date DESC";

$stmt2 = $pdo->prepare($result_bajs);
$stmt2 = execute(array(
    ':id' => $id
));
$result2 = $stmt2->fetchAll();
while($row = $result2){
//$result2 = mysql_query($result_bajs, $connection) or die (mysql_error());

$ip = $_SERVER['REMOTE_ADDR'];
//while ($row = mysql_fetch_array($result2)) {
   $comment = $row['comment'];
   $author = $row['author'];
   $post_date = $row['post_date'];
  • 写回答

1条回答 默认 最新

  • douluan5444 2014-04-22 14:30
    关注

    You're overwriting your variables. Also the code is very unclear. Maybe this code will help you understand and write your queries better:

    $SQL = $pdo->prepare("SELECT * FROM comments WHERE movie_id = :id ORDER BY post_date  DESC");
    $SQL->execute(array(':id' => $id));
    $row = $SQL->fetchAll();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。