problem with OPTION

Discussion in 'PHP' started by abhiN, Feb 27, 2008.

  1. #1
    Hi

    i m trying to get the values from database and put it into the select options..
    i m using code-
    
    <?php
    $con = mysql_connect("localhost","cdccpl","d123");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    					  mysql_select_db("cdccpl_aus", $con);
    $result = mysql_query("SELECT * FROM bak_bill_cust");
     while( $row = mysql_fetch_array( $result ) ):
     $option = $row["cust_code"];
    
    echo "<option value='$row[cust_code]'>$row[cust_code]</option>";
    endwhile;
     mysql_close($con);?>
    
    Code (markup):
    but i m getting displayes with the values as--
    
    Customer auswidestonemanpnicholsonllwmplnewuserguestanftasturnbullanglic  
    
    Code (markup):
    means values getting displayed one after another and not in option..

    why so..
    plz help
     
    abhiN, Feb 27, 2008 IP
  2. ghannam

    ghannam Peon

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    try this
    <?php
    $con = mysql_connect("localhost","cdccpl","d123");
    if (!$con)
      {
      die('Could not connect: ' . mysql_error());
      }
    					  mysql_select_db("cdccpl_aus", $con);
    $result = mysql_query("SELECT * FROM bak_bill_cust");
    echo"<select name='D1'>";
     while( $row = mysql_fetch_array( $result ) ):
     $option = $row["cust_code"];
    
    echo "<option value='$row[cust_code]'>$row[cust_code]</option>";
    endwhile;
    echo "</select>";
     mysql_close($con);?>
    PHP:
     
    ghannam, Feb 27, 2008 IP