Jump to content

comma seperated list in a column in Mysql


MDanz

Recommended Posts

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' )

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.