i think need to add MYSQL_ASSOC to line that do the loop
mysql_fetch_row($result,MYSQL_ASSOC)
the default is : MYSQL_BOTH
what mean that in the php loop you get the entry of the table name , and the entry of index like 0,1,2,...
i think need to add MYSQL_ASSOC to line that do the loop
mysql_fetch_row($result,MYSQL_ASSOC)
the default is : MYSQL_BOTH
what mean that in the php loop you get the entry of the table name , and the entry of index like 0,1,2,...
if it were me debugging that i would see what
print_r(mysql_fetch_row($result));
outputs
I think you are using the list-language construct incorrectly:
Description
void list ( mixed $varname [, mixed $... ] )
Like array(), this is not really a function, but a language construct. list() is used to > assign a list of variables in one operation.
Example:
$info = array('coffee', 'brown', 'caffeine');
// Listing all the variables
list($drink, $color, $power) = $info;
echo "$drink is $color and $power makes it special.\n";
Now, what you are trying to do is to fetch dynamic table-names (it seems). You do not need to use the list-function, since you can access the result as an array (you can define the appropriate indexes of the array that you are interested in and only assign them, but I think array access is much clearer):
while($row = mysql_fetch_assoc($result))
{
$sqlA = "SELECT COUNT(*) FROM ${row['table']} WHERE `site` LIKE '$entry'";
[...]
}
I am a bit curious though, do ALL the tables in your database feather have a column named site? Otherwise this query will fail, no matter how you format or refactor your code.
I am pretty sure your SHOW TABLES query is returning garbage. I was able to reproduce your problem by copying an existing table_name.frm to #&@.frm in the data folder for a local database. Make sure your database is not corrupt (meaning, try repair): http://dev.mysql.com/doc/refman/5.1/en/repair-table.html
Actually, I recently recalled that my very first table name is indeed "#&*+." I added it deliberately during development
And you're wondering why your SQL fails? :)
Quote your table name because this one is by far not a table name that can be used literally.
Something like
"SELECT COUNT(*) FROM \"$table\" ...
I think this is what you're after:
$result = mysql_query("SHOW TABLES FROM feather") or die(mysql_error());
while($table_row = mysql_fetch_row($result))
{
$table = $table_row[0];
$sqlA = "SELECT COUNT(*) FROM `" . mysql_escape_string($table) . "` WHERE `site` LIKE '" . mysql_escape_string($entry) . "'";
$resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
$isThere_row = mysql_fetch_row($resA);
$isThere = $isThere_row[0];
if ($isThere)
{
$table_list[] = $table;
}
}
NOTE: variables inside your sql should be escaped. I don't use mySQL but I assume mysql_escape_string should work. There is another function, mysql_real_escape_string, that might be more appropropriate. You may want to read the docs for that.