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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.