Jump to content


Photo

Function return a variable! Please help!!!


  • Please log in to reply
7 replies to this topic

#1 MCrosbie

MCrosbie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 27 September 2006 - 10:17 AM

function tablecall($table,$wherecmd,$othercmd,$callid){
		global $config;
		$que[$callid] = "SELECT * FROM $table where license='".$config['license']."' $wherecmd $othercmd";
		$res[$callid] = mysql_query($que[$callid])or die("ERROR". mysql_error()." query: ". $que[$callid]);
		$test_call = mysql_fetch_array($res[$callid]);
		if($test_call['license'] <> $config['license']){
			echo  '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php?error=license">'; exit;
    	}
		$$callid = mysql_fetch_array($res[$callid]);
		return $$callid;
	}

Now the above code ... let us say that $callid = row
Why can I not, after executing the function be able to go echo $row["id"] for example. Have I done something wrong? I am a newbie to using functions so I appologise if I'm asking a pathetically stupid question, which no doubt I am.

Thanks

#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 27 September 2006 - 01:08 PM

First Edit
return $$callid;
To be
return $callid;

Then to name that var
$callid = tablecall($table, $wherecmd, $othercmd, $callid);

Tell me the problem, I will try tell you the solution

#3 MCrosbie

MCrosbie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 27 September 2006 - 09:49 PM

Wouldn't this just repeat the function call forever? And just have it being repeated over and over again?
function tablecall($table,$wherecmd,$othercmd,$callid){
		global $config;
		$que[$callid] = "SELECT * FROM $table where license='".$config['license']."' $wherecmd $othercmd";
		$res[$callid] = mysql_query($que[$callid])or die("ERROR". mysql_error()." query: ". $que[$callid]);
		$test_call = mysql_fetch_array($res[$callid]);
		if($test_call['license'] <> $config['license']){
			// echo  '<META HTTP-EQUIV="Refresh" Content="0; URL=index.php?error=license">'; exit;
    	}
		$callid = tablecall($table, $wherecmd, $othercmd, $callid);
		$$callid = mysql_fetch_array($res[$callid]);
		return $callid;
	}


#4 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 27 September 2006 - 09:56 PM

no
it places the result of the function into that var
Tell me the problem, I will try tell you the solution

#5 MCrosbie

MCrosbie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 27 September 2006 - 10:09 PM

When I did run the script as above, that is exactly what it did, called the function for infinity.

#6 MCrosbie

MCrosbie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 27 September 2006 - 10:44 PM

I also tried to put "$callid =" infront of my function when it was called e.g.
$callid = tablecall("DL_functions","and functid='$functid'","","funct");

This didn't work and neither did this
$funct = tablecall("DL_functions","and functid='$functid'","","funct");
This returned "f" for every value asked for e.g. $funct['id'] would equal "f" when in fact it should equal 1

#7 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 27 September 2006 - 10:50 PM

What exactly are you trying to do? I dont see any reasoning behind a recursive function here.

#8 MCrosbie

MCrosbie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 27 September 2006 - 10:58 PM

Data is stored on a remote DB which checks the license number of the person with the script, if it matches it allows access to run the script in the DB. For instance if you called to Add a Page to your CMS then the internet address would be something like www.yoursite.com/cms/file.php?functid=100294, it would check that you were allowed to do this within your license rights and then give the file the script needed to add a page.

Because I am running the mysql_query, mysql_fetch_array, functions often I thought making a function would be easier and save code. As I said, I am new to functions, so I don't really know how to best use them. To me they don't seem very flexible and I don't understand how people can run whole sites off them. If anyone knows a good tutorial on OOP that would be greatly appreciated, one with real applications, for instance ecommerce example based.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users