Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在php中从一个数据库的两个不同表中获取多个数据_Php_Mysql_Database_Html - Fatal编程技术网

如何在php中从一个数据库的两个不同表中获取多个数据

如何在php中从一个数据库的两个不同表中获取多个数据,php,mysql,database,html,Php,Mysql,Database,Html,我正在创建购物网站,现在我有一个table call products,其中存储了所有产品数据,我有不同的table cart,其中存储了添加到cart的所有产品,因此基本上我在cart中存储了productid,userid现在在checkout页面上,我想从cart表中检索数据,我们将获取特定登录用户的productid,从products表中我们将显示添加到cart的所有产品,因此基本上从cart表中我们将获取添加到cart的产品,从products表中我们将显示它们。现在的问题是,我已经

我正在创建购物网站,现在我有一个table call products,其中存储了所有产品数据,我有不同的table cart,其中存储了添加到cart的所有产品,因此基本上我在cart中存储了productid,userid现在在checkout页面上,我想从cart表中检索数据,我们将获取特定登录用户的productid,从products表中我们将显示添加到cart的所有产品,因此基本上从cart表中我们将获取添加到cart的产品,从products表中我们将显示它们。现在的问题是,我已经检索到了数据,但它只显示了一个项目,而不是多个项目。提前谢谢

这是我的密码:


项目
价格
传送
小计
₹;
免费送货
$100.00
找不到数据。。。
找不到数据。。。

您可以使用内部联接使用单个查询

  SELECT  a.cartid
    , a.userid
    , a.productid
    , b.productname
    , b.productcategory
    , b.producttype
    , b.productprice
    , b.productimage1
    FROM  cart
    INNER JOIN  products ON a.productid = b.productid 
    where a.productid= :uid

您应该在JOIN语句中使用另一个且仅使用一个查询

SELECT * FROM cart c JOIN products p ON p.productid = c.productid WHERE c.userid = :uid

您将收到的数据将包含来自购物车的产品数据。

我将添加此技术,它更接近我所使用的,没有其他人做过完全相同的操作

select  *
from    cart c,
        products p
where   p.product_id = c.product_id
and     c.userid = :uid