Question: Line break in PHP Table

Question

Line break in PHP Table

Answers 3
Added at 2017-01-02 10:01
Tags
Question

I have a little display problem on my project.

The fact is that I want to display some information (column types of an sql request SHOW Columns btw) in a table, but it does not display properly.

The code is :

try
{
    echo '<table class="table table-bordered table-striped mb30 mt30">';
    echo'<thead>
            <th class="text-center">Name of column</th>
            <th class="text-center">Type</th>
            <th class="text-center">Update</th>
            <th class="text-center">Delete</th>
         </thead>';
    echo'<tbody>';
    $sql = $bdd->query("SHOW COLUMNS FROM ".$table);
    $column_name = $bdd->query('select column_name from information_schema.columns where table_name = "'.$table.'" and table_schema = "'.$db_name.'" ');
    $i = 0;

    while($donnees = $column_name->fetch())
    {
        $column = $donnees[$i];
        echo '<tr><td class="col-db text-center">'.$donnees[$i].'</td>';
        while ($row = $sql->fetch())
        {
            echo '<td class="col-db text-center">'.$row["Type"].'</td>';
        }
        ?>
        <td><p class="text-center"><a href="form_update_table.php?database=<?php echo $db_name;?>&table=<?php echo $table;?>&column=<?php echo $column;?>" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></a></p></td>
        <td><p class="text-center"><a href="drop_column.php?database=<?php echo $db_name;?>&table=<?php echo $table;?>&column=<?php echo $column;?>" onclick="return confirm_delete()" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a></p></td></tr>
        <?php
    }
    $i = $i + 1;
}

and the result is:

The Resulting Image

Unfortunately there is no Line break between the "Types" ><, how can I fix this?

I already tried a <br/>, it changed nothing.

Answers
nr: #1 dodano: 2017-01-02 10:01

Try this

try
{
    echo '<table class="table table-bordered table-striped mb30 mt30">';
    echo'<thead>
            <th class="text-center">Name of column</th>
            <th class="text-center">Type</th>
            <th class="text-center">Update</th>
            <th class="text-center">Delete</th>
         </thead>';
    echo'<tbody>';
    $sql = $bdd->query("SHOW COLUMNS FROM ".$table);
    $column_name = $bdd->query('select column_name from information_schema.columns where table_name = "'.$table.'" and table_schema = "'.$db_name.'" ');
    $i = 0;

    while($donnees = $column_name->fetch())
    {
        $column = $donnees[$i];
        while ($row = $sql->fetch())
        {
            echo '<tr><td class="col-db text-center">'.$donnees[$i].'</td><td class="col-db text-center">'.$row["Type"].'</td><td><p class="text-center"><a href="form_update_table.php?database='.'$db_name.'&table='.$table.'&column='.$column.'" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></a></p></td>
        <td><p class="text-center"><a href="drop_column.php?database='.$db_name.'&table='.$table.'&column='.$column.'" onclick="return confirm_delete()" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a></p></td></tr>';
        }
        ?>

        <?php
    }
    $i = $i + 1;
nr: #2 dodano: 2017-01-02 10:01

Could this help?

try
{
    echo '<table class="table table-bordered table-striped mb30 mt30">';
    echo'<thead>
            <th class="text-center">Name of column</th>
            <th class="text-center">Type</th>
            <th class="text-center">Update</th>
            <th class="text-center">Delete</th>
         </thead>';
    echo'<tbody>';

    $column_name = $bdd->query('select column_name, data_type from information_schema.columns where table_name = "'.$table.'" and table_schema = "'.$db_name.'" ');

    while($donnees = $column_name->fetch_assoc())
    {
        $column = $donnees['column_name'];
        echo '<tr><td class="col-db text-center">'.$donnees['column_name'].'</td>';
        echo '<td class="col-db text-center">'.$donnees['data_type'].'</td>';

        ?>
        <td><p class="text-center"><a href="form_update_table.php?database=<?php echo $db_name;?>&table=<?php echo $table;?>&column=<?php echo $column;?>" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></a></p></td>
        <td><p class="text-center"><a href="drop_column.php?database=<?php echo $db_name;?>&table=<?php echo $table;?>&column=<?php echo $column;?>" onclick="return confirm_delete()" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a></p></td></tr>
        <?php
    }
}
nr: #3 dodano: 2017-01-02 10:01

remove the second while. secon while is printing all type in a row. this is why you are having problem. if you just get one data in each of the circle in first loop, it will work ok

while($donnees = $column_name->fetch()) {
    $column = $donnees[$i];
    echo '<tr><td class="col-db text-center">'.$donnees[$i].'</td>';
    $row = $sql->fetch();
    echo '<td class="col-db text-center">'.$row["Type"].'</td>';
     ?>
    <td><p class="text-center"><a href="form_update_table.php?database=<?php echo $db_name;?>&table=<?php echo $table;?>&column=<?php echo $column;?>" class="btn btn-primary btn-xs"><span class="glyphicon glyphicon-pencil"></span></a></p></td>
    <td><p class="text-center"><a href="drop_column.php?database=<?php echo $db_name;?>&table=<?php echo $table;?>&column=<?php echo $column;?>" onclick="return confirm_delete()" class="btn btn-danger btn-xs"><span class="glyphicon glyphicon-trash"></span></a></p></td></tr>
<?php
}
Source Show
◀ Wstecz