Select the option from a Combo box

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
rajkumar_pb
Forum Newbie
Posts: 6
Joined: Mon Oct 26, 2009 1:45 am

Select the option from a Combo box

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: Select the option from a Combo box

Post 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
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
rajkumar_pb
Forum Newbie
Posts: 6
Joined: Mon Oct 26, 2009 1:45 am

Re: Select the option from a Combo box

Post 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
Post Reply