monkeypaw201 Posted May 16, 2008 Share Posted May 16, 2008 i have this function: <?php function topmenu() { do { echo $row_topmenu['link']; } while ($row_topmenu = mysql_fetch_assoc($topmenu)); } ?> and when i place this: <?php topmenu(); ?> i get this error: Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in index.php on line 87 Link to comment https://forums.phpfreaks.com/topic/105983-solved-function-not-working/ Share on other sites More sharing options...
micmania1 Posted May 16, 2008 Share Posted May 16, 2008 <?php function topmenu() { global $topmenu; // Fetc variable form outside of the funciton do { echo $row_topmenu['link']; } while ($row_topmenu = mysql_fetch_assoc($topmenu)); } ?> About Globals... Link to comment https://forums.phpfreaks.com/topic/105983-solved-function-not-working/#findComment-543168 Share on other sites More sharing options...
monkeypaw201 Posted May 16, 2008 Author Share Posted May 16, 2008 Well.. i am not getting errors, but it isn't displaying anything... Link to comment https://forums.phpfreaks.com/topic/105983-solved-function-not-working/#findComment-543169 Share on other sites More sharing options...
DarkWater Posted May 16, 2008 Share Posted May 16, 2008 Let us see where you assign $topmenu. Like, the query. Link to comment https://forums.phpfreaks.com/topic/105983-solved-function-not-working/#findComment-543171 Share on other sites More sharing options...
monkeypaw201 Posted May 16, 2008 Author Share Posted May 16, 2008 Well, i added global $row_topmenu; so it looks like this: <?php function topmenu() { global $topmenu; global $row_topmenu; do { echo $row_topmenu['link']; } while ($row_topmenu = mysql_fetch_assoc($topmenu)); } ?> and now it works, thanks! Link to comment https://forums.phpfreaks.com/topic/105983-solved-function-not-working/#findComment-543174 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.