PHP 如何创建所有任务的列表

发布于 2024-11-30 10:23:21 字数 366 浏览 1 评论 0原文

好吧,我有一个任务表,该表有一个外键,即“projectID”,

我正在选择该表中具有相同 projectID 的所有行。但我现在想将结果输出到列表中 ("

  • ")

    //Select tasks
    $sql = "SELECT * FROM tasks WHERE projectID = '".$project_ID."'";
    $result5 = $db->sql_query($sql);
    $data5 = mysql_fetch_assoc($result5);
    

    在此输入图像描述

    Alright, I have a table of tasks this table has a foreign key which is the "projectID"

    I am selecting all the rows within that table that have the same projectID. But I now want to output the results in a list ("<li></li>")

    //Select tasks
    $sql = "SELECT * FROM tasks WHERE projectID = '".$project_ID."'";
    $result5 = $db->sql_query($sql);
    $data5 = mysql_fetch_assoc($result5);
    

    enter image description here

    如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

    扫码二维码加入Web技术交流群

    发布评论

    需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

    评论(1

    水溶 2024-12-07 10:23:21

    您将需要迭代每一行并输出 taskList 列值:

    $sql = "SELECT * FROM tasks WHERE projectID = '".$project_ID."'";
    $result5 = $db->sql_query($sql);
    
    $data5 = mysql_fetch_assoc($result5);
    // this will let you handle an empty result set without a count.
    if( $data5 )
    {
        // opening the list only if there are things to put there
        echo "<ul >";
        do
        {
            // output the value from one row.
            echo "<li>" . $data5['taskName'].'</li>';
        }while($data5 = mysql_fetch_assoc($result5));
        echo "</ul>";
    }
    else
    { 
        echo 'No tasks found!';
    }
    

    You're going to need to iterate through each of the rows and output the taskList column value:

    $sql = "SELECT * FROM tasks WHERE projectID = '".$project_ID."'";
    $result5 = $db->sql_query($sql);
    
    $data5 = mysql_fetch_assoc($result5);
    // this will let you handle an empty result set without a count.
    if( $data5 )
    {
        // opening the list only if there are things to put there
        echo "<ul >";
        do
        {
            // output the value from one row.
            echo "<li>" . $data5['taskName'].'</li>';
        }while($data5 = mysql_fetch_assoc($result5));
        echo "</ul>";
    }
    else
    { 
        echo 'No tasks found!';
    }
    
    ~没有更多了~
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文