Monkuar Posted January 28, 2012 Share Posted January 28, 2012 Does storing multiple values in 1 database field with a varchar let's say set at 150, all separated by "|'s" so I don't have to create a field name for each one is it better performance wise or no? (storing 6-7 different |'s that will be outputted with a array ofc) ? Quote Link to comment https://forums.phpfreaks.com/topic/255922-quick-question/ Share on other sites More sharing options...
trq Posted January 28, 2012 Share Posted January 28, 2012 Storing data in a comma separated fashion within a database is generally a bad approach. It makes searching your data for more difficult. Quote Link to comment https://forums.phpfreaks.com/topic/255922-quick-question/#findComment-1311893 Share on other sites More sharing options...
Monkuar Posted January 28, 2012 Author Share Posted January 28, 2012 Storing data in a comma separated fashion within a database is generally a bad approach. It makes searching your data for more difficult. this data will not be searched though, (didn't point that out, my fault) here is a s/s of what the data looks like that is being called This way would be better instead of adding 8 more rows to call each | data right? See, i would have to add like 12 more fields just to get the data I want to pull out, but doing it this way it's alot simpler to me (IMO) These is the board's main stats (it's being called whenever sum1 visit's the board forum index) it should be fine? there both varchar's (100) Quote Link to comment https://forums.phpfreaks.com/topic/255922-quick-question/#findComment-1311902 Share on other sites More sharing options...
Proletarian Posted January 28, 2012 Share Posted January 28, 2012 The thing is, you're making this way more complicated than it really needs to be. If you would start putting your variables in arrays, instead of all your variables in one string, you won't need to find all your variables in that string when you need them and you can easily piece them into an output string when you do need to show them. This also means you can easily store each variable into a database via a loop so that the integrity of the data is maintained while storing, retrieving, and updating them. Your database could look like this: [ticket] - [choice 1] - [choice 2] - [choice 3] - [choice 4] - [choice 5] - [choice 6] - [choice 7] Which is easily translated into an array: ticket[choice 1] = 100 ticket[choice 2] = 200 ticket[choice 3] = etc, etc. Which is easily parsed into a string: for x { string .= ticket[x] } Which is also easily inserted and retrieved from a database: for x { insert ticket[x] into table } for x { ticket[x] = (get player.ticket[x] from table) } Try it out. You'll be amazed at how much your creativity can be focused on productivity rather than trying to reinvent the wheel. Quote Link to comment https://forums.phpfreaks.com/topic/255922-quick-question/#findComment-1311906 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.