SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Enthusiast nosnevel's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Edit form dropdown menu

    Using Kevin Yank's multi-purpose page, I have a form to edit a classified ad. It populates each field with the existing data, thren let's the user change the data and resubmit it to the database. Very straightforward.

    Only problem is that the category field is a dropdown menu so the editor can change what categroy the ad is post into. The way things are now, this means that the original category, pulled from the database, is never displayed. How can I have apulldown to select a category, AND have the exisitng category be the selected option?

    Here's the category select code:
    PHP Code:
    <td><select name="cid" size="1" />
              <option selected value="">Select One</option>
              <?php
        
    while ($cat mysql_fetch_array($cats)) {
           
    $cid $cat['categoryID'];
           
    $cname $cat['name'];
           echo(
    "<option value='$cid'>$cname</option>\n");
           }
        
    ?>
            </select></td>
    Thanks!
    Larry
    Larry Levenson
    Sigma Web Technologies - Prescott Valley, AZ, USA
    http://www.SigmaWebTechnologies.com

  2. #2
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    $selected = ($cname $current_choice) ? 'SELECTED' '';

    <
    option value='$cid' $selected
    This way if the option value is equal to wahtever the current choice is it will show SELECTED by that choice. You need to get rid of your other "selected" in the first option though.

  3. #3
    SitePoint Enthusiast nosnevel's Avatar
    Join Date
    Aug 2003
    Location
    US
    Posts
    70
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx, Jump! Works perfectly, and more importantly, I learned something.
    Larry Levenson
    Sigma Web Technologies - Prescott Valley, AZ, USA
    http://www.SigmaWebTechnologies.com

  4. #4
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NP I hope you didn't learnt how to spell "wahtever" though.

  5. #5
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Jump
    NP I hope you didn't learnt how to spell "wahtever" though.
    as the Restruant in your 'Location' ?
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.

  6. #6
    Non-Member hyperimage's Avatar
    Join Date
    Dec 2003
    Location
    Croatia
    Posts
    259
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    try this

    PHP Code:
    <?php
    $result 
    mysql_query("select * from  your_table group by name order by id desc"); 
    while(
    $row mysql_fetch_array($result)) { 
    echo 
    "<option value=\"$row[0]\">$row[1]</option>\n"

    mysql_free_result$result ); 
    ?>
    cya

  7. #7
    Now with customized title Jump's Avatar
    Join Date
    Sep 2002
    Location
    The Restaurant at The End of The Universe
    Posts
    1,423
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by frezno
    as the Restruant in your 'Location' ?
    Not sure what you are refering to there. *whistles innocently*

  8. #8
    does not play well with others frezno's Avatar
    Join Date
    Jan 2003
    Location
    Munich, Germany
    Posts
    1,391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nothing in particular
    We are the Borg. Resistance is futile. Prepare to be assimilated.
    I'm Pentium of Borg.Division is futile.Prepare to be approximated.


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
  •