Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Mar 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamically creating a select control.

    I have the basics of PHP fairly well and I have RTFM, but I simply cannot figure out what I'm doing wrong with this. I know it's prolly simple.

    Can any of you gurus please point out the error of my ways?
    Code:
    $query = "Select RecID, ColCode, ColName, endcaps from colors WHERE endcaps = '1'"; 
    
    $result = mysql_query($query);
    //echo (mysql_num_rows($result));
    while ($row = mysql_fetch_array($result)){
    echo "<option value = \"{$row[1]}\">{$row[1]}</option>"
    It throws parsing errors on the last line. I know I have a good result with 4 rows. The $row[1] has 3 digit numbers in it like 208, 209, etc.

    I want the statement generated to be:
    <option value="208">208</option>

    Can anyone tell me what the hell I'm doing wrong?

  • #2
    Senior Coder Nightfire's Avatar
    Join Date
    Jun 2002
    Posts
    4,266
    Thanks
    6
    Thanked 48 Times in 48 Posts
    PHP Code:
    $query "Select RecID, ColCode, ColName, endcaps from colors WHERE endcaps = '1'"

    $result mysql_query($query);
    //echo (mysql_num_rows($result));
    while ($row mysql_fetch_array($result)){
       echo 
    "<option value = \"{$row[1]}\">{$row[1]}</option>";

    It's also easier if you do it this way
    PHP Code:
    $query "Select RecID, ColCode, ColName, endcaps from colors WHERE endcaps = '1'"

    $result mysql_query($query);
    //echo (mysql_num_rows($result));
    while ($row mysql_fetch_array($result)){
       echo 
    '<option value="'.$row[1].'">'.$row[1].'</option>';


  • #3
    New Coder
    Join Date
    Mar 2007
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the fast reply.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •