Note that there are some explanatory texts on larger screens.

plurals
  1. POBuilding a photo array from database tables
    primarykey
    data
    text
    <p>So I have been fighting this for months now and am hoping to find a solution here once and for all. I am using <a href="http://www.bradpineau.com/PHPPwinty/" rel="nofollow">phppwinty</a> as a php library for <a href="http://pwinty.com" rel="nofollow">pwinty.com</a>. </p> <p>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. </p> <pre><code>$photo1 = $pwinty-&gt;addPhoto($order, "4x6", "http://www.picisto.com/photos/picisto-20120608100135-925870.jpg", "1", "ShrinkToFit"); $photo2 = $pwinty-&gt;addPhoto($order, "6x6", "http://www.picisto.com/photos/picisto-20120601010631-895061.jpg", "4", "ShrinkToFit"); $photo3 = $pwinty-&gt;addPhoto($order, "5x7", "http://www.picisto.com/photos/picisto-20120626210525-763773.jpg", "3", "ShrinkToFit"); </code></pre> <p><em>(note: in training, I have found out we don't necessarily need to add the integer after photo. instead of: <code>photo1</code> it can just be <code>photo</code>.)</em></p> <p>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.</p> <pre><code>-- 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 </code></pre> <p>I get the order_id into the script with a get variable: <code>$order_id = $_GET['id'];</code></p> <p>I have attempted to <code>JOIN</code> all the tables together with relationships and have got nothing but errors, Though I don't beleive the problem is in the <code>JOIN</code> but the way I have the <code>foreach</code> set up.</p> <p>My <code>JOIN</code> and <code>foreach</code> looks like this right now: </p> <pre><code>foreach ($db-&gt;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) &gt; 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-&gt;addPhoto($order, $size, $product_source, $product_quantity, "ShrinkToFit"); endforeach; endif; </code></pre> <p>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: </p> <pre><code>Warning: Invalid argument supplied for foreach() in /home/www/alphahq.org/libraries/phppwinty/print.php on line 35 </code></pre> <p>According to my code editor line 35 is the foreach statement from above. </p> <pre><code> foreach ($db-&gt;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; </code></pre> <p>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.</p> <p><strong>If I can provide any more information that you believe would be helpful, please simply comment kindly below requesting the information.</strong> </p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload