简体   繁体   English

PHP函数与多个查询-内部联接重复结果?

[英]php function with with multiple queries - inner join duplicating results?

I have been tackling trying to incorporate and implement a shopping cart system. 我一直在努力尝试合并和实施购物车系统。

How do I make it display 1 add to cart button with each shop product listing with the correct price showing? 如何使它显示1添加到购物车按钮,其中每个商店产品列表均显示正确的价格?

I have a function in my functions file. 我的功能文件中有一个功能。 And the function has 2 queries in it. 该函数中有2个查询。

first table called: products 第一张桌子叫: products

    $results = $db->query("SELECT DISTINCT * FROM `products` INNER JOIN `shop` ON `products`.`id` = `shop`.`id`;");
    $paypalContent = "";
    while($row = $results->fetch_assoc())
        {

second table called: shop 第二张桌子叫: shop

    $results = $db->query("SELECT DISTINCT * FROM shop ");
    while($row = $results->fetch_assoc())
    {

I use 我用

unset($results);
unset($row);

to unset the results so that the second query can be queried. 取消设置结果,以便可以查询第二个查询。

So basically my results is resulting in it repeating the add to cart buttons for all rows in the products table. 因此,基本上,我的结果是针对产品表中的所有行重复添加到购物车按钮。 I will show a picture. 我将显示图片。

在此处输入图片说明

So table info: the shop table has all info in it, 18 rows with pictures and links and descriptions etc etc. 表格信息:车间表格中包含所有信息,带有图片,链接和说明等的18行等。

Structure: 结构体:

 table 1 - products: id, name, image, price, status 
 table 2 - shop: id,title, name, standardprice, commercialprice, image, image2, image3, image4, image5, image6, description, descr, more, moredetails, url, paypalstandard, paypalcommercial

I will be removing the paypalstandard and paypalcommercial once i got this working. 一旦完成此工作,我将删除paypalstandard和paypalcommercial。 also the standardprice and commercial price is for other pages. 标准价格和商业价格也适用于其他页面。

Second table is basically for the products so it creates the buttons for the paypal end in a form. 第二个表基本上是针对产品的,因此它以一种形式为贝宝结束创建按钮。

So I do have a row for standard and commercial in each table, products and shop. 因此,在每个表,产品和商店中,我确实都有标准行和商业行。 So I need it to display the correct add to cart button for each shop listing - which is 1 button for each listing. 因此,我需要它为每个商店列表显示正确的“添加到购物车”按钮-每个列表为1个按钮。 It is needing to be linked to the product so it creates the correct button and price for each shop product. 它需要链接到产品,以便为每个商店产品创建正确的按钮和价格。

EDIT: So I need it to show 1 button per shop item. 编辑:所以我需要它显示每个商店项目1个按钮。 so as you see in the picture above it shows 4 buttons. 如上图所示,它显示了4个按钮。 I need it to show just 1 for each with the correct price reflected in each product. 我需要为每个产品只显示1个,并在每个产品中反映出正确的价格。

FURTHER EDIT: My 2 tables both have id and both are primary keys. 进一步编辑:我的2个表都具有id并且都是主键。 I have tried many different queries with left and right join to no avail. 我尝试了左右联接的许多不同查询,但均无济于事。

Thanks 谢谢

Well first to start i'd recommend you to use JS making the temporary cart for front end. 首先,我建议您使用JS制作前端的临时购物车。 After you build up a data and send int as json or whatever and just update using the needed items, dont reserve or inner because its not needed. 建立数据并以json或其他形式发送int并仅使用所需项进行更新后,请不要保留或内部,因为不需要它。 Wait the xhr or whatever your php post the data and just update with the data dont use inner because its not needed at all. 等待xhr或任何您的php发布数据,然后仅使用数据更新就不要使用inner,因为根本不需要它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM