[thelist] Calculating values from field types (PHP + MySQL)

jon steele jjsteele22 at yahoo.com
Wed Aug 21 20:53:01 CDT 2002


You COULD try some nifty sql...

select 1.5+SUM(IF(type='a',1,0.5)) as shippingCost from test where id = 1 or id = 5 or id = 6 ...

You'd have to build the where part from your variable which contains the id's of the shopping
cart. Say it was an array...

//sample array just as an example
$myArray = array(1,3,23,56,776);

//init sql
$sql = "select 1.5+SUM(IF(type='a',1,0.5)) as shippingCost from test where ";

//build rest of sql
foreach($myArray as $currid){
	$newArray[] = "id=$currid";
}

$sql .= implode(" or ",$newArray);

$shippingCost = mysql_result(mysqlquery($sql),0));


__________________________________________________
Do You Yahoo!?
HotJobs - Search Thousands of New Jobs
http://www.hotjobs.com



More information about the thelist mailing list