SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    A simple dropdown question

    Hi all,
    I have drop down populated from database table, which is working fine.
    I want to add another value to the drop down, but not from table. Which will be called "All", i can do that from table. But i don't want that. Just want to add it statically.
    Any ideas...

    Here is the code:

    PHP Code:
    <select name='id'>
    <?php
    $sql 
    mysql_query("select * from table where code='sm' order by id asc");
    while(
    $row mysql_fetch_object($sql)){
    if(
    $id == $row->id){ 
    echo 
    "<option value='$row->id' selected='selected'>$row->id</option>";
    }
    else
    {
    echo 
    "<option value='$row->id'>$row->id</option>";
    }
    }
    ?>
    </select>
    Thanks.

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    5 Thread(s)
    PHP Code:
    <select name='id'>
        <option value="0">All</option>
    <?php
    $sql 
    mysql_query('select * from table where code=\'sm\' order by id asc');
    while(
    $row mysql_fetch_object($sql)) {
         echo 
    '<option value=',$row->id,'',($id == $row->id?' selected=" selected"':''),'>',$row->id,'</option>';
    }
    ?>

  3. #3
    SitePoint Guru mmarif4u's Avatar
    Join Date
    Dec 2006
    Location
    /dev/swat
    Posts
    619
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gr8.
    Thanks oddz.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •