0

How do i retrieve information from a database and display certain information as the first option in a menu among other options. I want to edit information in a database using the menu like:

        <select name="items" id="items" >

        <?php
        while($product_rows=mysql_fetch_assoc($productSQL)){ ?>
                 <option value="<?php echo $ord_rows['pid'];?>">
                    <?php echo $ord_rows['name'];?>
                 </option>
        <?php } ?>

        </select> 

but this jst gets all the options from the db. I want the option am editing to appear as the first one and the rest follow, Any help, hope the question is clear.

Gaurav
  • 28,447
  • 8
  • 50
  • 80
John
  • 105
  • 4
  • 12
  • make it clear with an example. – Gaurav Feb 17 '11 at 06:59
  • I just can't believe that in 2011 there's still people a) using the old MySQL extension b) mixing MySQL code with HTML. The best help I possibly can give you is that you are doing it 100% wrong and you need to seriously look at frameworks and such. – chx Feb 18 '11 at 12:46
  • [**Please, don't use `mysql_*` functions in new code**](http://bit.ly/phpmsql). They are no longer maintained [and are officially deprecated](https://wiki.php.net/rfc/mysql_deprecation). See the [**red box**](http://j.mp/Te9zIL)? Learn about [*prepared statements*](http://j.mp/T9hLWi) instead, and use [PDO](http://php.net/pdo) or [MySQLi](http://php.net/mysqli) - [this article](http://j.mp/QEx8IB) will help you decide which. If you choose PDO, [here is a good tutorial](http://stackoverflow.com/a/14110189/1723893). – NullPoiиteя Jan 06 '13 at 09:02

1 Answers1

0

Without knowing what your query is, it's impossible to tell what this while loop will produce, can you include it? I would expect to see something like this;

     <select name="items" id="items" >
<?php

$query = "SELECT pid, name FROM products";

    $result = mysql_query($query);

    while ($product_rows = mysql_fetch_assoc($result)){

    ?> <option value="<?php echo $product_rows['pid'];?>">
                    <?php echo $product_rows['name'];?>
                 </option>

   <?php } ?>
</select>
charliefortune
  • 3,072
  • 5
  • 28
  • 48