MDanz Posted May 21, 2011 Share Posted May 21, 2011 Is a comma seperated list in a column in Mysql good practice? or should i just loop the INSERT clause... so each value has it's own row? Quote Link to comment https://forums.phpfreaks.com/topic/237025-comma-seperated-list-in-a-column-in-mysql/ Share on other sites More sharing options...
Pikachu2000 Posted May 21, 2011 Share Posted May 21, 2011 Well, neither really is the best option. Build the query string in a loop, then run the query once. Running a query in a loop should always be avoided when possible. $array = explode( ',', 'one,two,three,four,five'); $values = implode( "' ), ( '", $csv ); $query = "INSERT INTO table (field) VALUES ( '$values' )"; $result = mysql_query($query) etcetera . . . echo $query returns: INSERT INTO table (field) VALUES ( 'one' ), ( 'two' ), ( 'three' ), ( 'four' ), ( 'five' ) Quote Link to comment https://forums.phpfreaks.com/topic/237025-comma-seperated-list-in-a-column-in-mysql/#findComment-1218311 Share on other sites More sharing options...
The Little Guy Posted May 25, 2011 Share Posted May 25, 2011 Is a comma seperated list in a column in Mysql good practice? That is horrible practice. I say one value = one row. You can find data hell of a ton easier than with comma separated values. It also is easier to match two columns from 2+ tables. Quote Link to comment https://forums.phpfreaks.com/topic/237025-comma-seperated-list-in-a-column-in-mysql/#findComment-1220107 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.