检索多个数据并显示为单行

时间:2016-09-04 09:40:51

标签: php html sql

我的下表是我查询的结果,

Status |Tasks|Owner|Details
-------------------------------
OnGoing|test |test |2016-09-01
                    test a
OnGoing|test |test |2016-09-02
                    test b
OnGoing|test |test |2016-09-03
                    test c 

我想要发生的是,如果任务类似于test且状态类似于OnGoing,它将显示在下方详细信息列下的单行中,

Status |Tasks|Owner|Details
-------------------------------
OnGoing|test |test |2016-09-01
                    test a
                    2016-09-02
                    test b
                    2016-09-03
                    test c 

我当前的查询是,

$sql="SELECT date, status, task, owner, details
        FROM tracker
        WHERE date BETWEEN '" . $date . "' AND '" . $date1 . "'
        ORDER BY date, status";

这是我桌子的代码,

echo "<table width='auto' cellpadding='1px' cellspacing='0px' border=1 align='center'>
<tr>
<th align='center' style='border:dotted 1px;' bgcolor='#66CC00'><font color='#FFFFFF'><strong>Status</strong></font></th>
<th align='center' style='border:dotted 1px;' bgcolor='#66CC00'><font color='#FFFFFF'><strong>Tasks</strong></font></th>
<th align='center' style='border:dotted 1px;' bgcolor='#66CC00'><font color='#FFFFFF'><strong>Owner/s</strong></font></th>
<th align='center' style='border:dotted 1px;' bgcolor='#66CC00'><font color='#FFFFFF'><strong>Details</strong></font></th>
</tr>"; 

while($result = mysql_fetch_array($myData)) 
{
{
$status = $result['status'];
$status = str_replace("\r\n", "<br>", $status);
$status = str_replace("\r", "<br>", $status);
$status = str_replace("\n", "<br>", $status);

$task = $result['task'];
$task = str_replace("\r\n", "<br>", $task);
$task = str_replace("\r", "<br>", $task);
$task = str_replace("\n", "<br>", $task);

$owner = $result['owner'];
$owner = str_replace("\r\n", "<br>", $owner);
$owner = str_replace("\r", "<br>", $owner);
$owner = str_replace("\n", "<br>", $owner);

$date = $result['date'];
$date = str_replace("\r\n", "<br>", $date);
$date = str_replace("\r", "<br>", $date);
$date = str_replace("\n", "<br>", $date);

$details = $result['details'];
$details = str_replace("\r\n", "<br>", $details);
$details = str_replace("\r", "<br>", $details);
$details = str_replace("\n", "<br>", $details);

echo "<form action='get_test.php' method='post'>";
echo"<tr>"; 
echo  "<td align='center'>" . $result['status'] . "<input type=hidden name=status value=" . $result['status'] . " </td>";
echo  "<td align='center'>" . $result['task'] . "<input type=hidden name=task value=" . $result['task'] . " </td>";
echo  "<td align='center'>" . $result['owner'] . "<input type=hidden name=owner value=" . $result['owner'] . " </td>";
echo  
"<td align='left' width='auto'>
" . $date . "<input type=hidden name=date value=" . htmlspecialchars($date) . " /><br>
" . $details . "<input type=hidden name=details value=" . htmlspecialchars($details) . " /> </td>";
"</tr>"; 
echo "</form>";
}
}
echo "</table>";

1 个答案:

答案 0 :(得分:0)

您可以尝试group_concat,例如

if(ndef.canMakeReadOnly()){
    ndef.makeReadOnly();
    Log.e("Read Only", "Read Only");
}