dongzhiyong8577 2013-08-02 20:59
浏览 25

显示MySQL中特定行的数据

I'm building a simple bug tracking tool. When you create a new project, all the info you fill in in the form, gets stored in the database.

When you create the new project you get redirected to a unique project page. On top of the page it shows the name of the project, but it's not the name of the project I just created, it always shows the name of the first project in the MySQL table.

How can I show the name of the project I just created?

With this query I retrieve the data from the database.

$query = "SELECT CONCAT(name) 
AS name FROM projects";
$result = @mysql_query ($query)

With this I show the project name, but it always shows the name of the first record in the table.

    <?php 
    if ($row = mysql_fetch_array ($result))
        echo '<h5>' . $row['name'] . '</h5>'; 
    ?>

It isn't yet SQL Injection prove and is far from complete... But I'm really struggling with this problem.

  • 写回答

2条回答 默认 最新

  • dplo59755 2013-08-02 21:02
    关注

    Try using ORDER BY.

    $query = "SELECT CONCAT(name) 
    AS name FROM projects ORDER BY id DESC";
    

    This would show the most recent project (assuming you have an ID column).

    However, a much better way is to have an ID variable on the page.

    $query = "SELECT CONCAT(name) 
    AS name FROM projects WHERE id=?";
    
    评论

报告相同问题?

悬赏问题

  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大
  • ¥15 Oracle中如何从clob类型截取特定字符串后面的字符
  • ¥15 想通过pywinauto自动电机应用程序按钮,但是找不到应用程序按钮信息
  • ¥15 如何在炒股软件中,爬到我想看的日k线
  • ¥15 seatunnel 怎么配置Elasticsearch
  • ¥15 PSCAD安装问题 ERROR: Visual Studio 2013, 2015, 2017 or 2019 is not found in the system.
  • ¥15 (标签-MATLAB|关键词-多址)
  • ¥15 关于#MATLAB#的问题,如何解决?(相关搜索:信噪比,系统容量)
  • ¥500 52810做蓝牙接受端