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 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器