foreach not working my MySQL query

Hello,

My code returns this:

<select name="FolderID">
  <option value="2">2</option>
  <option value="M">M</option>
</select>

Instead of this:
<select name="FolderID">
  <option value="21">Main</option>
  <option value="23">Sub</option>
  <option value="25">Tree</option>
</select>

<?php
	$strQry = "SELECT FolderID, FolderName FROM cms_Folders";
	$nResult = mysql_query($strQry);
	foreach (mysql_fetch_object($nResult) as $row)
             {
             echo '<option value="' . $row['FolderID'] .'">' . $row['FolderName'] . '</option>';
             }
?>

Open in new window

LVL 16
hankknightAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

gnarCommented:
With mysql_fetch_object, shouldn't it be something like $row->folder_id instead of $row['folder_id']?  I think the latter one (that you're using) would be correct with mysql_fetch_array.
0
nplibCommented:
do it like this.
<?php
   $strQry = "SELECT FolderID, FolderName FROM cms_Folders";
   $nResult = mysql_query($strQry);
   while ($row = mysql_fetch_object($nResult))
   {
      echo '<option value="' . $row['FolderID'] .'">' . $row['FolderName'] . '</option>';
   }
?>

Open in new window

0
Cornelia YoderArtistCommented:

 <?php
      $strQry = "SELECT FolderID, FolderName FROM cms_Folders";
      $nResult = mysql_query($strQry);
      while ($row=mysql_fetch_array($nResult))
             {
             echo '<option value="' . $row['FolderID'] .'">' . $row['FolderName'] . '</option>';
             }
?>
0
nplibCommented:
oops I ment
<?php
   $strQry = "SELECT FolderID, FolderName FROM cms_Folders";
   $nResult = mysql_query($strQry);
   while ($row = mysql_fetch_array($nResult))
   {
      echo '<option value="' . $row['FolderID'] .'">' . $row['FolderName'] . '</option>';
   }
?>

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nplibCommented:
and to do it with the mysql_fetch_object() function
<?php
   $strQry = "SELECT FolderID, FolderName FROM cms_Folders";
   $nResult = mysql_query($strQry);
   while ($row = mysql_fetch_object($nResult))
   {
      echo '<option value="' . $row->'FolderID' .'">' . $row->'FolderName' . '</option>';
   }
?>

Open in new window

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.