SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    populating a drop down menu

    I tried this a buttload of ways & can't get it to work.

    Here's the deal, I've got it working on another page where the page pops in & out of php & the page i'm working on now really can't do that.

    Here's the code that works when it pops in & out of php:

    PHP Code:
            <select name="playercharactor" size="1">
              <option<?=(!$playercharactor) ? " selected" ""?>>Choose Charactor</option>
              <option value="Sniper"<?=($playercharactor == "Sniper") ? " selected" ""?>>Sniper</option>
              <option value="Gunner"<?=($playercharactor == "Gunner") ? " selected" ""?>>Gunner</option>
              <option value="Aquadic Medic"<?=($playercharactor == "Aquadic Medic") ? " selected" ""?>>Aquadic 
              Medic</option>
              <option value="Granadier"<?=($playercharactor == "Granadier") ? " selected" ""?>>Granadier</option>
              <option value="Close Quarters Combat"<?=($playercharactor == "Close Quarters Combat") ? " selected" ""?>>Close 
              Quarters Combat</option>
            </select>
    Here's the one where the whole page is in php & wont work:
    [VBS] <select name=\"activated\">
    <option =(!$activated) ? \" selected\" : \"\"> </option>
    <option value=\"Yes\" =($activated== \"Yes\") ? \" selected\" : \"\">Yes</option>
    <option value=\"No\" =($activated== \"No\") ? \" selected\" : \"\">No</option>
    </select>
    [/VBS]

    Can you help me out as to whats wrong?

    TIA
    Last edited by whofarted; Dec 22, 2001 at 06:05.
    You smell something?

  2. #2
    SitePoint Enthusiast Cabbage's Avatar
    Join Date
    Jun 2001
    Location
    New Jersey
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    put the choices in a database

    i'd probably do something like this
    make a table called playercharactor
    with 2 fields
    pc_id
    player

    populate the table like this:
    pc_id player
    1 Sniper
    2 Gunner
    3 Aquadic Medic
    4 Granadier
    5 Close Quarters Combat

    then the PHP to make the drop down would be this:
    <select name="sections" size="1">
    <?php
    $sql = mysql_query("SELECT * FROM playercharactor");
    while ( $rowsql = mysql_fetch_array($sql) )
    {
    extract($rowsql);
    echo("<OPTION VALUE='$pc_id'>$player\n");
    }
    ?>
    </select>
    ~Cabbage
    http://www.jimmieschickenshack.net
    want to trade live recordings? JCS, Smashing Pumpkins, Local H, Toadies

  3. #3
    Custom User Title v1.0 FireFly's Avatar
    Join Date
    Aug 2001
    Posts
    363
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is what you need:
    Code:
    echo "        <select name=\"activated\">
              <option".(!$activated ? " selected" : "")."> </option>
              <option value=\"Yes\"".($activated=="Yes" ? " selected" : "").">Yes</option>
              <option value=\"No\"".($activated=="No" ? " selected" : "").">No</option>
            </select>";
    When you move things into PHP code you don't just slash all the "'s, some are needed for the actual code.
    Only "'s that you output you slash, not all of them.
    Also you need to use the . operator, for example:
    Code:
    <?php
    echo "Hi" . $name . " welcome!";
    ?>

  4. #4
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks Firefly, it works now


    Thanks to you 2 for trying Cabbage, but the one you tried to fix for me was the one I said worked lol. I was using that one as my example.
    You smell something?

  5. #5
    SitePoint Enthusiast Cabbage's Avatar
    Join Date
    Jun 2001
    Location
    New Jersey
    Posts
    36
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh figures
    ~Cabbage
    http://www.jimmieschickenshack.net
    want to trade live recordings? JCS, Smashing Pumpkins, Local H, Toadies

  6. #6
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Actually thanks you 2 because you did give an example of my next question, how to populate a drop down menu with info in the databsae.

    See all was not lost!
    You smell something?


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
  •