Link to home
Create AccountLog in
Avatar of Tablecloth
Tablecloth

asked on

PHP dropdown list not displaying first MySql record

Greetings,

I cannot know why the following code does not return the first record to a dropdown list from a MySql table.

The funny thing is, the commented out code does work.

I am not calling the mysql_fetch_array twice either...

Any help would be appreciated.

Mick
 

$sqlAuthors="SELECT AuthorID, Author FROM Authors";
$TheResult=mysql_query($sqlAuthors);
$options="";


while ($row=mysql_fetch_array($TheResult))
{
    $id=$row["AuthorID"];
    $thing=$row["Author"];
    $options.="<OPTION VALUE=\"$id\">".$thing.'</option>';
}  

//while ($row=mysql_fetch_array($TheResult))
//{
//     $id=$row["AuthorID"];
//     $thing=$row["Author"];
//    
//     echo "Record No. $id is $thing </br>";
//    // $options.='<option value="'.$id.'">'.$thing.'</option>';  
//      
//}


 
 echo <<<_END
   
<form action="DropDownListExample.php" method="post">

         <SELECT NAME="ddAuthors">
         <?=$options?>
         </SELECT>
         
        <input type ="submit" value="GetAuthors"/>
   
 </form>

_END;
Avatar of forethought
forethought

Does this work?

$sqlAuthors = "SELECT AuthorID, Author FROM Authors"; 
$TheResult = mysql_query($sqlAuthors); 
$options = ''; 


while (list($id, $thing) = mysql_fetch_array($TheResult)) 
{ 
    $options .= '<option value="' . $id .'">' . $thing . '</option>';
}   

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Tablecloth
Tablecloth

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
Avatar of Tablecloth

ASKER

trial and error of a weak programmer