tags:

views:

53

answers:

2

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 />";
}
+1  A: 

How about:

SELECT COUNT(*), sum(votes_up) FROM `$table` WHERE `site` LIKE '$entry'

That would add up all the upvotes, and count all the rows.

Andomar
+1  A: 

This assumes that you want a 'votes up' output for every occurrence of 'entry' in the table.

while(list($table)= mysql_fetch_row($result))
{
 $sqlA = "SELECT `site`,votes_up FROM `$table` WHERE `site` LIKE '$entry'";
 $resA = mysql_query($sqlA) or die("$sqlA:".mysql_error());
 if(mysql_num_rows($resA) > 0)
 {
$table_list[] = $table;
while($rowA = mysql_fetch_assoc($resA))
  {
  $votes_up[$rowA["site"]] = $rowA["votes_up"];
  }
 }
}

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

foreach($votes_up as $site => $vote_up)
{
  echo "$site: $vote_up<br />";
}
Steve
Hi... I appreciate the response. I tried your code, and for the line "if(mysql_num_rows($resA) > 0)", I'm getting this error:Parse error: syntax error, unexpected ';'
Oops. looks like my '>' got converted to '>'. Try changing it back to a '>'. There's also two in each of the foreach loops.
Steve
I edited my code to fix those errors.
Steve
The corrected code almost works. I need more character space to explain what it does, so I am going to start a new post.I appreciate your help.