Michan Posted May 5, 2008 Share Posted May 5, 2008 Hi, I'm having problems trying to retrieve certain values from a function. The function is below: function getpage($pageid,$number,$comic,$total,$thispage) { $getpage = mysql_query('SELECT pageid FROM pages WHERE page='.$comic.' AND previouspg='.$pageid); $page = mysql_fetch_array($getpage); $pageorder[$number] = $page['pageid']; if($number != $total) getpage($page['pageid'],($number+1),$comic,$total,$thispage); if($pageid = $thispage) $thepage = $number; } After running it (and getting some results; I've tested it with an echo), how do I get $thepage and $pageorder (an array) from the function? I've tried return $thepage; and return $pageorder; but have had no success there ($thepage and $pageorder were empty). Any help would be greatly appreciated! Thanks in advance, - Mi Link to comment https://forums.phpfreaks.com/topic/104163-retrieving-values-in-a-function/ Share on other sites More sharing options...
rameshfaj Posted May 5, 2008 Share Posted May 5, 2008 <?php function getpage($pageid,$number,$comic,$total,$thispage) { $getpage = mysql_query('SELECT pageid FROM pages WHERE page='.$comic.' AND previouspg='.$pageid); $page = mysql_fetch_array($getpage); $pageorder[$number] = $page['pageid']; if($number != $total) getpage($page['pageid'],($number+1),$comic,$total,$thispage); if($pageid = $thispage) $thepage = $number; } function getValues() { return "Test"; } $returnvalue=getValues(); echo "the return values is $returnvalue"; ?> this will give the result: the return values is Test What u are lacking is the return statement and if u want to return more than one values,then try to return in the array,This may solve ur problem.Ex: first element of the array may be something and others may be the other according to our conventions. Link to comment https://forums.phpfreaks.com/topic/104163-retrieving-values-in-a-function/#findComment-533321 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.