I'm using both variables called in another page.
Taking globals off causes weight not to be calculated in the shipping
cost?

Steve Jackson
Web Developer
Viola Systems Ltd.
http://www.violasystems.com
[EMAIL PROTECTED]
Mobile +358 50 343 5159



> -----Original Message-----
> From: Jason Wong [mailto:[EMAIL PROTECTED]] 
> Sent: 17. lokakuuta 2002 12:39
> To: [EMAIL PROTECTED]
> Subject: Re: [PHP] Weight function.
> 
> 
> On Thursday 17 October 2002 15:52, Steve Jackson wrote:
> > Thanks.
> > I have just this minute got it working.
> > Basically the same function I used for determining price of 
> the cart 
> > items could be used for determining weight. All I needed to do was 
> > assign my DB with a field called weight and call that 
> instead of price 
> > from the DB so my calculate weight function looks like this.
> >
> > function calculate_weight($cart)
> > {
> >   // sum total weight for all items in shopping cart
> >   global $weight;
> >   $weight = 0.0;
> >   if(is_array($cart))
> >   {
> >     $conn = db_connect();
> >     foreach($cart as $ItemCode => $qty)
> >     {
> >       $query = "select weight from products where 
> ItemCode='$ItemCode'";
> >       $result = mysql_query($query);
> >       if ($result)
> >       {
> >         $item_weight = mysql_result($result, 0, "weight");
> >         $weight +=$item_weight*$qty;
> >       }
> >     }
> >   }
> >   return $weight;
> 
> See below
> 
> > }
> >
> > By making $weight a global variable I then call that in my shipping 
> > function and set it's parameters:
> 
> By making $weight a global variable there is no need for 
> "return $weight;" 
> inside your function. And same for "return $shipping;" below.
> 
> 
> > function calculate_shipping_cost($weight)
> > {
> >   //shipping costs calc. less than 10KG is 15 more than 
> 10KG currently 
> > 20.
> >
> >     global $shipping;
> >     if ($weight <= "10000")
> >     $shipping = "15";
> >     else
> >     $shipping = "20";
> >     return $shipping;
> >
> > }
> >
> > I still don't fully understand why this works but am happy it does!
> 
> -- 
> Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
> Open Source Software Systems Integrators
> * Web Design & Hosting * Internet & Intranet Applications 
> Development *
> 
> /*
> The solution of problems is the most characteristic and 
> peculiar sort of voluntary thinking.
>               -- William James
> */
> 
> 
> -- 
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
> 


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

Reply via email to