Jump to content

Retrieving values in a function?


Michan

Recommended Posts

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

<?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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.