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 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助