erme Posted January 6, 2010 Share Posted January 6, 2010 Hi, how can I add a 'list' in an SQL database without having to creat lots of individual fields. Many thanks Quote Link to comment https://forums.phpfreaks.com/topic/187482-in-a-database/ Share on other sites More sharing options...
tomdchi Posted January 7, 2010 Share Posted January 7, 2010 I don't think mysql is right for something like that. How could you have a relational database and be able to query against it if it just contains a big list? Quote Link to comment https://forums.phpfreaks.com/topic/187482-in-a-database/#findComment-990160 Share on other sites More sharing options...
Mchl Posted January 7, 2010 Share Posted January 7, 2010 Just what exactly you want to do? Quote Link to comment https://forums.phpfreaks.com/topic/187482-in-a-database/#findComment-990190 Share on other sites More sharing options...
kickstart Posted January 7, 2010 Share Posted January 7, 2010 Hi While I am not a fan of completely splitting the processing and the display of data (they are too related to do it totally), it does appear that you want just use a table field in much the same way you would use a flat file. If you have a table containing rows which you want to display on screen as a list then you could use GROUP_CONCAT in your SQL. However most of the time it would probably be more flexible and maintainable to do the formatting within php. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/187482-in-a-database/#findComment-990217 Share on other sites More sharing options...
erme Posted January 7, 2010 Author Share Posted January 7, 2010 I think i've not explained myself. I dont want to put any 'code' within the database itself. Ideally I'd wanted to put something like this in a field: List Item 1, List Item 2, List Item 3 And then I can format it in the PHP to read as a list List Item 1 List Item 2 List Item 3 There must be a way of doing this, or something similar to this? Or do I have to create hundreds of fields in the table for each List Item? Quote Link to comment https://forums.phpfreaks.com/topic/187482-in-a-database/#findComment-990315 Share on other sites More sharing options...
kickstart Posted January 7, 2010 Share Posted January 7, 2010 Hi Normally depending on the data I would expect the table to contain one row for each of those items. ie, it the list items were children for a parent then there would be one row per child. If you did this then you could either bring back the rows in MySQL and use php to output the <li></li> tags, or you you use GROUP_CONCAT in MySQL to bring them back from the database with most of the tags in place. Having a comma seperated field within a table makes it very difficult to do joins on the data to other tables. All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/187482-in-a-database/#findComment-990427 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.