MySQL Forums
Forum List  »  PHP

UPDATE: I've tried "UNION SELECT" and it's getting warmer
Posted by: Kurt Wayne
Date: March 03, 2012 05:16PM

However, it's not working yet as my data is displaying strangely. Using "UNION" I was indeed able to work both tables in the same query without getting a blank page, and all the results are displaying; however, the site results are all displaying in the same column...the first column ("City") is displaying properly, but there's nothing in the next three columns. The radio and newspaper sites are all displaying in column 5, and the facebook/twitter sites are in columns 6 and 7, respectively.

$query = "SELECT city,radio,radio_site,rfacebook,rtwitter FROM my_radio UNION SELECT city,newspaper,newspaper_site,facebook,twitter FROM my_newspapers WHERE state='Arkansas' ORDER BY city LIMIT $offset, $rowsPerPage";

$result = mysql_query($query);


if($result)
{
while($row = mysql_fetch_array($result))
{

echo "<table border='1'>
<tr>
<th>City</th>
<th>Newspaper web site</th>
<th>Facebook</th>
<th>Twitter</th>
<th>Radio web site</th>
<th>Facebook</th>
<th>Twitter</th>
</tr>";

while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>";
echo "<a target=\"_new\" href=\"".$row['newspaper_site']."\">".$row['newspaper'] . "</a>";
echo "</td>";
echo "<td>";
if(strlen($row["facebook"]) > 0)
echo "<a target=\"_new\" href=\"".$row['facebook']."\">"."<IMG SRC=\"images/facebook.gif\">" . "</a>";

echo "</td>";
echo "<td>";
if(strlen($row["twitter"]) > 0)
echo "<a target=\"_new\" href=\"".$row['twitter']."\">"."<IMG SRC=\"images/twitter.gif\">" . "</a>";

echo "</td>";
echo "<td>";
echo "<a target=\"_new\" href=\"".$row['radio_site']."\">".$row['radio'] . "</a>";
echo "</td>";
echo "<td>";
if(strlen($row["rfacebook"]) > 0)
echo "<a target=\"_new\" href=\"".$row['rfacebook']."\">"."<IMG SRC=\"images/facebook.gif\">" . "</a>";

echo "</td>";
echo "<td>";
if(strlen($row["rtwitter"]) > 0)
echo "<a target=\"_new\" href=\"".$row['rtwitter']."\">"."<IMG SRC=\"images/twitter.gif\">" . "</a>";

echo "</td>";
echo "</tr>";
}

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.