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

Dave Stevens stem at stemofficial.co.uk
Wed Aug 21 19:06:01 CDT 2002


thanks for the reply, I'll have a go - bit more advanced than anything I've
ever done, but I'll try to get it sorted this way. Thanks for taking the
time...

Dave S

----- Original Message -----
From: "Rich Gray" <richardgray at onetel.co.uk>
To: <thelist at lists.evolt.org>
Sent: Thursday, August 22, 2002 8:55 AM
Subject: RE: [thelist] Calculating values from field types (PHP + MySQL)


> Hi Dave,
>
> <caveat>
> Not seen your code, assuming MySQL, no quantities taken into account, a
> shopping cart class with an array of selected product ids, pseudo code...
> </caveat>
>
> $link = mysql_connect('localhost','me','pw');
> if  (mysql_select_db('mydb')) {
>
> foreach($Cart->pids as $pid) {
> $res=mysql_query('select type from products where id = \''.$pid.'\'');
> if (mysql_num_rows($res) > 0) {
> $row = mysql_fetch_row($res);
> switch $row[0] {
> case 'a':
> $Cart->ship_cost[$pid] += 1.00;
> break;
> case 'b':
> $Cart->ship_cost[$pid] += 0.50;
> break;
>                                         default:
> $Cart->ship_cost[$pid] += 10000000.00;  // or whatever.... :)
> }
> }
> else $Cart->item[$pid] = null;
> }
> }
> mysql_close();
>
> HTH
> Rich
> -----Original Message-----
> From: thelist-admin at lists.evolt.org
> [mailto:thelist-admin at lists.evolt.org]On Behalf Of Dave Stevens
> Sent: 21 August 2002 16:09
> To: thelist at lists.evolt.org
> Subject: [thelist] Calculating values from field types (PHP + MySQL)
>
>
> --
> [ Picked text/plain from multipart/alternative ]
> Greetings evolters,
>
> Sorry about the vague title, I'll try and explain better here.
>
> I've hit another problem in my latest project (you'll have noticed the
> previous two questions, sorry!)
>
> Here's the trouble:
>
> I need to calculate the shipping costs for different items in my store.
> These are calculated as follows:
>
> A base rate of £1.50 stands for all orders. Each item that is added either
> has £1.00 added on if the type is type "a" or £0.50 if the type is type
"b".
>
> Each product in my products table in the database has a Type defined in a
> field called "type".
>
>  What I have been trying to do is, using php, pull all the "type" fields
> from the products table for all the selected products in the user's
basket,
> and then use an if statement to say "If the type is 'a', add £1.00 and if
> the type is 'b', add £0.50" however it has not been going to plan, the
> shipping always is just the base rate + any type 'a' products.
>
> Is there a better way to do it other than using an if statement? Or is
there
> just a better way to use an if statement?
>
> Thanks for your ongoing help,
> Dave Stevens
> --
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !
>
> --
> For unsubscribe and other options, including
> the Tip Harvester and archive of thelist go to:
> http://lists.evolt.org Workers of the Web, evolt !




More information about the thelist mailing list