ArizonaJohn Posted June 16, 2009 Share Posted June 16, 2009 The code below returns the following: Table Name 1 Table Name 2 Table Name 3 Table Name 4 "$entry": "votes_up for $entry from Table Name 4" I want it to return this: Table Name 1: "votes_up for $entry from Table Name 1" Table Name 2: "votes_up for $entry from Table Name 2" Table Name 3: "votes_up for $entry from Table Name 3" Table Name 4: "votes_up for $entry from Table Name 4" How could I change the code to make it return what I want? Edit: the number of Table Names varies based on $entry. Thanks, John $result = mysql_query("SHOW TABLES FROM feather") or die(mysql_error()); 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"; } Link to comment https://forums.phpfreaks.com/topic/162474-solved-code-almost-does-what-i-want-it-to/ Share on other sites More sharing options...
ArizonaJohn Posted June 17, 2009 Author Share Posted June 17, 2009 Nevermind. This gives me what I want: $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 $table) { $sql = "SELECT votes_up FROM `$table` WHERE `site` LIKE '$entry'"; $sql1 = mysql_query($sql) or die("$sql:".mysql_error()); while ($row = mysql_fetch_assoc($sql1)) { echo $table . ': "' . $row['votes_up'] . " for $entry from $table\"<br />"; } } Link to comment https://forums.phpfreaks.com/topic/162474-solved-code-almost-does-what-i-want-it-to/#findComment-857651 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.