[thelist] MySQL: How to see which table it was, after UNION

Mike evolt at muinar.com
Thu Jul 8 15:06:47 CDT 2004


Hi group

Maybe someone can help with this query? I'd like to show the last
entries of several DB tables on a homepage, ordered by date. So
far no big deal with the new UNION command. But here it comes:

Of course I need to link from this contents to the actual pages.
For this I need to know which tables the entries came from... And
here I'm stuck. Here's what I have so far (only with two tables):

$query = "
(select id as homeId,title as homeTitle,teaser as homeTeaser,date as 
homeDate from muinar_webnews order by homeDate desc limit 1) union
(select id as homeId,title as homeTitle,subtitle as homeTeaser,date as 
homeDate from kmu_tips order by homeDate desc limit 1)
order by homeDate desc";
$result = mysql_query( $query );
$number = mysql_numrows( $result );

for( $i = 0; $i < $number;$i++ )
         {
         $homeTable = mysql_field_table( $result,$i );
         $homeId = mysql_result( $result,$i,"homeId" );
         $homeTitle = mysql_result( $result,$i,"homeTitle" );
         $homeTeaser = mysql_result( $result,$i,"homeTeaser" );
         $homeDate = mysql_result( $result,$i,"homeDate" );
         list( $homeYear,$homeMonth,$homeDay ) = explode( '-',$homeDate );
         $homeDate = "$homeDay.$homeMonth.$homeYear";
         print( "<p>$homeTable $homeDate &nbsp;|&nbsp; $homeTitle 
&nbsp;|&nbsp; $homeTeaser</p>" );
         }

$homeTable always shows the same value, i. e. the first of the two tables,
which is wrong. What's wrong with using mysql_field_table here? Is there
a better way to identify the tables?

Thanks!!

Mike



_____  mike s. krischker  http://webdesign-schweiz.ch/
        webpro mailing list  http://webdesign-list.com/
        flashpro mailing list  http://flash-list.com/



More information about the thelist mailing list