I have a mysql legacy table which contains an client identifier and a list of items, the latter as a comma-delimited string. E.g. \"xyz001\", \"foo,bar,baz\"
. T
I really wanted to get this to work using SQL but was unable to. I wrote this quick PHP script to do the job.
It's quick and dirty and NOT how I would ever recommend doing production code. But sometimes you do what it takes to get the job done quick.
".mysql_error();
exit;
}
$applications = array();
while($row = mysql_fetch_array($result)){
echo "
".$row[$pri_column];
$topics = explode(",", $row[$column]);
foreach($topics as $topic){
$topic = trim($topic);
$applications[$row[$pri_column]][$topic] = $topic;
}
echo "
".$row[$column];
}
echo "";
print_r($applications);
echo "
";
foreach($applications as $app => $topics){
foreach($topics as $topic){
$query = "insert into ".$newTable." values ('', \"".$app."\", \"".$topic."\")";
echo "
".$query;
mysql_query($query);
if(mysql_errno()){
echo "
".mysql_error();
}
}
}
?>