Retrieve multiple data and display to a single row

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
davinci29
Forum Newbie
Posts: 1
Joined: Sun Sep 04, 2016 9:14 am

Retrieve multiple data and display to a single row

Post by davinci29 »

I have my table below which is the result from my query,

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

What I want to happen is that if the Tasks is like `test` and Status is like `OnGoing` it will show up in a single row under Details column below,

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

My current query is,

Code: Select all

    $sql="SELECT date, status, task, owner, details
     FROM tracker
     WHERE date BETWEEN '" . $date . "' AND '" . $date1 . "'
     ORDER BY date, status";
And here is the code for my table,

Code: Select all

 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>";
Please help as I dont know what to do anymore.
Post Reply