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 Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/ 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); Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99569 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] Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99885 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 Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99889 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. Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99898 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 Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99924 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. Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99931 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. Link to comment https://forums.phpfreaks.com/topic/22228-function-return-a-variable-please-help/#findComment-99933 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.