Issue in displaying value of select field in table column

this is my select field in form

                             <select class="form-control" id="fruits" name="fruits" type="text">
                                       <option value = '0'>-Select-</option>
                                       <option value = '1'>Apple</option>  
                                       <option value = '2'>Orange</option>

This is how I am trying to get the values

                 $conn = mysqli_connect("localhost", "root", ""); // Establishing Connection with Server..
                $db = mysqli_select_db($conn,"basket");
                $list= mysqli_query($conn,"SELECT fruits from tbl_shop_A");
                 $row = $list->fetch_object()

// display names but as the values are storing in databse as option values they are displaying in table also as option value

       <th><?php echo $row->fruits; ?></th>

i.e. <th> 2 </th>

The values are storing in database as option values i.e 1, 2

  • but I want to display it in table according to their names i.e. orange , apple
    How to do that ?

Well, ask yourself this - why are you giving them values of 0,1,2?

Also there’s no way you’re calling this line:
$row = mysqli_query($conn,"SELECT fruits from tbl_shop_A");
followed by this one
<php echo $row->medium; ?>;
because you haven’t selected anything called ‘medium’ in your query. Also $row isnt a row. It’s the query result. You’ll have to get your values out of it (fetch, fetch_array, etc) somehow.

So show us the actual code you’re trying to debug.

1 Like

hey Sorry for the mistake now I have updated my code please guide me through it

I see form HTML and the SELECT query code. If the SELECT is returning numeric values from the “fruits” field of the “tbl_shop_A” table it suggests that field contains numeric values.

What has not been shown is how the value attribute values from the <option> elements are getting into those table fields.

Can you post the code related to the INSERT (and UPDATE if there is one) query?

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.