* Thus wrote Cesar Aracena ([EMAIL PROTECTED]):
> Ok. Here you have the entire function to see how many CD's the order
> will contain:
> 
> function cart_cdqty()
> {
>       $query = "SELECT * FROM sessions WHERE sess_sid =
> ".$_COOKIE['SID']."";
>       $result = mysql_query($query);
>       $num_rows = mysql_num_rows($result);
>       
>       $x = 0;
>       $n = 0;
>       
>       for ($y = 0; $y < $num_rows; $y++)
>       {
>               $row = mysql_fetch_array($result);
>               $n = $n + $row[sess_itemsize];
>       }

For one, sql can handle this for you. much faster too, I might add.
just do something like:

  select sum(sess_itemsize) from sessions where sess_id = ...
  
  ...

  $result = mysql_query($query);
  list($n) = mysql_fetch_row($result);

>       
>       if ($n > 0 AND $n <= 690.0) { 
>               $x = 1;
>       } elseif ($n > 690.1 AND $n <= 1380.0) { 
>               $x = 2;
>       } elseif ($n > 1380.1 AND $n <= 2070.0) { 
>               $x = 3;
>       } elseif ($n > 2070.1 AND $n <= 2760.0) { 
>               $x = 4;
>       } elseif ($n > 2760.1 AND $n <= 3450.0) { 
>               $x = 5;
>       }

A simple division of the size per disk will give you the qty:
  $x = ceil( $n / 690.0 );

Now it wont be so bad if someone is ording 30 disks worth... i'd
hate to see that if statment not to mention write it :)

You might want to check for $x < 0 cause I don't think the customer
will be happy if he has to pay you to send you his disks.

Curt
-- 
"I used to think I was indecisive, but now I'm not so sure."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to