hankknight
asked on
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>
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>';
}
?>
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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