【发布时间】:2013-12-12 17:55:35
【问题描述】:
所以我几个月来一直在努力解决这个问题,并希望在这里找到一劳永逸的解决方案。我使用phppwinty 作为pwinty.com 的php 库。
在作者提供的默认示例中,images 数组的创建如下例所示,其中所有变量都被硬编码为示例。
$photo1 = $pwinty->addPhoto($order, "4x6", "http://www.picisto.com/photos/picisto-20120608100135-925870.jpg", "1", "ShrinkToFit");
$photo2 = $pwinty->addPhoto($order, "6x6", "http://www.picisto.com/photos/picisto-20120601010631-895061.jpg", "4", "ShrinkToFit");
$photo3 = $pwinty->addPhoto($order, "5x7", "http://www.picisto.com/photos/picisto-20120626210525-763773.jpg", "3", "ShrinkToFit");
(注意:在训练中,我发现我们不一定需要在照片后面添加整数。而不是:photo1 它可以是photo。) p>
现在 $order 变量可以保留。接下来是尺寸、图片来源和数量。这是我目前唯一担心的三个变量。不幸的是,我使用购物车将这些分成了 3 个不同的表。
-- order_options -- The table for the size variable
--option_value -- The column for the size variable
--order_id -- Relationship column
-- order_products -- The table for the product id's and qty in the order
-- product_id -- The column for the product id variable
-- product_quantity -- The column for the quantity variable
-- order_id -- Relationship column
-- products -- The table for the image source variable
-- product_image -- The column for the image source variable
-- product_id -- Relationship column
我使用 get 变量将 order_id 放入脚本中:$order_id = $_GET['id'];
我尝试JOIN 将所有表格与关系联系在一起,但除了错误之外什么都没有,虽然我不相信问题出在JOIN 但我设置foreach 的方式。
我的 JOIN 和 foreach 现在看起来像这样:
foreach ($db->query("SELECT orderproducts.product_id, orderoptions.option_value, products.product_image FROM order_products as orderproducts INNER JOIN order_options as orderoptions ON orderproducts.order_id = orderoptions.order_id INNER JOIN products as products ON orderproducts.product_id = products.product_id WHERE orderproducts.order_id = $order_id AND orderproducts.product_id = $product_id") as $row)
$order_variables[] = $row;
if (count($order_variables) > 0):
foreach ($order_variables as $row):
$product_id = $row['product_id'];
$product_quantity = $row['product_quantity'];
$size = $row['option_value'];
$product_source = "https://www.alphahq.org/uploads/images/".$row['product_image']."";
$photo = $pwinty->addPhoto($order, $size, $product_source, $product_quantity, "ShrinkToFit");
endforeach;
endif;
我之所以说我认为问题在于 foreach 的设置方式是因为我在运行脚本时在浏览器中遇到的 1 错误如下:
Warning: Invalid argument supplied for foreach() in /home/www/alphahq.org/libraries/phppwinty/print.php on line 35
根据我的代码编辑器第 35 行是上面的 foreach 语句。
foreach ($db->query("SELECT orderproducts.product_id, orderoptions.option_value, products.product_image FROM order_products as orderproducts INNER JOIN order_options as orderoptions ON orderproducts.order_id = orderoptions.order_id INNER JOIN products as products ON orderproducts.product_id = products.product_id WHERE orderproducts.order_id = $order_id AND orderproducts.product_id = $product_id") as $row)
$order_variables[] = $row;
我希望我的描述性足够好,最终可以一劳永逸地解决这个该死的问题。提前感谢您的帮助,希望我们能共同制定解决方案。编码愉快。
如果我可以提供更多您认为对您有帮助的信息,请在下方留言索取信息。
【问题讨论】:
标签: php mysql sql arrays foreach