Hello!

There are 7 tables, 4 of them contain a 'price' column.

It is necessary to do the following:

I need to remove from the database the names of only those tables that contain the column 'price'. And then output them separated by commas and assign the result to the variable.

I do this:

$basessites = mysql_query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='sale' AND COLUMN_NAME='price'"); if (mysql_num_rows($basessites) > 0) {$bsites = mysql_fetch_assoc($basessites); $sites = implode(",", $bsites); echo $sites; } 

Displays only one table of the 4 corresponding to the condition. How to be, tell me what I'm doing wrong!

    2 answers 2

    Use the loop:

     while($bsites = mysql_fetch_assoc($basessites)){ $sites = implode(",", $bsites); echo $sites; } 
    • It works fine only displays only 3 and not 4 names, the first one does not! - cheh1
    • Try running a sql query in phpmyadmin. - terantul
    • everything displays in phpmyadmin - cheh1

    Here is a solution found, @terantul Thanks for getting out of the idea!

     $basessites = mysql_query("SELECT TABLE_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA='sale' AND COLUMN_NAME='price'"); if (mysql_num_rows($basessites) > 0) {$bsites = mysql_fetch_assoc($basessites);} do {$sites.=$bsites['TABLE_NAME'].", "; } while($bsites = mysql_fetch_assoc($basessites)); echo $sites;