RE: [PHP] Delimiter WITHOUT lots of IF's

From: Date: Tue, 19 Aug 2003 17:18:02 +0000
Subject: RE: [PHP] Delimiter WITHOUT lots of IF's
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-160032@lists.php.net to get a copy of this message
Ralph, I tested the function below but the result at the page is: "CD Quantity: Array" and not the CD quantity according to file size... Why is the array there and what it is supposed to be called with to give one or another result? Thanks, Cesar Aracena www.icaam.com.ar > > 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 > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.general (#160032) next »