简体   繁体   中英

PHP/MySQL output into table with bootstrap - columns are messed

I have problem with mysql output into table. Script is working perfectly, I got data what I need but columns in table are messed. It seems like there might be a problem with these multiple echos, but I tried every possible combination what I found/come up with and nothing worked so far.

if (mysqli_num_rows($result) > 0) {
    while($row = mysqli_fetch_assoc($result)) {
        echo"<table class='table table-hover table-striped table-responsive'>";
        echo"<tr class='table_row'>";
        echo"<td>" . $row['1'] . "</td>";
        echo"<td>" . $row['2'] . "</td>";
        echo"<td>" . $row['3'] . "</td>";
        echo"<td>" . $row['4'] . "</td>";
        echo"<td><a href='#'><button type='button' class='btn btn-danger btn-xs glyphicon glyphicon-remove-circle'></button></a></td>";
        echo"</tr>";
        echo"</table>";
    }
}

You must try this :

 if (mysqli_num_rows($result) > 0) {
  echo"<table class='table table-hover table-striped table-responsive'>";
                  while($row = mysqli_fetch_assoc($result)) {

                    echo"<tr class='table_row'>";
                    echo"<td>" . $row['1'] . "</td>";
                    echo"<td>" . $row['2'] . "</td>";
                    echo"<td>" . $row['3'] . "</td>";
                    echo"<td>" . $row['4'] . "</td>";
                    echo"<td><a href='#'><button type='button' class='btn btn-danger btn-xs glyphicon glyphicon-remove-circle'></button></a></td>";
                    echo"</tr>";

                  }
echo"</table>";
}

You are repeating the table inside while loop. Hope this help you.

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