dpbsy60000 2016-05-30 04:33
浏览 217

PHP / SQL - 如何在数据库中获取表的名称?

I am trying to use the function mysqli_fetch_field() to get the name of each of my tables in the database. However when i try to output the table name using $fieldInfo->table i get duplicates. How can i select only 1 column from each table so that $fieldInfo->table isnt called for every column of each table?

current sql:

$sql = "SELECT * from administrators, bookings, customers, rooms";
$results = mysqli_query($conn, $sql)
or die ('Problem with query' . mysqli_error($conn));

my code to display the table name in radio buttons:

<?php
while ($fieldInfo = mysqli_fetch_field($results)) { 
?>
<input type="radio" name="tableNames" value="<?php echo $fieldInfo->table; ?>"> <?php echo $fieldInfo->table ?> <br>
<?php } ?>
  • 写回答

2条回答 默认 最新

  • dongzhuji1042 2016-05-30 05:25
    关注

    I added 2 temporary table name holder and made an IF condition that only outputs the radio buttons once the 2 temporary name holders are different.

    <?php
        $tempName2 = "";
        while ($fieldInfo = mysqli_fetch_field($results)) { 
            $tempName = $fieldInfo->table;
            if ($tempName != $tempName2) {
                $tempName2 = $tempName;
    ?>
        <input type="radio" name="tableNames" value="<?php echo $tempName; ?>" > <?php echo $tempName ?> <br>
        <?php }
    } ?>
    
    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大