Jump to content
YePix

value output

Recommended Posts

Hello everyone, how can I output this value 0: 0.50 from the database as 0.50 on the product page?

Share this post


Link to post
Share on other sites
Posted (edited)

What kind of data is this in the database? Is it a string (TEXT, etc.)? Is its format consistent, or is it something that could vary quite a bit?

By the way, a question like this belongs in PHP / SQL / Web Design.

Edited by MrPhil

If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozenpatches or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

There are values for shipping costs. 0 stands for the weight and 0.50 is the price. It's just about spending the price.

Share this post


Link to post
Share on other sites

Well, you didn't answer my question about the data type, but I'll assume this is for table (weight) shipping cost, so it would be a string in PHP. The more general case would be $table_list being a string of comma-separated fields, each max_weight:cost. The following would split up this long list $table_list into two numbers per entry: $max_weight and $cost.

$entries = explode(',', $table_list);
foreach ($entries as $entry) {
    ($max_weight, $cost) = explode(':', $entry);
    // do what you want with this weight and cost
}

I didn't get fancy and try to split it with preg_split(), because there might be spaces at both the commas and the colons. You'll have to trim off any leading and trailing spaces around the number, if you want pretty formatting. If all you have is the $entry, as in your first post, the explode(':', $entry) line would do the job.


If you are running the "official" osC 2.3.4 or 2.3.4.1 download, your installation is obsolete! Get (stable) Frozenpatches or (unstable) Edge. See also the naming convention and the latest community-supported responsive "Edge" release

Share this post


Link to post
Share on other sites

Thanks, i solved it as follows

$insel_cost = explode ("/[:,]/", $shipzones['insel_fee']);
foreach ($insel_cost as $cost);

 

Share this post


Link to post
Share on other sites
Posted (edited)

The resolution from @MrPhil is very good. Clear and effective!!!

@YePix

Your explode isn't right. You don't need an start or an end tag.
I recommand you shoul read here https://www.php.net/manual/en/function.explode.php

 

Edited by mcmannehan

  • The clever one learn from everything and from everybody
  • The normal one learn from his experience
  • The silly one knows everything better

[socrates, 412 before Christ]

Computers help us with the problems we wouldn't have without them!
99.9% of the bugs sit in front of the computer!
My programmed add-ons: WDW EasyTabs 1.0.3, WDW Facebook Like 1.0.0

if(isset($this) || !isset($this)){ // that's the question...

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×