So I have been fighting this for months now and am hoping to find a solution here once and for all. I am using phppwinty as a php library for pwinty.com.
In the default example provided by the author, the images array is created like the example below with all the variables hard coded as an example.
$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");
(note: in training, I have found out we don't necessarily need to add the integer after photo. instead of: photo1 it can just be photo.)
Now the $order variable is fine to stay. Next is the size, image source, and quantity. These are the only 3 variables I am worried about at the moment. With the shopping cart I have these unfortunately are broken up into 3 different tables.
-- 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
I get the order_id into the script with a get variable: $order_id = $_GET['id'];
I have attempted to JOIN all the tables together with relationships and have got nothing but errors, Though I don't beleive the problem is in the JOIN but the way I have the foreach set up.
My JOIN and foreach looks like this right now:
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;
The reason I say I believe the problem is in how the foreach is set up is because the 1 error I get in my browser when I run the script is as follows:
Warning: Invalid argument supplied for foreach() in /home/www/alphahq.org/libraries/phppwinty/print.php on line 35
According to my code editor line 35 is the foreach statement from above.
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;
I hope I have been descriptive enough to finally get a solution to this darn problem once in for all. Thank you for your help in advance and hope we can work out a solution together. Happy coding.
If I can provide any more information that you believe would be helpful, please simply comment kindly below requesting the information.