tags:

views:

136

answers:

6
A: 

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,...

Haim Evgi
I appreciate the suggestion, but when I do that, I get this error:Warning: Wrong parameter count for mysql_fetch_row()
sorry i mistake i think u use fetch_array , u use fetch_row that is not problem
Haim Evgi
but try to do this :while ($tmp_tbl = mysql_fetch_array( $res_tbl )) { $curr_tbl = $tmp_tbl[0];}
Haim Evgi
+1  A: 

if it were me debugging that i would see what

print_r(mysql_fetch_row($result));

outputs

Galen
Galen
what happens if you rename/remove that table?
Galen
I tried putting ` around $table, and no error message. I'll print a few things out to see if you solved my problem.
Quick question: how would I print or echo $table_list[]?
In any event, I think you solved my problem: it was the back-ticks.
foreach($table_list as $t){echo "$t<br>"}
Galen
+1  A: 

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.

PatrikAkerstrand
Yes, all the tables have a column named "site." I will try your suggestion.
And you are also connected to the database feather?
PatrikAkerstrand
Yes, I'm connected to feather. I tried this code:while($row = mysql_fetch_assoc($result)){ $sqlA = "SELECT COUNT(*) FROM ${row['table']} WHERE `site` LIKE '$entry'"; $resA = mysql_query($sqlA) or die("$sqlA:".mysql_error()); list($isThere) = mysql_fetch_row($resA); if ($isThere) { $table_list[] = $table; }}and I got this error:SELECT COUNT(*) FROM WHERE `site` LIKE 'miami.com':You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE `site` LIKE 'miami.com'' at line 1
oh, you have to change 'table' into the correct index. do a var_dump($row); exit; before the sql and print the result
PatrikAkerstrand
A: 

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

Thomas Jung
+1  A: 

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\" ...
VVS
THanks... back-ticks work as well... that was the problem.
A: 

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.

Stacey Richards