Here is a quick example highlighting what u're trying to retrieve (id_item) from $_SESSION :
http://www.tehplayground.com/#Iyf7c0LTM
$arr = array();
$arr['cart']['1'] = 3;
$arr['cart']['18'] = 5;
// This loop will display every id_item that had be added to the "cart"
foreach($arr['cart'] as $row)
{
print "id_item : " . $row . "\n";
}
U can use now make ur sql query :
$sql = "SELECT * FROM products WHERE id =". $row;
EDIT - Since it was unclear for you, I made u the direct answer :
<?php
session_start();
// Examples of shopped items (added to $_SESSION['cart'])
$_SESSION['cart']['1'] = 3;
$_SESSION['cart']['18'] = 5;
// This loop will display every id_item that had be added to the "cart"
// Further informations how foreach works with array
// https://stackoverflow.com/questions/10057671/how-foreach-actually-works
foreach($_SESSION['cart'] as $row)
{
print "id_item : " . $row . "\n";
}
// Full Display to help understanding the process
print "<pre>";
print_r($_SESSION['cart']);
print "</pre>";
?>
Advanced explanations about "how foreach interacts with array" : here
EDIT 2 :
Fill db variables + column names of your table
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "";
$mysqli = new mysqli($servername, $username, $password, $dbname);
// check connection
if ($mysqli->connect_errno) {
printf("Connect failed: %s\n", $mysqli->connect_error);
exit();
}
// Query the DB - Get itemID & quantity added in the cart table
$query = "SELECT itemID, itemQuantity FROM cart";
$result = $mysqli->query($query);
// Return the result into an array
$res_array = $result->fetch_array();
// Add the items into $_SESSION
// Pattern : $_SESSION['cart']['$itemId'] = $itemQuantity
foreach($res_array as $row)
$_SESSION['cart'][($row['itemID'])] = $row['itemQuantity']
print "<pre>";
print_r($_SESSION['cart']);
print "</pre>";
?>
Example : here