Jump to content

Archived

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

MCrosbie

Function return a variable! Please help!!!

Recommended Posts

[code] 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;
}[/code]

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

Share this post


Link to post
Share on other sites
First Edit
return $$callid;
To be
return $callid;

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

Share this post


Link to post
Share on other sites
Wouldn't this just repeat the function call forever? And just have it being repeated over and over again?
[code]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;
}[/code]

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
What exactly are you trying to do? I dont see any reasoning behind a recursive function here.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

×

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.