Skip navigation links

MySQL Forums :: PHP :: Able to select multiple tables with manually generated (primary) keys, but not auto-numbered ones


Advanced Search

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


Subject Written By Posted
Able to select multiple tables with manually generated (primary) keys, but not auto-numbered ones Kurt Wayne 03/03/2012 11:51AM
UPDATE: I've tried "UNION SELECT" and it's getting warmer Kurt Wayne 03/03/2012 05:16PM
Re: UPDATE: I've tried "UNION SELECT" and it's getting warmer Kurt Wayne 03/05/2012 09:29AM
Re: UPDATE: I've tried "UNION SELECT" and it's getting warmer Barry Galbraith 03/05/2012 03:57PM
Re: UPDATE: I've tried "UNION SELECT" and it's getting warmer Kurt Wayne 03/07/2012 10:22AM
Re: UPDATE: I've tried "UNION SELECT" and it's getting warmer laptop alias 03/07/2012 10:24AM
Thanks, laptop alias (and Barry), here is the SHOW CREATE TABLE Kurt Wayne 03/07/2012 08:16PM
Re: Thanks, laptop alias (and Barry), here is the SHOW CREATE TABLE Barry Galbraith 03/07/2012 08:58PM
Barry Galbraith, here is some additional information Kurt Wayne 03/08/2012 12:54PM
Re: Barry Galbraith, here is some additional information Barry Galbraith 03/08/2012 05:09PM
Re: Barry Galbraith, here is some additional information Kurt Wayne 03/09/2012 06:11PM
Re: Barry Galbraith, here is some additional information Barry Galbraith 03/10/2012 12:27AM
Re: Barry Galbraith, here is some additional information Rick James 03/11/2012 03:57PM


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.