我的项目有一点显示问题。
事实是我想在表中显示一些信息(sql请求SHOW Columns
btw的列类型),但它无法正确显示。
代码是:
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;
}
结果是:
不幸的是Line break
之间没有"Types" ><
,我该如何解决这个问题?
我已经尝试了<br/>
,但它没有改变任何内容。
答案 0 :(得分: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>';
$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 :(得分:1)
删除第二个。 secon同时打印所有类型的行。这就是你遇到问题的原因。如果您只是在第一个循环中的每个圆圈中获得一个数据,它将正常工作
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
}
答案 2 :(得分:0)
这有用吗?
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
}
}