0

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..

Edited by sami.asanga: n/a

2
Contributors
3
Replies
5
Views
6 Years
Discussion Span
Last Post by metalix
0

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
?>
0

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.

0

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"

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.