所以我有一个查询,我从两个不同的表中选择值并将它们联合在一起。我需要知道哪个条目来自哪里,因为我需要为每个条目形成不同的 URL。标记这两个 SELECT 查询的最佳方式和正确语法是什么。任何帮助,将不胜感激。要遵循的代码:
$query = "SELECT newsletter_id id, newstitle title FROM tbl_news WHERE (newstitle LIKE '%".stripslashes($rowCont->fname)."%' && newstitle LIKE '%".stripslashes($rowCont->lname)."%') || (newsletter_content LIKE '%".stripslashes($rowCont->fname)."%' && newsletter_content LIKE '%".stripslashes($rowCont->lname)."%') SET @type = news
UNION
SELECT event_id id, event_title title FROM tbl_event WHERE ((event_title LIKE '%".stripslashes($rowCont->fname)."%' && event_title LIKE '%".stripslashes($rowCont->lname)."%') || (event_content LIKE '%".stripslashes($rowCont->fname)."%' && event_content LIKE '%".stripslashes($rowCont->lname)."%')) SET @type = event";
$result = mysql_query($query) or die(mysql_error());
$i = 0;
while($row = mysql_fetch_assoc($result)) {
if($table_name == table1) { //SIMULATED TABLE NAME VARIABLE IF STATEMENT, NEED TO KNOW HOW TO GET TABLE NAME FOR SORTING
echo "<p><a style='color:#00aeef' href='http://www.url1.com/display.php?article_=".$row["id"]."'>".$row["title"]."</a></p>";
} else {
echo "<p><a style='color:#00aeef' href='http://www.url1.com/display.php?article_=".$row["id"]."'>".$row["title"]."</a></p>";
}
}