RE: [PHP] Delimiter WITHOUT lots of IF's
| From: | Ralph Guzman | Date: | Tue, 19 Aug 2003 07:08:21 +0000 |
| Subject: | RE: [PHP] Delimiter WITHOUT lots of IF's | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-159992@lists.php.net to get a copy of this message | ||
Actually, I missed a few things on that function. It should look like
this:
function cart_cdqty()
{
$query = "SELECT SUM(sess_itemsize) AS total_size
FROM sessions
WHERE sess_id = ".$_COOKIE['SID']."";
$result = mysql_query($query);
if(!$row = mysql_fetch_array($result))
{
return false;
} else {
$n = $row['total_size'];
$x = ceil( $n / 690.0 );
$cart_cdqty = array(
'quantity' => $x,
'total_size' => $n
);
return $cart_cdqty;
}
}
-----Original Message-----
From: Ralph Guzman [mailto:ralph@nqionline.com]
Sent: Monday, August 18, 2003 11:41 PM
To: 'Cesar Aracena'; php-general@lists.php.net
Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
Sensitivity: Confidential
I agree with Curt, use mySQL to get the sum of 'sess_itemsize' then
divide the result by size per disk to get quantity. So your function
should look something like this:
function cart_cdqty()
{
$query = "SELECT SUM(sess_itemsize) AS total_size
FROM sessions
WHERE sess_id = ".$_COOKIE['SID']."";
$result = mysql_query($query);
if($row = mysql_fetch_array($result))
{
$n = $row['total_size'];
$x = ceil( $n / 690.0 );
$cart_cdqty = array(
'quantity' => '$x',
'total_size' => '$n',
);
return $cart_cdqty;
} else {
return false;
}
}
Then all you do is call the function like this:
if(!$cdqty = cart_cdqty())
{
print 'no items found in your shopping cart';
} else {
print 'Total Size:' . $cdqty['quantity'] . '<BR>';
print 'Total CDs:' . $cdqty['total_size'] . 'MBs <BR>';
}
I have not tested this but it should work.
Ralph