Hi,

I need to get the itemId's from the Database to a combo box where the combo box will increase according to the new values.

I wrote a code like this

<select name="catId">
                        <?php
                          //get category id from the database 
                            $sql = "SELECT cat_id FROM tbl_category ORDER BY cat_id";
                            $result = mysql_query($sql);
                            while($row = mysql_fetch_array($result))
                            {
                                 echo "<option value=\"".$row['cat_id']."\">".$row['cat_id']."</option> \n  ";
                            }
                
                        ?>				    
                      </select>

With that I could have taken the item id and the other necessary values displayed according to the id.But the problem is even though it displayed correct values ,always the item id which is selected is the first one.So I cant do any update with it,because it will update only the 1st record in the DB table since update query is working according to the itemId.How should I change the code to get the correct item id selected with its values displayed in the form where I can edit and update it.

Please help me..

You need to add a WHERE statement to your query
for example if the cat id is called by example.com?catid=14

<?PHP
$catid = $_GET['catid'];
$catid = mysql_real_escape_string($catid);
$sql = "SELECT cat_id FROM tbl_category WHERE cat_id = '$catid'";
//rest of code
?>

No..Its not working..because when we give a where clause in the select statement none of the category id get selected.Just only the combo box will display with out any value.

So reading your problem from a different angle. are you only recieving one result from the db in your first example?
or are you needing selected="selected"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.