Ok long time coder, first time stuck ( I think due to not seeing the woods through the trees!)
any how I have data being returned in an array. When foreached out one of the data fields is the part number.
As an example the data set looks like this (I've removed some as it repeats)
[1] => Array
(
[id] => 1628
[partnum] => 02030200104bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS400 4 BLACK D RING CHUKKA PAD COLLAR PUDD SOLE STEEL TOEandMID S1P STES
[is_over] => 0
[price] => 1
[image] => 1717-1727
[location] =>
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[2] => Array
(
[id] => 1629
[partnum] => 02030200105bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS400 5 BLACK D RING CHUKKA PAD COLLAR PUDD SOLE STEEL TOEandMID S1P STES
[is_over] => 0
[price] => 1
[image] => 1717-1727
[location] =>
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[3] => Array
(
[id] => 1630
[partnum] => 02030200106bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS400 6 BLACK D RING CHUKKA PAD COLLAR PUDD SOLE STEEL TOEandMID S1P STES
[is_over] => 0
[price] => 1
[image] => 1717-1727
[location] =>
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[11] => Array
(
[id] => 1638
[partnum] => 02030200205bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS609 5 BLACK PAD COLLAR/TONGUE PU DD SOLE STEEL TOECAP and MIDSOLE S3 STES
[is_over] => 0
[price] => 1
[image] => 1728-1735
[location] => C36
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] => 5 6 7 8 9 10 11 12
[ass_prod] =>
)
[12] => Array
(
[id] => 1639
[partnum] => 02030200206bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS609 6 BLACK PAD COLLAR/TONGUE PU DD SOLE STEEL TOECAP and MIDSOLE S3 STES
[is_over] => 0
[price] => 1
[image] => 1728-1735
[location] => C36
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[13] => Array
(
[id] => 1640
[partnum] => 02030200207bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS609 7 BLACK PAD COLLAR/TONGUE PU DD SOLE STEEL TOECAP and MIDSOLE S3 STES
[is_over] => 0
[price] => 1
[image] => 1728-1735
[location] => C36
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[14] => Array
(
[id] => 1641
[partnum] => 02030200208bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS609 8 BLACK PAD COLLAR/TONGUE PU DD SOLE STEEL TOECAP and MIDSOLE S3 STES
[is_over] => 0
[price] => 1
[image] => 1728-1735
[location] => C36
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[13] => Array
(
[id] => 1640
[partnum] => 02030200207bla
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS609 7 BLACK PAD COLLAR/TONGUE PU DD SOLE STEEL TOECAP and MIDSOLE S3 STES
[is_over] => 0
[price] => 1
[image] => 1728-1735
[location] => C36
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
[15] => Array
(
[id] => 1642
[partnum] => 02030200108yel
[cat] => PPE
[class] => FOOT PROTECTION
[subcat] => BOOTS
[name] => BOOT SS400 8 YELLOW D RING CHUKKA PAD COLLAR PUDD SOLE STEEL TOEandMID S1P STES
[is_over] => 0
[price] => 1
[image] => 1728-1735
[location] => C36
[purchase] => 1
[hire] => 0
[hide] => 0
[hasother] => 0
[name_soundex] =>
[options] =>
[ass_prod] =>
)
)
The first 9 characters are the product code so i do
$thisval = substr($t['partnum'], 0, 9);
and the next 2 characters are the size
$thissize = substr($t['partnum'], 9, 2);
and the last 3 characters are the colour
$thissize = substr($t['partnum'], 11, 3);
All i need to do is if the first 9 characters match, create a select for each of the last 2 characters where the first nine match, so they all appear in the dropdown as a selectable size and it takes the last 3 characters and makes them selectable colours
If a new 9 characters comes along, it takes that and starts a new one . . . ?
So you would end up like you would on a store with an item and a colour and a size selector
From the above data I'd be looking for 2 items, one with a size selector and a colour selector with black and yellow and one with a size selector and a colour selector of just black.
Any help would be great!
I'm thinking it should work like
If(is_array($products)){
$check="";
foreach($products as $key => $p){
$substring1 = substr($p['partnum'], 9,2);
$nexttwo = substr($p['partnum'],9,2);
If($check == $substring1){
}else{
If(is_array($products){
Foreach($products as $key => $t){
$substring2 = substr($t['partnum'], 9,2);
$nexttwo2 = substr($t['partnum'],9,2);
If($substring1 != $substring2){
Echo "<li>" . $p['itemname'] . "<ul>";
}else{
If($substring1 == $substring2){
Echo "<li>". $nexttwo2."</li>;
}else{
Echo "</ul>";
}
}
</li>
$check = $substring1;
}
}
}