rizmah Posted January 18, 2016 Share Posted January 18, 2016 First off, I am not 100% sure how I would do this that is why I am posting on here. I want to draw each row of database data and put it in a table kind of thing but when I have multiple things in the database it goes in the same row of the table. Instead of it going into the same one I want it to have a different section. Below is an example: Quote Link to comment Share on other sites More sharing options...
thara Posted January 18, 2016 Share Posted January 18, 2016 Can we see your code? Quote Link to comment Share on other sites More sharing options...
rizmah Posted January 18, 2016 Author Share Posted January 18, 2016 Can we see your code? <tbody> <tr> <td><?php $methodssql = $odb -> query("SELECT `m_title` FROM `methods`"); while($row = $methodssql ->fetch()) { echo "<tr>" . $row['m_title'] . "</tr>"; } ?></td> <td><?php $methodssql = $odb -> query("SELECT `sub_date` FROM `methods`"); while($row = $methodssql ->fetch()) { echo $row['sub_date']; } ?></td> <td><?php $methodssql = $odb -> query("SELECT `author` FROM `methods`"); while($row = $methodssql ->fetch()) { echo $row['author']; } ?></td> <td><?php $methodssql = $odb -> query("SELECT `tutorial` FROM `methods`"); while($row = $methodssql ->fetch()) { echo $row['tutorial']; } ?></td> <td> <span class="label label-table label-success"><?php $methodssql = $odb -> query("SELECT `status` FROM `methods`"); while($row = $methodssql ->fetch()) { echo $row['status']; } ?></span> </td> </tr> </tbody> Thats the table one. I was thinking of concatenation look at the top one of the code above ( echo "<tr>" . $row['m_title'] . "</tr>"; ). It works but its made it all weird Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 18, 2016 Share Posted January 18, 2016 (edited) You only need ONE query and ONE while loop. Select all the columns you want from your table at one time. SELECT m_title, sub_date, author, tutorial, status FROM methods while{ } Edited January 18, 2016 by benanamen Quote Link to comment Share on other sites More sharing options...
rizmah Posted January 18, 2016 Author Share Posted January 18, 2016 You only need ONE query and ONE while loop. Select all the columns you want from your table at one time. SELECT m_title, sub_date, author, tutorial, status FROM methods while{ } I changed the code to one while, but now it displayed it on same row but in separate places. <tbody> <tr> <?php $methodssql = $odb -> query("SELECT * FROM `methods`"); while($row = $methodssql ->fetch()) { echo '<td>' . $row['m_title'] . '</td>'; echo '<td>' . $row['sub_date'] . '</td>'; echo '<td>' . $row['author'] . '</td>'; echo '<td>' . $row['tutorial'] . '</td>'; echo '<td> <span class="label label-table label-success"> ' . $row['status'] . ' </span> </td>'; } ?> </tr> </tbody> Quote Link to comment Share on other sites More sharing options...
rizmah Posted January 18, 2016 Author Share Posted January 18, 2016 Fixed! Done it thanks for your help anyway! Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 18, 2016 Share Posted January 18, 2016 Your <tr></tr> needs to be IN the loop. not outside if it. 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.