使用一个查询和一个php文件显示来自两个不同表的图像

i have two select statement in one query in loadimage.php fle and display it in two different procees, one image for the event and one image for news. my code goes like this

loadimage.php

<?php
mysql_connect("localhost","root");
mysql_select_db("pcnl");
$q="select * from tbl_event where event_ID = ".$_GET['id'];
$rec=mysql_fetch_array(mysql_query($q));
$image=$rec['event_img'];
header('Content-Length: '.strlen($image));
header("Content-type: image/".$rec['event_imgExt']);
echo $image;

$sqlmain="select * from tbl_news where news_ID = ".$_GET['mainid'];
$mainimg=mysql_fetch_array(mysql_query($sqlmain));
$mainimage=$mainimg['news_img'];
header('Content-Length: '.strlen($mainimage));
header("Content-type: image/".$mainimg['news_ext']);
echo $mainimage;
?>

event.php

<img src="loadimage.php?id=<?php echo $events[id];?>" width="700px" height="350px">

news.php

<img src="loadimage.php?mainid=<?php echo $main['news_ID'];?>" width="300px" height="350px">

You haven't asked any question, said what you expect to happen, said what did happen, told us about the errors which should have been logged when you ran this.

You can't return multiple resources in response to a single HTTP request. (this is not strictly true, but that's like talking about string theory when you're still getting the basics of arithmetic).

BTW your current script is vulnerable to SQL injection.

Try this:

<?php
mysql_connect("localhost","root");
mysql_select_db("pcnl");
$t='event'==$_GET['itype'] ? 'tbl_event' : 'tbl_news';

$q="select * from $t where event_ID = ".(integer)$_GET['id'];
if ($rec=mysql_fetch_array(mysql_query($q))) {
   $image=$rec['event_img'];
   header('Content-Length: '.strlen($image));
   header("Content-type: image/".$rec['event_imgExt']);
   echo $image;
} else {
   header('HTTP/1.0 404 Not Found', 404);
}

and...

<img src="loadimage.php?itype=event&id=<?php echo $events['id'];?>"...

<img src="loadimage.php?itype=main&id=<?php echo $main['news_ID'];?>"...

Or better yet just have a single table holding the data.