Jump to content

Pulling a column value from an Array of Table Names


ArizonaJohn

Recommended Posts

Hello,

 

The code below prints out all tables in a database called "feather" that contain "$entry" in a column called "site."  Every table in "feather" has a column called "site."

 

This code works great.  However, I would like to add something.  Every table in "feather" also contains a column called "votes_up."  For each table that has "$entry" in it, I would like to print out the value for the "votes_up" column that corresponds to $entry.  How do I go about doing this?

 

Thanks in advance,

 

John

 

 

$result = mysql_query("SHOW TABLES FROM feather") 
or die(mysql_error()); 

while(list($table)= mysql_fetch_row($result))
{
  $sqlA = "SELECT COUNT(*) FROM `$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;
  }
}



foreach( $table_list as $key => $value){
echo "$value <br />";
}

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.