okay, I know that everyone has their own coding style, but I think you may be bordering on abuse!!! 🙂
I must say, it would probably make a lot more sence to me if I had some clue what you were doing, but here is my shot at helping you 🙂
My test case
<?
/*$sql = "select special_prod_list from cart_special_products where special_prod_id='".$_GET['special_prod_id']."'";
$sql_result = mysql_query($sql) or die ("Could not select data");*/
/*while ($row = mysql_fetch_array($sql_result))
{
$special_prod_list = $row['special_prod_list']; //do you relize you are overwriting your var each loop?
}*/
$special_prod_list = "1,2:3,4:5,6:7,8"; //remove me!
$explode_1 = explode(":", $special_prod_list);
foreach ($explode_1 as $v){
$cool = explode(",", $v);
$aaa[] = $cool[0];
$bbb[] = $cool[1];
}
echo "TEST: ".$aaa[0]." / ".$bbb[0]."<BR>";
echo "TEST: ".$aaa[1]." / ".$bbb[1]."<BR>";
echo "TEST: ".$aaa[2]." / ".$bbb[2]."<BR>";
echo "TEST: ".$aaa[3]." / ".$bbb[3]."<BR>";
$ii = 0;
/*$sql = "select * from cart_products";
$sql_result = mysql_query($sql) or die ("Could not select data");
while ($row = mysql_fetch_array($sql_result)){
$prod_id = $row['prod_id'];
$prod_name = stripslashes($row['prod_name']);*/
$prod_name = "that"; //remove me
$prod_id = 3; //remove me!
echo "<tr ";
if(in_array($prod_id, $aaa))echo "style='background-color:#CCCCCC'";
echo ">
<td><input name='special_check[$ii-1]' type='checkbox' value='$prod_id' ";
if(in_array($prod_id, $aaa))echo 'checked';
echo "onClick=\"enableField('special_check[$ii-1]','special_select[$ii-1]')\"></td>
<td nowrap>$prod_name</td>
<td width='100%'></td>
<td align='right'>
QTY:
<select name='special_select[$ii-1]' style='font-size:10px' ";
if(!in_array($prod_id, $aaa)) echo 'disabled';
echo ">";
for($count = 1; $count <= 12; $count++)
{
echo "<option value='$count' ";
// THIS IS WHERE THE PROBLEM IS
if(in_array($count, $bbb)) echo 'selected';
echo ">$count";
}
echo "
</select>
</td>
</tr>";
$ii++;
/*}*/
My html output
TEST: 1 / 2<BR>TEST: 3 / 4<BR>TEST: 5 / 6<BR>TEST: 7 / 8<BR><tr style='background-color:#CCCCCC'>
<td><input name='special_check[0-1]' type='checkbox' value='3' checkedonClick="enableField('special_check[0-1]','special_select[0-1]')"></td>
<td nowrap>that</td>
<td width='100%'></td>
<td align='right'>
QTY:
<select name='special_select[0-1]' style='font-size:10px' ><option value='1' >1<option value='2' selected>2<option value='3' >3<option value='4' selected>4<option value='5' >5<option value='6' selected>6<option value='7' >7<option value='8' selected>8<option value='9' >9<option value='10' >10<option value='11' >11<option value='12' >12
</select>
</td>
</tr>
notice that there are a number of selects? when this happens the browser should select the last one, I don't know if the rest of your code prevents this from ever happining, but if not, this is bad code.
maybe what you are looking for?
<?
$sql = "select special_prod_list from cart_special_products where special_prod_id='".$_GET['special_prod_id']."'";
$sql_result = mysql_query($sql) or die ("Could not select data");
while ($row = mysql_fetch_array($sql_result))
{
$special_prod_list = $row['special_prod_list']; //do you relize you are overwriting your var each loop?
}
$explode_1 = explode(":", $special_prod_list);
foreach ($explode_1 as $v){
$cool = explode(",", $v);
$aaa[] = $cool[0];
$bbb[] = $cool[1];
}
echo "TEST: ".$aaa[0]." / ".$bbb[0]."<BR>";
echo "TEST: ".$aaa[1]." / ".$bbb[1]."<BR>";
echo "TEST: ".$aaa[2]." / ".$bbb[2]."<BR>";
echo "TEST: ".$aaa[3]." / ".$bbb[3]."<BR>";
$ii = 0;
$sql = "select * from cart_products";
$sql_result = mysql_query($sql) or die ("Could not select data");
while ($row = mysql_fetch_array($sql_result)){
$prod_id = $row['prod_id'];
$prod_name = stripslashes($row['prod_name']);
echo "<tr ";
if(in_array($prod_id, $aaa))echo "style='background-color:#CCCCCC'";
echo ">
<td><input name='special_check[$ii-1]' type='checkbox' value='$prod_id' ";
if(in_array($prod_id, $aaa))echo 'checked';
echo "onClick=\"enableField('special_check[$ii-1]','special_select[$ii-1]')\"></td>
<td nowrap>$prod_name</td>
<td width='100%'></td>
<td align='right'>
QTY:
<select name='special_select[$ii-1]' style='font-size:10px' ";
if(!in_array($prod_id, $aaa)) echo 'disabled';
echo ">";
for($count = 1; $count <= 12; $count++)
{
echo "<option value='$count' ";
// THIS IS WHERE THE PROBLEM IS
if(in_array($count, $bbb)) echo 'selected';
echo ">$count";
}
echo "
</select>
</td>
</tr>";
$ii++;
}
not sure if that was any help... if not, could you give us an example of what a special_prod_list and * from cart_products would be?