So heres what Ive got so far. I have attached some table sql data for you to play with.
The problem with this code is
- Its not getting the new path for 2,3,4th level concatenated values.
<?php
mysql_connect("localhost", "xxxxx", "xxxxx") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("xxxxx") or die(mysql_error());
echo "Connected to Database <br/><br/><br/><br/>";
//DB Cleanup
//mysql_query("UPDATE `zzz_CWR_itemToPath` SET CWR_item_path = replace(CWR_item_path,', ',' ');");
//printf("Items Modified: %d\
", mysql_affected_rows());
//echo "<BR />";
$query="SELECT * FROM zzz_CWR_itemToPath LIMIT 4000,600";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result)){
$indivPath = explode(",", $row['CWR_item_path']);
$numPaths = count($indivPath);
//if ($numPaths>3){
echo "<BR />" . $row['CWR_item_ID']. " - ". $row['CWR_item_path']."<BR />";
for ($i = 0; $i < count($indivPath); $i++){
$pathNum = $i;
echo 'Path: ' . ++$pathNum . ' - ' . $indivPath[$i] ;
$query2='SELECT `QMS_Categories` FROM `zzz_CWR-QMS_catMapping` WHERE `CWR_Categories` ="'.$indivPath[$i].'"';
$result2 = mysql_query($query2) or die(mysql_error());
if(mysql_num_rows($result2) > 0) {
while($row2 = mysql_fetch_array($result2)){
echo " New Path: ".$row2[$i]."<BR />";
}
} else {
echo "---------------- No New Path Available -----------------------<BR />";
}
}
}
?>
and heres some data to plug in if you want to test.
CREATE TABLE IF NOT EXISTS `zzz_CWR_itemToPath` (
`Product to` text NOT NULL,
`Product Path to` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `zzz_CWR_itemToPath` (`CWR_item_ID`, `CWR_item_path`) VALUES
('31971','Boat Outfitting | Accessories'),
('13528','Boat Outfitting | Display Mounts,Entertainment | Accessories'),
('39745','Boat Outfitting | Trolling Motors,Boat Outfitting | Anchors/Chain/Rope'),
('37185','Winterizing | Winter Covers,Boat Outfitting | Winter Covers');
CREATE TABLE IF NOT EXISTS `zzz_CWR-QMS_catMapping` (
`QMS Categories` text NOT NULL,
`CWR Categories` text NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
INSERT INTO `zzz_CWR-QMS_catMapping` (`QMS_Categories`, `CWR_Categories`) VALUES
('Accessories|Boat Outfitting Accessories','Boat Outfitting | Accessories'),
('Entertainment|Accessories','Entertainment | Accessories'),
('Anchor & Docking|Anchors/Chain/Rope','Boat Outfitting | Anchors/Chain/Rope'),
('Trolling Motors','Boat Outfitting | Trolling Motors'),
('Electronics|Electronics & Antennas|Display Mounts','Boat Outfitting | Display Mounts'),
('Winterizing|Winter Covers','Boat Outfitting | Winter Covers'),
('Winterizing|Winter Covers','Winterizing | Winter Covers');
Let me know if you see anything obvious.