I've researched but am yet to find a solution...
I currently have a site I'm constructing in Flash, and I'm using PHP and a mySQL db to ensure the content on the flash page is database driven.
I currently have one php file, which connects to the DB in the usual way and outputs all fine, but I need to print out some information from multiple tables on this one page. So for instance I have one table which holds all the content for, say the Home Page, consisting of simple welcome text and title. I then have another table storing the latest news, which i intended to have a snippet of on that same Home Page as the welcome text, so the user could read a bit then click through to the news page to read more.
Whilst researching, the only logical way I could see that other people suggest to connect to multiple tables within one SELECT query is using UNION?? I couldn't find anything on php.net about this, but assumed as it comes up quite a lot it must be used. I get this error:
This applies to each field in that second news table I'm trying to connect to. I've tested in another php file, just connecting to this db and printing out details from it and it works fine, but won't work combined with the other database in one page. Can this be done (i.e. connect to two database tables in one PHP file SELECT statement and print out the relevant fields for use later on, or am i going about this in completely the wrong way!?!? Any advice would be hugely appreciated. Below is my code:Notice: Undefined index: news_title in /Applications/MAMP/htdocs/flashSite/testing.php on line 22
Code: Select all
<?php
//variables for connecting to database
include("db_connect.php");
loginInfo();
mysql_pconnect ($host, $user, $pass) or die ("Login info is incorrect") ;
mysql_select_db ($database);
$qResult = mysql_query ("SELECT id,home_title,home,about FROM $table UNION SELECT id,news_title,news_post,date FROM $tableTwo");
$nRows = mysql_num_rows($qResult);
//string var for first db table
$rString ="";
//string var for 2nd db table
$newsString = "";
$row = mysql_fetch_array($qResult);
//the & are for use in Flash later on
$rString .="&ID"."=".$row['id']."&home_title"."=".$row['home_title']."&home"."=".$row['home']."&about"."=".$row['about'];
$newsString .="&ID"."=".$row['id']."&newsTitle"."=".$row['news_title']."<br>"."&date"."=".$row['date']."<br><br>"."&newsPost"."=".$row['news_post'];;
// printing it to the document
echo nl2br($rString."&");
echo $newsString . "<br>";
?>