help with if statement and then mailing

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
RobLamb
Forum Newbie
Posts: 2
Joined: Mon Jul 27, 2009 3:16 am

help with if statement and then mailing

Post by RobLamb »

Good day everyone
I have a page that generates a cart on a site. Basically what I want is that if the values of the size2 and 3 are empty then they must be hidden and if they are populated then be shown. I have tried a couple of options and am not winning! Could someone please help me out on this one urgently. Then... my next issue is that I need to mail this off to a client and am battling with that too becasue I am unsure on how to do this when the names of my fields are based on the products id!! Some help and advise would be greatly appreciated... here is the code I have....please..any urgent help would be appreciated!

<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p>You have 0 in your shopping cart</p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '<p>You have <a href="cart.php">'.count($items).' item'.$s.' in your shopping cart</a></p>';
}
}

function showCart() {
global $db;
//echo $db;
$cart = $_SESSION['cart'];
//echo $cart;
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart.php?action=update" method="post" id="cart">';
$output[] = '<table border="0">';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM tbl_products WHERE prod_id = '.$id;
//echo $sql2;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td width="50px" align="center"><img src="prodImages/'.$prod_image.'" width="30px" height="30px"></td>';
$output[] = '<td nowrap=nowrap>&nbsp;</td>';
$output[] = '<td nowrap=nowrap>'.$prod_name.'</td>';
$output[] = '<td nowrap=nowrap>'.$size1.' @ R'.$price.'<input onclick="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="price'.$id.'" type="radio" value="'.$price.'" checked="checked"/>&nbsp;'.$size2.' @ R'.$price2.'<input onclick="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="price'.$id.'" type="radio" value="'.$price2.'" />&nbsp;'.$size3.' @ R'.$price3.'<input onclick="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="price'.$id.'" type="radio" value="'.$price3.'" /></td>';
$output[] = '<td nowrap=nowrap><input onblur="KW_calcForm(\'total'.$id.'\',100,-1,\'#price'.$id.'\',\'*\',\'#qty'.$id.'\')" name="qty'.$id.'" type="text" value="'.$qty.'" size="3" maxlength="5" /></td>';
$output[] = '<td nowrap=nowrap>&nbsp;</td>';
$output[] = '<td nowrap=nowrap><input type="text" name="total'.$id.'" size="5" /></td>';
$output[] = '<td nowrap=nowrap><a href="cart.php?action=delete&id='.$id.'" class="r">Remove</a></td>';
$total += $price * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '&nbsp;';
$output[] = '<div><button type="submit" class="button">Update cart</button></div>';
$output[] = '</form>';
} else {
$output[] = '<p>Your shopping cart is empty.</p>';
}
return join('',$output);
}
?>
Post Reply