You are here: another question: foreach() « All PHP « IT news, forums, messages
another question: foreach()

Posted by gerg on 05/09/06 10:32

I've got a function that creates a form with a drop down list of values
selected from a database.


function form_MS($formname, $method, $action){

$sql = "SELECT orders.MS FROM orders;";
$result = @mysql_query($sql);
$numrows = @mysql_num_rows($result);

if ($numrows == NULL){
return (false);
}
else
{
$my_baby = @mysql_fetch_array($result);

echo ("<form name=\"$formname\" method=\"$method\" action=\"$action\">\n");

echo ("<select name=\"MS\">\n");

foreach($my_baby as $baby){
echo ("<option value=\"$baby\">$baby</option>\n");
}

echo ("</select>\n");
echo ("</form>\n");

}


}

there are three records in the DB. But the form ends up looking like this:

<form action="someaction" method="somemethod" name="somename>
<selcect name="MS">
<option value="123456">123456</option>
<option value="123456">123456</option>
</select>
</form>

So it's only selecting the first record and echoing it twice.

thanks in advance for any help.

Greg

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация