dongyuan3094 2015-08-06 04: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 04: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.

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部