Okay so my issue is that I am trying to loop through $_SESSION variables with each element of that array getting a query (that checks the database for its existence). I am having problems figuring out the correct way to do the syntax, especially for the query.
Essentially I am trying to concatenate the element name from the $_SESSION array with the variable $n which will just be an integer increasing by 1 every time it goes through the loop.
PHP Code:
$n = 0;
while(isset($_SESSION['item_' . $n])) {
$[B]current_cart_query = "SELECT product_name, product_price, product_desciption, image_path
FROM products WHERE product_id = $_SESSION['item_'" . $n]" LIMIT 1";[/B] //need to do a join?
$current_cart_results = mysqli_query($dbc, $current_cart_query) or trigger_error("Query: "
. $current_cart_query . "\n<br />MySQL Error: " . mysqli_error($dbc));
$cc_row = mysqli_fetch_array($current_cart_results, MYSQLI_ASSOC);
$product_total = $ccrow['product_price '] * $_SESSION['item_' . $n . 'qty'];
echo '
<div class="product_box">
<span class="product_image">
<a href="view_product.php?product_id=' . $ccrow['product_id'] . '">
<img src="' . $ccrow["image_path"] . '" />
</a>
</span>
<strong>' . $ccrow["product_name"] . '</strong><br />
"<em>' . $ccrow["product_description"] . '</em>"<br />
<strong>' . $ccrow["product_price"] . '</strong> x ' . $_SESSION["item_" . $n . "qty"] .
' = $' . $product_total . '
</div>
';
$n++;
}
}
Currently the error that I am getting says the following:
Code:
Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/kylhur/ecommerce.danconia.us/cart.php on line 46
Where line 46 is the line in bold. What is the correct syntax to do this? Maybe there is an easier way?