PHP mySQL, Joining More than Two Tables Together with Similar IDs?

我们两清 提交于 2019-12-13 06:59:14

问题


Here is what I am working with:

$query = "SELECT Products.Title, Product_Lines.pl_Title, Manufacturers.man_Title".
 "FROM Products, Product_Lines, Manufacturers ".
    "WHERE Products.pl_ID = Product_Lines.pl_ID AND Product_Lines.man_ID = Manufacturers.man_ID";

$result = mysql_query($query) or die(mysql_error());


while($row = mysql_fetch_array($result)){
    echo $row['Title']. " - ". $row['pl_Title']. " - ". $row['man_Title'];
    echo "<br />";
}

I am getting this error:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server
version for the right syntax to use near 'WHERE Products.pl_ID = Product_Lines.pl_ID AND  
Product_Lines.man_ID = Manufactur' at line 1   

I am unfamiliar with this method and this error


回答1:


SELECT Products.Title, Product_Lines.pl_Title, Manufacturers.man_Title
 FROM Products INNER JOIN Product_Lines ON Products.pl_ID = Product_Lines.pl_ID INNER JOIN Manufacturers ON Product_Lines.man_ID = Manufacturers.man_ID

WILL DO




回答2:


I don't see white space before your FROM clause. This is a possible cause for the error. Try:

$query = "SELECT Products.Title, Product_Lines.pl_Title, Manufacturers.man_Title".
 " FROM Products, Product_Lines, Manufacturers ".
    "WHERE Products.pl_ID = Product_Lines.pl_ID AND Product_Lines.man_ID = Manufacturers.man_ID";



回答3:


Need To follow two things

  • Foriegn Key
  • Join

Search Join i.e [left join right join...] In Inter u ll get anwser for ur question/..



来源:https://stackoverflow.com/questions/6436897/php-mysql-joining-more-than-two-tables-together-with-similar-ids

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!