MCrosbie Posted September 27, 2006 Share Posted September 27, 2006 [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 = rowWhy 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 Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 27, 2006 Share Posted September 27, 2006 First Editreturn $$callid;To bereturn $callid;Then to name that var$callid = tablecall($table, $wherecmd, $othercmd, $callid); Quote Link to comment Share on other sites More sharing options...
MCrosbie Posted September 27, 2006 Author Share Posted September 27, 2006 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] Quote Link to comment Share on other sites More sharing options...
onlyican Posted September 27, 2006 Share Posted September 27, 2006 noit places the result of the function into that var Quote Link to comment Share on other sites More sharing options...
MCrosbie Posted September 27, 2006 Author Share Posted September 27, 2006 When I did run the script as above, that is exactly what it did, called the function for infinity. Quote Link to comment Share on other sites More sharing options...
MCrosbie Posted September 27, 2006 Author Share Posted September 27, 2006 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 Quote Link to comment Share on other sites More sharing options...
trq Posted September 27, 2006 Share Posted September 27, 2006 What exactly are you trying to do? I dont see any reasoning behind a recursive function here. Quote Link to comment Share on other sites More sharing options...
MCrosbie Posted September 27, 2006 Author Share Posted September 27, 2006 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.