简体   繁体   中英

How to make my table cell auto fit to contents in Bootstrap 3?

I am fetching data from Mysql database and populating them in a table. However, i cannot seem to make the cell autofit to contents. I have tried width as the property of the table but i cant get it to work Would really appreciate your help. Thanks Here's what i have done so far

<div id="page-content-wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12">

                <table class="table table-bordered" style="width:100%">
                    <thead>
                      <tr>
                        <th><center>ID</center></th>
                        <th>Name</th>
                        <th><center>Email</center></th>
                        <th>Number</th>
                        <th>Package</th>
                        <th>Flexibility</th>
                        <th >Date</th>
                        <th>Departuring From</th>
                        <th>Departure Date</th>
                        <th>Destination</th>
                        <th>Arrival Date</th>
                        <th>Price</th>
                        <th>Consolidator</th>

                      </tr>
                    </thead>

                    <tbody>
                      <?php

                        $query = 'SELECT * FROM queries';

                        $result = mysql_query($query);

                        while ($row = mysql_fetch_array($result)) {
                            echo '<tr>';
                            echo '<td>'. $row['id'] . '</td>';
                            echo '<td>'. $row['name'] . '</td>';
                            echo '<td>'. $row['email'] . '</td>';
                            echo '<td>'. $row['contactnumber'] . '</td>';
                            echo '<td>'. $row['packagedetails'] . '</td>';
                            echo '<td>'. $row['flexibility'] . '</td>';
                            echo '<td>'. $row['datetoday'] . '</td>';
                            echo '<td>'. $row['departure'] . '</td>';
                            echo '<td>'. $row['dateofdeparture'] . '</td>';
                            echo '<td>'. $row['destination'] . '</td>';
                            echo '<td>'. $row['dateofarrival'] . '</td>';
                            echo '<td>'. $row['price'] . '</td>';
                            echo '<td>'. $row['vendor'] . '</td>';
                            echo '<td width=250>';
                            echo '<a class="btn btn-success" href="readquery.php?id='.$row['id'].'">Read</a>';
                            echo '&nbsp;';
                            echo '<a class="btn btn-success" href="updatequery.php?id='.$row['id'].'">Update</a>';
                            echo '&nbsp;';
                            echo '<a class="btn btn-danger" href="deletequery.php?id='.$row['id'].'">Delete</a>';
                            echo '</td>';
                            echo '</tr>';
                        } 
                        ?>  
                    </tbody>
                </table>

I never see you echo </tr> or </td> . It would be helpful to give us an output of the HTML being generated by your while loop.

The problem was not with my table. To make it work, i increased the width of my container in which my table was inside, and it worked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM