这里有人知道如何加入2个桌子吗?我在语法方面一直有错误我不知道错误是什么以及在哪里。我想要的只是从不同的表中获取这些特定数据。请帮助!
<?php
echo"<ul>";
$sql="select product_title.products, qty.cart from products Inner Join cart on product_id.procucts=p_id.cart ";
$query = mysql_query($sql);
while($row = mysql_fetch_array($query))
echo"
<center>Summary of orders <br><br>
<li>Your Order: $row[0]</li>
<li>Quantity: $row[1]</li>
</center><br/>";
echo"</ul>";
?>
答案 0 :(得分:1)
表首先应该是第一个。因此,您的查询将如下所示:
1
2
3
4
Count: 0
答案 1 :(得分:1)
这是第一个答案的解释(由KinjaMistry)。
你必须始终是代码语法!您必须始终以大写形式编写保留的SQL字。您必须始终格式化代码。这样可以避免将来出现此类问题和错误。
SELECT
cart.qty,
products.product_title
FROM cart /* select first from cart beacause here cart is "parent" data */
INNER JOIN products /* join "dependency" data */
ON products.product_id = cart.p_id /* compare as dependency<->parent (like native: you<-above->friend) */
答案 2 :(得分:0)
当你select
&amp; join clause
table
列名称table name
。它应该首先显示$sql = "SELECT products.product_title, cart.qty FROM products INNER JOIN cart ON products.product_id = cart.p_id";
而不是列名。
join
有关public interface ISaveData
{
void DeleteFile(); // this is common method
}
public interface IPermission
{
void AssignPermission();
}
public interface IBucketOperation //or something else
{
void ChangeBucket();
}
public class AzureSaveData : ISaveData, IBucketOperation
{
public void ChangeBucket()
{
Console.WriteLine("AzureSaveData ChangeBucket");
}
public void DeleteFile()
{
Console.WriteLine("AzureSaveData DeleteFile");
}
}
public class GoogleCloudSaveFile : ISaveData, IPermission
{
public void AssignPermission()
{
Console.WriteLine("GoogleCloudSaveFile AssignPermission");
}
public void DeleteFile()
{
Console.WriteLine("GoogleCloudSaveFile DeleteFile");
}
}
的更多信息:
MySQL join