Hi guys
I try to display models of session cart. But the way that I coded it I always display the same "model" no mather which model I added. I also can't see them afterwards. I already tried since one week to solve that problem but I get no where.
1.st page:
<html>
<body>
<head>
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<div class=logofix>
</div>
<?php
require_once('navbar.php');
include('connection.php');
if(! $conn )
{
die('Could not connect: ' . mysql_error());
}
$result = mysql_query('SELECT * FROM femalemodels_t ORDER BY m_name');
echo '<div class="scrollImages">';
while($row = mysql_fetch_array($result)){
?> <img src="<?php echo $row['path'];?>" height="" width=""><br/> <?php
echo '<div class="infoText">';
echo '<b>NAME:</b>';
echo $row['m_name'].'<br/>';
echo '<b>SIZE:</b>';
echo $row['m_size'].'<br/>';
echo '<b>EYECOLOR:</b>';
echo $row['m_eyecolor'].'<br/>';
echo '<b>HAIRCOLOR:</b>';
echo $row['m_haircolor'].'<br/>';
echo '<b>BUST:</b>';
echo $row['m_bust'].'<br/>';
echo '<b>WAIST:</b>';
echo $row['m_waist'].'<br/>';
echo '<b>HIPS:</b>';
echo $row['m_hips'].'<br/>';
echo '</div>';
}
echo '</div>';
?>
</body>
</html>
Session file:
<?php
ob_start();
session_start();
include('connection.php');
// 2) When the linked to page is visited, add the specified item to the cart with a quantity of one...
// a) Validate the id received from the link.
$id = isset($_GET['ID']) ? (int)$_GET['ID'] : 0; // zero is not used/valid for a database auto-increment value that would be used as an id
if($id < 1){
// not a valid id
echo "The requested id is not valid";
} else {
// the id is valid
// b) If the cart doesn't exist, create an empty one.
if(!isset($_SESSION['cart'])){
$_SESSION['cart'] = array();
}
// c) Add the item to the cart with a quantity of one, if it is not already in the cart or increment the item quantity if it is already in the cart.
if(!isset($_SESSION['cart'][$id])){
// id is not in the cart, create an entry
$_SESSION['cart'][$id] = 0; // initialize to zero (the next statement will set it to one)
}
$_SESSION['cart'][$id]++; // add one to the quantity (if the item was already in the cart with some quantity, this will increment the quantity)
}
// At this point, you are done with the add to cart task.
// You would either link/redirect back to the page that displays all the items
// or you could display the cart contents, by retrieving all the id's from the cart (see the array_keys() and implode() functions), then retrieve the information from the database table and loop over it to display it
// or you could incorporate this code into the main page, making a single page.
// for demo purposes, just display the session data -
header('location:viewreadinglist.php');
?>
[/PHP
file to display the the items from sessions cart:
[code=php]<?php
ini_set('display_errors',1);
ini_set('display_startup_errors',1);
error_reporting(-1);
session_start();
include('connection.php');
var_dump($_SESSION['cart']);
echo '<table >';
foreach($_SESSION['cart'] as $value){
$query = 'SELECT * FROM femalemodels_t WHERE ID='.$value;
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo '<tr>';
echo '<td>'.$row['ID'].'</td>';
echo '<td>'.$row['m_name'].'</td>';
echo '<td>'.$row['m_address'].'</td>';
echo '<td>'.$row['m_phonenumber'].'</td>';
/*echo '<td ><a style="color:red;" href="lab20_AddBookmark.php?ID='.$row['ID'].'"><img src="icon_bookmark.gif" alt="delete link"/></a></td>';*/
echo "</tr>";
}
echo '</table>';
?>
Help would be very much appreciated!