Thursday, 15 August 2013

fetching option values from mysql

fetching option values from mysql

I new to php and mysql.
I wrote the function below:
function catOption() {
$maincatfunc_query = mysql_query("SELECT * FROM mainCats ORDER BY id ") or
die(mysql_error());
$funcCat = array();
while ($mainCatFunc = mysql_fetch_array($maincatfunc_query)) {
for ($i = 0; $i < count($maincatfunc_query); $i++) {
$funcCat[$i] = '<option
value="'.$maincatfunc_sorgu['mainCatID'].'">' .
$maincatfunc_sorgu['name'] . '</option>';
}
}
for ($i = 0; $i < count($maincatfunc_query); $i++) {
return $funcCat[$i];
}
}
I want to fetch "all" value from mysql database and fill it in a dropdown.
So i wrote a function like this. But it does not work.
And i don't think count() function doesn't really work in this conditions.
How can i get the max count of mysql array ?.
or besides can i do this without using a function ?. I've googled it for a
long time but i can't find any usefull info.
Thanks !

No comments:

Post a Comment