0

I am using the code below to gather and show the data stored in a database. Everything is workig fine but I am not able to show it with bootstrap css. If I copy an exemple of a table (code 2 below) in boostrap it does work (which means I did included all the files for bootstrap correctly). Is there something i am missing? WHy the table I retrieve show up as a plain table and not with bootstrap css that looks nicer?

-------code 1------------

$query = "SELECT * FROM ..."; 
$result = mysql_query($query);

echo "<table>"; 

while($row = mysql_fetch_array($result)){   
echo "<tr><td>" . $row['name'] . "</td>
               <td>" . $row['...'] . "</td>
               <td>" . $row['...'] . "</td>
               <td>" . $row['...'] . "</td>
               <td>" . $row['...'] . "</td>
               <td>" . $row['...'] . "</td>
               </tr>";
}echo "</table>";
 mysql_close(); //Make sure to close out the database connection
?>

-----------code 2-----------

<div class="bs-example">
    <table class="table">
        <thead>
            <tr>
                <th>Row</th>
                <th>Bill</th>
                <th>Payment Date</th>
                <th>Payment Status</th>
            </tr>
        </thead>
        <tbody>
            <tr class="active">
                <td>1</td>
                <td>Credit Card</td>
                <td>04/07/2014</td>
                <td>Call in to confirm</td>
            </tr>

            <tr class="danger">
                <td>5</td>
                <td>Telephone</td>
                <td>06/07/2014</td>
                <td>Due</td>
            </tr>
        </tbody>
    </table>

-----------exemple solution updated--------

    echo "<table class='table'>";
  while($row = mysql_fetch_array($result)){
    echo "<tr class='info'><td>" . $row['...'] . "</td>
                   <td>" . $row['...'] . "</td>
                   <td>" . $row['...'] . "</td>
                   <td>" . $row['...'] . "</td>
                   <td>" . $row['...'] . "</td>
                   <td>" . $row['...'] . "</td>
                   </tr>"; 
    }
    echo "</table>"; 
    mysql_close(); 

    ?>

2 Answers 2

1

You need to add the table class:

echo "<table class='table'>"; 
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you, I was actually writing: <table class="table">
It should work with double-quotes too, but then you need to escape the quotes. Example: echo "<table class=\"table\">";
1

The magic of bootstrap is in its class attributes. You need to add the specific bootstrap class attributes that you want to help structure your table. Like table, active and danger. As you can see quite clearly the difference in code 1 and code 2 are the class attributes. Give this blog post a read to get more info on what each attribute does for you.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.