YePix Posted April 19, 2019 Posted April 19, 2019 Hello everyone, how can I output this value 0: 0.50 from the database as 0.50 on the product page?
MrPhil Posted April 19, 2019 Posted April 19, 2019 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.
YePix Posted April 19, 2019 Author Posted April 19, 2019 There are values for shipping costs. 0 stands for the weight and 0.50 is the price. It's just about spending the price.
MrPhil Posted April 19, 2019 Posted April 19, 2019 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.
YePix Posted April 20, 2019 Author Posted April 20, 2019 Thanks, i solved it as follows $insel_cost = explode ("/[:,]/", $shipzones['insel_fee']); foreach ($insel_cost as $cost);
mcmannehan Posted April 20, 2019 Posted April 20, 2019 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...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.