PHP line break

I have a slight display problem in my project.

The thing is, I want to display some information ( SHOW Columnsbtw sql query column types ) in a table, but it does not display properly.

The code:

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:

The Resulting Image

Sorry, no in Line breakbetween "Types" ><, how can I fix this?

I already tried a <br/>, it hasn’t changed anything.

+4
source share
3 answers

delete the second. secon while printing all type in a line. that's why you have problems. if you just get one information in each circle in the first cycle, it will work fine

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
}
+1
source

try it

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;
+1

?

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
    }
}
0

Source: https://habr.com/ru/post/1665502/


All Articles