Hi I have been trying to figure this out for a school project out for a couple of days now and I am seriously going crazy 🙁
Maybe some one can help.
I have 2 tables in a database(mysql), and I want to extract and print all rows from both tables, ussing one query.
Here is the closest I ever got :
$db="database";
$link = mysql_connect("localhost","username","password");
if (! $link)
die("Couldn't connect to MySQL");
mysql_select_db($db , $link)
or die("Couldn't open $db: ".mysql_error());
$result = mysql_query( "SELECT newspha.newspha_title, newsall.news_title FROM newspha, newsall" )
or die("SELECT Error: ".mysql_error());
$num_rows = mysql_num_rows($result);
print "There are $num_rows records.<P>";
print "<table width=200 border=1>\n";
while ($get_info = mysql_fetch_array($result)){
print "<tr>\n";
foreach ($get_info as $field)
print "\t<td><font face=arial size=1/>$field</font></td>\n";
print "</tr>\n";
}
print "</table>\n";
mysql_close($link);
At this point it returns 20 results, which intself shows I have something wrong as there are 5 rows in one and 4 in the other table. The resulting number of rows seem to be always the multiplication of the number of rows in one table and the other.
Perhaps I am going this totally the worng way. If anybody knows of an easy way to just display all rows from 2 diferent tables in one go please please please do tell 🙂
thanks alot
Larry