In a UNION, only the names from the *FIRST* SELECT are accessible.
If you had done that same query using a DB tool, instead of trying to first do it in your PHP code, you would have seen that.
Code:
select movieid,namehe,nameen,poster,plot,imdb,janer, 'moviesdb' as movies
UNION
select gameid,namehe,nameen,poster,plot,rating,janer, 'gamesdb' as movies
In this case, you are correctly using your
movies field to discriminate between the two SELECTs, so your PHP logic simply needs to be somthing like
Code:
if ( $row["movies"] =="gamesdb" )
{
$gameid = $row["movieid"];
$rating = $row["imdb"];
} else {
$movieid = $row["movieid"];
$imdb = $row["imdb"];
}
And alternative, if you really want the two fields to be separate, would be to do:
Code:
select movieid,...,plot,imdb, NULL AS rating, janer, ...
UNION
select gameid,...,plot,NULL AS imdb, rating, janer, ...
And, in fact, you *SHOULD* do that if
imdb and
rating are not compatible data types.
For example, if
imdb is INT and
rating is CHAR(2) then they should *NOT* be combined into the
imdb name as you had them in your original query.
MySQL is fairly loose about "compatible types" (more so than most DBs), but sometimes that can get you in trouble.