sub.phl
前の
買物かご
に使う sub.phl である
<?php
class Cart {
var $item;
//新規
function Cart() {
$this->item = null;
}
//商品追加
function addItem($item_cd, $num) {
$this->item[$item_cd] += $num;
}
//商品削除
function removeItem($item_cd, $num) {
$this->item[$item_cd] -= $num;
if ($this->item[$item_cd] < 0) {
$this->item[$item_cd] = 0;
}
}
//商品全削除
function clear() {
$this->item = null;
}
//商品一覧表示
function showItem() {
if ($this->item != null){
$tmp = "";
while(list($_cd, $_num) = each($this->item)) {
$tmp .= "<tr>" .
"<td>" . '..'. $_cd .'..'. "</td>" .
"<td> ".
"<input type='text' value='".$_num."' size='3'>".
"</td>" .
"</tr>";
}
print "買物かごの中身<p>\n";
echo "<table cellspacing=0 cellpadding=3 border=1>".$tmp."</table>";
}
}
}
?>
|