duanhuang7591 2014-09-06 04:45
浏览 127

返回一个结果的MySQL查询

I have a form that allows me to input data into a database. When the information in the form is submitted it is also returned to let the user know the data has been successfully uploaded. At the moment all of the data in the database is being returned. Ideally I would like only the data being submitted at the time to be returned (which should return one result). Is there a mysql query that will allow this? This is what I currently have:

    $query = "SELECT * FROM residents";

    $result = mysql_query($query);

    while($person = mysql_fetch_array($result)) {
        echo "<h3>" . $person['FirstName'] . "</h3>";
        echo "<p>" . $person['LastName'] . "</p>"; 
        echo "<p>" . $person['Address'] . "</p>";
        echo "<p>" . $person['Birthday'] . "</p>"; 
        echo "<p>" . $person['FormerResidence'] . "</p>";
        echo "<p>" . $person['Career'] . "</p>";
        echo "<p>" . $person['Education'] . "</p>";
        echo "<p>" . $person['SpecialInterests'] . "</p>";
        echo '<p><img src="upload/' . $person['Picture'].'" width="70" height="70"/></p>';
    }
    ?>
    <?php

I have also tried: while($person = mysql_fetch_assoc($result)) which still returns all of the data in the database instead of just one result.

  • 写回答

2条回答 默认 最新

  • douturan1807 2014-09-06 04:49
    关注

    You're about to get an influx of responses that say this, but you should be using a non-deprecated database method like mysqli. One of the advantages that this will also bring you is the ability to get the insert ID back from the last query by using ->insertid. Then, you can use this to query the database for that exact ID, guaranteeing the correct entry.

    评论

报告相同问题?

悬赏问题

  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端
  • ¥15 基于PLC的三轴机械手程序
  • ¥15 多址通信方式的抗噪声性能和系统容量对比
  • ¥15 winform的chart曲线生成时有凸起
  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 Centos / PETSc / PETGEM