我正在尝试使用函数mysqli_fetch_field()
来获取数据库中每个表的名称。但是,当我尝试使用$fieldInfo->table
输出表名时,我得到了重复项。如何从每个表中仅选择1列,以便不为每个表的每列调用$fieldInfo->table
?
当前的sql:
$sql = "SELECT * from administrators, bookings, customers, rooms";
$results = mysqli_query($conn, $sql)
or die ('Problem with query' . mysqli_error($conn));
我的代码在单选按钮中显示表名:
<?php
while ($fieldInfo = mysqli_fetch_field($results)) {
?>
<input type="radio" name="tableNames" value="<?php echo $fieldInfo->table; ?>"> <?php echo $fieldInfo->table ?> <br>
<?php } ?>
答案 0 :(得分:0)
我添加了2个临时表名持有者并制作了一个IF条件,只有在2个临时名称持有者不同时才输出单选按钮。
class DataTable{
public DataTable(){} //Again default one, in case you want to initialize manually
public DataTable(SQLConnection con, SQLCommand command){
//Code to connect to database get the data and fill the table
}
public DataTable(File file){
//Code to read data from a file and fill the table
}
}
答案 1 :(得分:0)
<?php
$query='SHOW TABLES FROM DB_NAME';
$results=mysqli_query($conn,$query);
while ($fieldInfo = mysqli_fetch_array($results)) { ?>
<input type="radio" name="tableNames" value="<?php echo $fieldInfo[0]; ?>"> <?php echo $fieldInfo[0]; ?> <br>
<?php } ?>