Cholotron Posted July 6, 2023 Share Posted July 6, 2023 Good Morning, (First post) I have modified several functions. They no longer need 2 variables, just one. But they still working fine when I send two variables. Why there is not error? Function web_name($the_id) { $var_sql = "select page_name from web_pages where page_id='$the_id';"; $ms_conn = sqlsrv_connect($sql_server, $ms_sql); $result = sqlsrv_query($ms_conn,$var_sql); while ($row = sqlsrv_fetch_array($result)) { return $row['page_name']; } sqlsrv_close($ms_conn); } Thank you All, Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/ Share on other sites More sharing options...
Solution kicken Posted July 6, 2023 Solution Share Posted July 6, 2023 6 minutes ago, Cholotron said: Why there is not error? PHP allows extra values to be passed to a function. You can use func_get_args to obtain these values within the function and do something with them. This is the original way of creating a variable-length argument function. Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610308 Share on other sites More sharing options...
ginerjm Posted July 6, 2023 Share Posted July 6, 2023 But the function does not make sense. Where are $sql_server, $ms_sql and $var_sql defined? And what is the point of a while loop if you are returning after fetching only one record? Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610317 Share on other sites More sharing options...
Cholotron Posted July 7, 2023 Author Share Posted July 7, 2023 (edited) Hi, my funct is inside a funcionts.php file Variables are declare at the top. All my pages have error code handling Question how can I change to code to avoid the while loop? <?php //Start php ini_set('display_errors', TRUE); error_reporting(E_ALL); // Global Variables $ms_sql = array( "Database"=>"WEBSQL", "UID"=>"xxxx_user", "PWD"=>"xxx2003"); $sql_server = "INTRANET"; $local_ip = getenv("REMOTE_ADDR") ; $local_user = gethostbyaddr($_SERVER['REMOTE_ADDR']); ....... ?> Thank you All Edited July 7, 2023 by Cholotron Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610323 Share on other sites More sharing options...
ginerjm Posted July 7, 2023 Share Posted July 7, 2023 (edited) I don't know what this "funcionts.php" (sic) file is doing for you but you are showing US a function that uses variables that simply Do Not Exist. Period. And your latest post has a comment followed by some definitions. Those items may be supposed 'Global variables' but there is nothing being done to make them global. And besides - just because you may have declared (properly) a variable to be global, if you don't also reference them with the 'global' command (construct?) inside each function that you want to have access to it, they will be strictly local Edited July 7, 2023 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610340 Share on other sites More sharing options...
Cholotron Posted July 7, 2023 Author Share Posted July 7, 2023 Function web_name($the_id) { global $ms_sql, $sql_server,$local_ip, $local_user; $var_sql = "select page_name from web_pages where page_id='$the_id';"; $ms_conn = sqlsrv_connect($sql_server, $ms_sql); $result = sqlsrv_query($ms_conn,$var_sql); while ($row = sqlsrv_fetch_array($result)) { return $row['page_name']; } sqlsrv_close($ms_conn); } Happy now? Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610349 Share on other sites More sharing options...
Cholotron Posted July 7, 2023 Author Share Posted July 7, 2023 Sic? Period? Are you ok man? If you are constipated I can send you prunes... You know? To easy your Mornings Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610350 Share on other sites More sharing options...
ginerjm Posted July 7, 2023 Share Posted July 7, 2023 Have no idea what your beef is and No - I am not happy now. But I think you will be happier now that you fixed your function. Sic? Do you know what that mean? Period - means I am telling you the truth and that's that. But I shouldn't have had to splain that to you. HTH Quote Link to comment https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610353 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.