Trying to retrieve tables only with particular column php mysql

294

I am trying to retrieve only tables with particular column like 'name'. For example having 3 tables table1, table2 with column name 'name' and table3 with column name 'message', I want to retrieve only table1 and table2 as they are having column name as 'name'. Here is code I tried:

   <div >
     <label for="email">Enter number of tables:</label>
       <div >
        <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>

The above code is showing all tables, but I want to show to show tables with only column name as 'name'.

709

Answer

Solution:

you must change a query to

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

People are also looking for solutions to the problem: php - Convert String Date to Object

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.