Jump to content

Viewing database stuff in table


rizmah

Recommended Posts

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:

70385027c5e3408ba149f40443d63519.png

Link to comment
Share on other sites

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 773bbc3126a17ad1fc90a8ccd2c777d4.png

Link to comment
Share on other sites

 

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>

r2O6X.png

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.