davinci29 Posted September 4, 2016 Share Posted September 4, 2016 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, $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, 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. Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 4, 2016 Share Posted September 4, 2016 YOu have copied a lot of very old code here. Have you done any reading on how to program in PHP? Or how to setup an html table? Or how variables work? Some things I see YOu are doing a nice job of replacing newline chars with an html newline char. But why would you expect your date field ot have newlines in it? A true date field is just that a date field. Not a text field. You needlessly move your data items out of the query result "row" and edit those new vars but then when you output your html table row you use the original query result values. Why? Your while loop has a double set of braces around the code. Why? For each record in your loop you do the edits and then begin an html form and row and output the td elements and end the form. Why? You don't have any submit button so what's the point of having a form and hidden inputs? Are you going to do something with this hidden data? Not with this code. You are using a lot of styling in each and every element of your table. A lot of it is outdated and deprecated. Stop. Worry about the output, then worry about the presentation once you have done some reading on how css works. I know you copied it and have no idea what is happening, but it is not good. You need to learn the basics so write your own code and make it work and then learn some stuff and apply it to improve it. And one last piece of advice. Stop using MySQL and use only mysqlI or PDO to access your database. Read the manual to find out why. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted September 6, 2016 Share Posted September 6, 2016 You could assign all the data, in the while loop, to a multidimensional associative array. And then loop through the multidimensional associative array to generate the HTML table. If done correctly, you can use the count() function to determine how many rows to span the "OnGoing" value, for example, across. More information about multidimensional arrays and multidimensional associative arrays can be found here: http://webcheatsheet.com/php/multidimensional_arrays.php On a related note, you could use the nl2br() function instead of all those calls to str_replace(). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.