dongyuan3094 2015-08-06 12:13
浏览 47
已采纳

无法在数据库php pdo mysql上选择第一行

I couldn't understand what is wrong here. I cannot take the first row on database. I also cannot the data which are single according to $ara parameter. Here are the codes:

$ara =$_POST['ara'];
$query=$db->prepare("SELECT * FROM uyeler WHERE
                     name like '%".$ara."%' or 
                     surname like '%".$ara."%' or
                     email like '%".$ara."%' 
                    ");
$query->execute(array());           
if ($num_row = $query->fetchAll(PDO::FETCH_BOTH)){
    echo "<li><a href='profil.php?id=".$num_row['user_id']."'>" .$num_row['name']. " " .$num_row['surname']."</a></li>";

}else{
    echo "Hiç birşey bulunamadı!";
}
  • 写回答

1条回答 默认 最新

  • dongsong8932 2015-08-06 12:59
    关注

    You need to correct your array call:

    from

    $num_row['user_id']
    

    To

    $num_row[0]['user_id']
    

    Your code is tested and works, nice job.

    what you need to correct is the following line:

    echo "<li><a href='profil.php?id=" . $num_row[0]['user_id'] . "'>" . $num_row[0]['name'] . " " . $num_row[0]['surname'] . "</a></li>";
    

    If you face such problem in the future, it is a good practice to var_dump the results like:

    var_dump($num_row);
    

    This will give you a total raw picture of the content.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看