problem in code

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

  1. #1
    Hi All,

    I have some problems in the following code please help me.....
    <?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>';
    ?>

    ERROR COMES: echo '<option value="'.$row['yourfield'].'">'.$row['yourfield'].'</option>'; line

    ','string should used ','

    I am not able to understand what is the actual problem???
     
    mahiraj, Oct 15, 2007 IP
  2. MakeADifference

    MakeADifference Peon

    Messages:
    476
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this:
    echo '<option value="' .$row["yourfield"] .'">' .$row["yourfield"] .'</option>';
     
    MakeADifference, Oct 15, 2007 IP
  3. Lordy

    Lordy Peon

    Messages:
    1,643
    Likes Received:
    29
    Best Answers:
    0
    Trophy Points:
    0
    #3
    echo "<option value=".$row['yourfield'].">".$row['yourfield']."</option>";

    i could be wrong, but not sure why you have "'.$row['yourfield']'"

    dont know why oyu need the ' and " :eek: i could be wrong though.

    also, try echoing it with " instead of '
     
    Lordy, Oct 16, 2007 IP
  4. mahiraj

    mahiraj Guest

    Messages:
    47
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    actually i want to fetch value from 'hostel_name' table into a combo box so i am doing this
    and 'yourfield' is the field name of that table '
    so i am doing this .......
    any suggestion will be appreciated.
    thank you.
     
    mahiraj, Oct 16, 2007 IP
  5. jnestor

    jnestor Peon

    Messages:
    133
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    There's nothing wrong with that line.

    What's the actual error you're getting?
     
    jnestor, Oct 16, 2007 IP
  6. grikis

    grikis Banned

    Messages:
    333
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    0
    #6
    <?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>";
    ?>
     
    grikis, Oct 16, 2007 IP