SwanseaMick wrote:Further to my previous posts, I discovered a drawback in getting MySQL to include the £ in the returned result! Although the resulting page looks 'pretty', one cannot sum the different results to get a grand total, as the individual totals are regarded as strings, and the sum of their results is '0' (zero)!
Goes to show, some you win, some you lose!
Its always best to represent things as their "natural" data types, so currency should be a decimal, a yes/no choice would be a tinyint (effectively a boolean) and do all your formatting in the output layer. A String is really a very generic type and while you can manipulate them in a lot of ways its not a suitable way to store numeric data. The other problem is that its bad programming practice where you should be trying to separate the data, logic and presentation layers. So in this case your data is in MySQL and the logic and presentation are in PHP. However in that PHP you should have the logic in a different class to your HTML. This lets you in the future switch things around more easily.
In your case you found you wanted to do some sums on your data that you can't do easily with it as a string. An example that I've just come across was I was trying to get my Pi to output data to a 16x2 display however it wasn't working. I had a suspicion it was due to the slow GPIO library I was using thankfully though I had used interfaces to give me some separation and so to use a new library I just wrote one new file for the new library and changed a couple of words and I was up and running with the new interface that worked. If I hadn't then I would of had to rewrite all my bits of code in all my classes that used the GPIO.