douli2063 2019-04-12 14:15
浏览 415

如何使用fetch函数只获取从数据库中获取的数据的一个值

I am new to php and had chosen to stick to PDO format. I have been able to set up a workable registration and login system, but my challenge is fetching data from my database which would be used in other page of the user profile page I created. I had tried all the many examples and methods I was able to get on the internet but there are not working, or rather I don't know how to use it, where I want to insert the variable will still be empty. The only fetch function I was able to get will select all the row, for instance, if it is email, it will fetch all the registered emails in the database which is not suppose to be. The email should only be for the user whose profile is opened. Here are the codes. I am sure someone will help me figure this out. Thanks

    $data = $pdo->query("SELECT * FROM databaseName")->fetchAll();
    //this one is in the body where i want to insert the email
    foreach ($data as $row) {
    echo $row['email']."<br />
";
}

I tried everything my little knowledge of php but all to no avail. If i decide to use any other one, nothing will show.

  • 写回答

4条回答 默认 最新

  • du521521521 2019-04-12 14:18
    关注

    You can try other alternative to achieve the same,

    $stmt = $pdo->query('SELECT * FROM databasetable');
    while ($row = $stmt->fetch())
    {
        echo $row['email'] . "
    ";
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行
  • ¥15 R语言Rstudio突然无法启动
  • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
  • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法