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

时间:2011-08-20 03:35:11

标签: php echo

好的,我有一个任务表,这个表有一个外键,即“projectID”

我选择该表中具有相同projectID的所有行。但我现在想要在列表中输出结果(“<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

1 个答案:

答案 0 :(得分:1)

您将需要遍历每一行并输出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!';
}