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? 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' ) 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. 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
Archived
This topic is now archived and is closed to further replies.