On Thursday 17 October 2002 14:34, Steve Jackson wrote:
> Hi all.
> Wondering if anyone can shed some light!
>
> I have a problem whereby I need to define the weight of a selection of
> items in a shopping cart in order to calculate a shipping cost.
> Basically I have 5 products (at the moment) which are of set weights.
> What I want to do is add up the amount of items in the cart and multiply
> by weight then determine what the shipping weight is. Once that is
> determined I can calculate the shipping cost. My problem is arrays. I
> dunno what I'm doing with them! I can return the weight of one item and
> multiply that by the amount of items in the cart but need to figure out
> how do then do it again for any more items and add them to the first
> calculation. Here is my code:
>
> function calculate_weight($items)
> {
>       global $weight;
>       $conn = db_connect();
>       $query = "select weight from products
>                               where catid = $catid";
>       $result = @mysql_query($query);
>       $weight = ($result*$items);
>       return $weight;
> }
>
> Where $items is the number of items in the cart. $catid is the category
> the products are in but maybe I need to use a different identifier. I
> have another identifier called $itemCode which defines the actual item
> which would probably be more reasonable?

Your code as it stands does not do anything meaningful.

1) mysql_query() returns a resource_id -- which you assigned to $result.

2) You need to pass $result into one of these functions to actually get the 
data resulting from your query -- mysql_fetch_row(), mysql_fetch_array(), 
mysql_fetch_object(), mysql_result().

Try to get this part working then post your question again!

-- 
Jason Wong -> Gremlins Associates -> www.gremlins.com.hk
Open Source Software Systems Integrators
* Web Design & Hosting * Internet & Intranet Applications Development *

/*
Absence makes the heart grow fonder.
                -- Sextus Aurelius
*/


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

Reply via email to