Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

value output


YePix

Recommended Posts

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.

Link to comment
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.

Link to comment
Share on other sites

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

 

  • 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...

 

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...