Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
C0D4681387yOh my eyes, the blood is pouring out.
At least shove json in there if your going to do that kind of satanic crap. -
Tobyvw6987yI wish I could say otherwise, but that nothing. I was doing some work on a cash register. Old receipts were stored in the database... In the following manner in a single column
HP 250€ 449,001€ 449,00Logitech M220€ 14.2€ 28.003.5mm to 6.5mm jack€0.52 €1Wireless adapter€320 €60
Which was actually a list of
1 HP 250 @€449,00 subtotal: €449,00
2 Logitech M220 @€14 sub: €28,00
2 3.5>6.5mm jack @ €0.5 sub: €1,00
20 Wireless adapter@€3 sub: €60
You couldn't even regex the shit out of it. There has to be some kind of validation
Eg:
221 is that 1 time €22 or is that 21 times €2, you could only see by the subtotal.
It was hell. -
cursee171597yIf that is what I think it is, RIP op. It might be easier to start from scratch 😀
-
Nothing wrong with that. Its a row containing a array/list. If you know the amount of items in such a list, its easy to create a column for each item. However, if you don't know - for example, number of items in a receipt, its better to do like in OP's post.
However, for receipts its better to use like:
Item_amounts = "2,1,2"
item_names = "bread,butter,salami"
item_prices = "2,1.5,2.5"
Which would be equvalient of:
2 pcs of Bread for 2$ each = 4$
1 pcs of Butter for 1.5$ each = 1.5$
2 pcs of Salami for 2.5$ each = 5$
Total: 10.5$
Its however important to use a sensible delimiter AND filter input from any occurences of delimiter. -
Tobyvw6987y@sebastian yes, that's what I'm trying to say, there was no delimiter.only thing you could hope was that the subtotal had 2 decimals, and if not that the next item didn't start with a number.
Needless to say, there is json in that column now -
@sebastian Yeah, I've had to do something similar to the picture. My system tracks certain events which might contain an arbitrary amount of subevents. Most concise way is to store like OP, or use "field_name" and "field_value" along with some sort of unique identifier. Not very readable in database though.
Related Rants
Please use normalization. Don't store more than is intended in one field and use special characters to separate things. It would make future developers job easy.
rant
phpmyadmin
db design
php
mysql
database