kpowning;10913999 wrote:I'm trying to input each color, size and quantity into my database for each product. PLEASE HELP.
I'm not familiar with cvs files, but if I understand correctly (and I could be wrong here), I would separate all those items into arrays and go from there by doing:
$str = 'Pink/Black -:- XL ~ 0;Red/Black -:- S ~ 0;Red/Black -:- M ~ 0;Red/Black -:- L ~ 0;Red/Black -:- XL ~ 1975;Pink/Black -:- M ~ 0;Pink/Black -:- S ~ 0;Pink/Black -:- L ~ 0';
preg_match_all('#(.+?) -:- (.+?) ~ ([^;]+);#', $str, $matches);
echo '<pre>'.print_r($matches[1],true); // colour multi-dimensional array
echo '<pre>'.print_r($matches[2],true); // size array
echo '<pre>'.print_r($matches[3],true); // quantity array
Granted, if you keep the colour pairs as what currently $matches[1] holds (say: Pink/Black for example), then this violates 1st normal form of databases (as all values should be atomic).
So we can rewrite the above snippet so that we can separate $matches[1] into a multi-dimensional array, each element containing each colour:
$str = 'Pink/Black -:- XL ~ 0;Red/Black -:- S ~ 0;Red/Black -:- M ~ 0;Red/Black -:- L ~ 0;Red/Black -:- XL ~ 1975;Pink/Black -:- M ~ 0;Pink/Black -:- S ~ 0;Pink/Black -:- L ~ 0';
preg_match_all('#(.+?) -:- (.+?) ~ ([^;]+);#', $str, $matches);
foreach($matches[1] as $val){
$subColour = explode('/', $val);
$colourArray[] = array($subColour[0],$subColour[1]);
}
echo '<pre>'.print_r($colourArray,true); // colour multi-dimensional array
echo '<pre>'.print_r($matches[2],true); // size array
echo '<pre>'.print_r($matches[3],true); // quantity array
Is that along the lines of what you are looking for?