【问题标题】:Trying to retrieve tables only with particular column php mysql尝试仅使用特定列 php mysql 检索表
【发布时间】:2017-06-17 22:15:49
【问题描述】:

我正在尝试仅检索具有特定列(如“名称”)的表。 例如,有 3 个表 table1、table2 的列名为“name”,table3 的列名为“message”,我只想检索 table1 和 table2,因为它们的列名为“name”。这是我尝试过的代码:

     <div class="form-group">
          <label class="control-label col-sm-2" for="email">Enter number of tables:</label>
              <div class="col-sm-10">
                <select  name="table_name">
                  <?php 
                     include 'config.php';
                     $query="show tables";
                     $result_query=mysqli_query($conn,$query);
                      while($row=mysqli_fetch_array($result_query))
                       {
                          echo "<option value='{$row[0]}'>$row[0]</option>";
                       }
                  ?>
                 </select>
              </div>
        </div>

上面的代码显示了所有表,但我想显示只有列名作为“名称”的表。

【问题讨论】:

标签: php mysql select


【解决方案1】:

您必须将查询更改为

SELECT DISTINCT TABLE_NAME 
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE COLUMN_NAME IN ('columnA','ColumnB')
        AND TABLE_SCHEMA='YourDatabase';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-01-23
    • 2016-04-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多