SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: Drop down box

  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question Drop down box

    I want to have a drop down box where a user can choose an address. I got 10 different addresses. Problem with my code now is that its displaying 10 different drop down down boxes instead of displaying 1 with all 10 addresses in. Somebody who can help?

    PHP Code:
     echo'
    <form method="post">
    Sorter etter:<br>
                    <select name="sort" size="1">
                      <option value="test"> '
    .$v_address.' </option>

                    </select>
                    <input type="submit" name="Request" value="OK">
    </form>'


  2. #2
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    if the addresses are in an array you can foreach over the array and output the "<option>" parts of the form
    PHP Code:
    <form method="post">
    Sorter etter:<br>
                    <select name="sort" size="1"> 
    <?php
    foreach($addressArray as $v_address){
      print 
    '<option value="test"> '.$v_address.' </option>'
    }
    ?>
    </select>
                    <input type="submit" name="Request" value="OK">
    </form>
    Erh

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its fetched as object. Can i do something similar then?

  4. #4
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by sirikit
    Its fetched as object. Can i do something similar then?
    Erh..it's early for me...still drinking my coffee...can you explain or show what you mean by "its fethced as object"? Thanks. I'm assuming that we're going to get to the solution easily enough...just not thinking straight right now.
    Erh

  5. #5
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hehe, im having dinner soon

    I have a database with all the addresses stored. So im fetching my database and table as object like this:

    PHP Code:
    $q = "SELECT *, leilighet.leilighetsNr AS lNr FROM leilighet LEFT JOIN leietager ON leietager.leilighetsNr = leilighet.leilighetsNr 
          WHERE leietager.leilighetsNr IS NULL ORDER BY $order LIMIT $from, $max_results"; 
    $result = mysql_query($q, $conn) or die(mysql_error()); 
    while ($row = mysql_fetch_object($result))
    {
     
    $row_color = ($row_count % 2) ? $color1 : $color2;

    // Henter data fra tabeller i databasen. De blir da lagret til egne variabler. 
    $v_photo=$row->bilde_url;
    $v_overskrift=$row->overskrift;
    $v_adresse=$row->leiladresse;
    $v_post=$row->leilpostnr;
    $v_sted=$row->leilpoststed;
    $v_kvm=$row->kvm;
    $v_rom=$row->antallRom;
    $v_pris=$row->pris;
    $v_number=$row->lNr;

    ?>
    <form method="post"> 
    Sorter etter:<br> 
                    <select name="sort" size="1"> 
    <?php 
    foreach($addressArray as $v_adresse)

      print 
    '<option value="test"> '.$v_adresse.' </option>';

    ?> 
    </select> 
                    <input type="submit" name="Request" value="OK"> 
    </form> 

    <?
    Oooops some is still in norwegian...

  6. #6
    Mal Reynolds Mandibal's Avatar
    Join Date
    Aug 2003
    Location
    Columbus
    Posts
    718
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <form method="post"> 
    Sorter etter:<br> 
                    <select name="sort" size="1"> 
    <?php
    $q 
    "SELECT *, leilighet.leilighetsNr AS lNr FROM leilighet LEFT JOIN leietager ON leietager.leilighetsNr = leilighet.leilighetsNr 
          WHERE leietager.leilighetsNr IS NULL ORDER BY 
    $order LIMIT $from$max_results"
    $result mysql_query($q$conn) or die(mysql_error()); 
    while (
    $row mysql_fetch_object($result))
    {
     
    $row_color = ($row_count 2) ? $color1 $color2;

    // Henter data fra tabeller i databasen. De blir da lagret til egne variabler. 
    $v_photo=$row->bilde_url;
    $v_overskrift=$row->overskrift;
    $v_adresse=$row->leiladresse;
    $v_post=$row->leilpostnr;
    $v_sted=$row->leilpoststed;
    $v_kvm=$row->kvm;
    $v_rom=$row->antallRom;
    $v_pris=$row->pris;
    $v_number=$row->lNr;

      print 
    '<option value="test"> '.$v_adresse.' </option>';
    }
    ?> 
    </select> 
                    <input type="submit" name="Request" value="OK"> 
    </form>
    Oooops some is still in norwegian...
    I just can't understand.....j/k
    It's perfectly understandable....

    Okay so you just use the loop you're already using with the DB result set. But you put the form tags and the select tags outside the loop so your just outputing the option tags in the loop. HTH (and I hope the code works...sorry if it's not quite right...it's the idea that counts. )
    Erh

  7. #7
    SitePoint Enthusiast
    Join Date
    Apr 2005
    Posts
    25
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    NICE!! works perfect. thanks


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
  •