tomb
tomb

Reputation: 1827

SHOW TABLES only shows tables starting with a space mysql

I have some code that needs to get a list of all of the tables in a database with a certain column equaling a certain thing. However, using the SHOW TABLES MySQL code is only listing tables that start with a space. Here is my code...

$result = mysql_query("SHOW FULL TABLES IN `db`") or die("Error: " . mysql_error());
while ($word = mysql_fetch_array($result)) {
    $word = $word[0];
    $sql = "SELECT * FROM `db`.`$word` WHERE col='$val'";
    $result = mysql_query($sql, $con) or die("Error: " . mysql_error());
    while ($col = mysql_fetch_array($result)) echo "<li><a nav='$word' title='View $word'>$word</a></li>";
}

For some reason, the first mysql_query() is only returning one result, which happens to be a table beginning with a space. (It is the only table starting with a space in the whole thing) Edit: I just realized that I left out the line of code that turned $word from an array into a string... it's in there now.

Upvotes: 3

Views: 541

Answers (1)

SteB
SteB

Reputation: 2007

You're over-writing $result (your table list) inside the loop.

After the first iteration, $result will contain a list of fields from the first table.

Upvotes: 2

Related Questions