Page 1 of 1

Select the option from a Combo box

Posted: Mon Dec 28, 2009 4:17 am
by rajkumar_pb
This is for editing a record. When the user click the edit button, the id of the record will pass to editin.php page and all the value will retrieve from db and must fill in the form controls. The problem is the values sit properly in text boxes but not in combo boxes. The code i am using is

<?php
while($row = mysql_fetch_array($result))
{
array_push($dd,$row['product_code']);
$temp_pid = $row['product_code'];
echo '<option value='.$row['product_code'].' if($temp_pid == $product_code1) {echo "selected=selected"; } >'.$row['product_code'].'</option>';
}
echo '</select>';
?>

But it doesnt suit me,. Please help me doing this.

Re: Select the option from a Combo box

Posted: Mon Dec 28, 2009 9:48 am
by AbraCadaver
1. You don't have an opening <select>
2. Your IF logic is concatenated as a string so it's a string that is echoed not evaluated as PHP code
3. $product_code1 is never defined anywhere so obviously it will never == $temp_pid

Re: Select the option from a Combo box

Posted: Tue Dec 29, 2009 5:51 am
by rajkumar_pb
AbraCadaver wrote:1. You don't have an opening <select>
This is just a part of the code
AbraCadaver wrote:2. Your IF logic is concatenated as a string so it's a string that is echoed not evaluated as PHP code
I'll change that
AbraCadaver wrote:3. $product_code1 is never defined anywhere so obviously it will never == $temp_pid
Its defined in top of the page