Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

php/mysql problem

0 views
Skip to first unread message

R. Gregg Reed

unread,
Mar 15, 2003, 7:13:21 PM3/15/03
to
I'm trying to learn php/mysql while configuring an open source php
shopping cart. Most of the time I can figure out what I need to do
but this one has got me stumped.

The original code allowed you to enter a number and two decimal
places, then would assign a currency symbol depending on how you set
the default currency, like if you entered 129.99 with $ as the
default currency, the price would display as $129.99, and the program
would treat it as USD for conversion purposes. Same with euros.

I changed it so that you could enter a currency symbol in the
database along with the price, so you could have different products
displayed with different currencies on the same page. Instead of all
prices being either euros or dollars, now you can have some prices in
euros, and some in dollars displayed together.

This brings me to my problem. Before, you could easily convert prices
from one currency to another. If the default currency was dollars,
and you chose euros, all the prices would be converted from dollars
to euros. Now different currencies are on the same page. Even though
some prices are in euros, all prices are treated as the default
currency, so if you chose to display prices in pesos, all prices
would be converted from dollars to pesos, regardless of the currency
symbol in front of it.

What I would like to do is change the code so that it looks at the
first character in the database field to determine what the currency
is, rather than assuming the currency is the default. Something like
"If the first character is $, then treat the numbers in this field
like dollars, or if the first character is €, treat the numbers in
this field like euros."

Can anyone give me a clue how to do this? Thanks.


----== Posted via Newsfeed.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeed.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= 19 East/West-Coast Specialized Servers - Total Privacy via Encryption =---

PoDuck

unread,
Mar 16, 2003, 2:22:18 AM3/16/03
to
www.php.net/substr

that's the substr command, and you would use it with a switch to get it to
do different things for different currency.

$firstchar = substr( $foo, 0, 1 );
switch ( $firstchar )
{
case '$': do this;
break;
case '?': do this;
break;
default: do this;
}

Anyway, that should get it for you.

"R. Gregg Reed" <re...@cetlink.net> wrote in message
news:Xns933FC7A966DD...@198.87.234.3...

> like dollars, or if the first character is ?, treat the numbers in

R. Gregg Reed

unread,
Mar 16, 2003, 2:56:29 PM3/16/03
to
"PoDuck" <sa...@clause.net> wrote in
news:v789hcs...@corp.supernews.com:

> www.php.net/substr
>
> that's the substr command, and you would use it with a switch to
get
> it to do different things for different currency.
>
> $firstchar = substr( $foo, 0, 1 );
> switch ( $firstchar )
> {
> case '$': do this;
> break;
> case '?': do this;
> break;
> default: do this;
> }
>
> Anyway, that should get it for you.
>

Thanks. That's exactly what I needed.

Gregg

0 new messages