help in php

Discussion in 'PHP' started by mahiraj, Oct 14, 2007.

  1. #1
    Hi All,

    I am new in PHP. I want to retrieve value from database into a combo-box.
    How will i do this?
    Please give me the code to do this. and what will i write in html side
    <select>
    <option> </option></select>
    please help me to do this.
     
    mahiraj, Oct 14, 2007 IP
  2. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #2
    can you explain better?
     
    Lordy, Oct 14, 2007 IP
  3. mahiraj

    mahiraj Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    I want fetch values from a table ,
    in database i have a table which name is "hostel_name"
    now i am making a combo-box in the form and i want to fetch values from "hostel_name"
    when i click on the combo the list of all "hostel_name" i get which are stored into the table"hostel-name".

    please help
     
    mahiraj, Oct 14, 2007 IP
  4. kkrizka

    kkrizka Peon

    Messages:
    223
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Assuming you already connected to the DB, and make sure to replace the yourfield with the column name of what you want to fetch. :)

    
    <?php
    $query="SELECT * FROM hostel_name";
    $res=mysql_query($query) or die(mysql_error());
    echo '<select>';
    while($row=mysql_fetch_array($res)) {
       echo '<option value="'.$row['yourfield'].'">'.$row['yourfield'].'</option>';
    }
    echo '</select>';
    ?>
    
    Code (php):
     
    kkrizka, Oct 14, 2007 IP
  5. mahiraj

    mahiraj Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Thanks a lot man.

    It's working.........
     
    mahiraj, Oct 14, 2007 IP