Jump to content

variable functions


Go to solution Solved by kicken,

Recommended Posts

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,

 

Link to comment
https://forums.phpfreaks.com/topic/317056-variable-functions/
Share on other sites

  • Solution
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.

 

Link to comment
https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610308
Share on other sites

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 by Cholotron
Link to comment
https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610323
Share on other sites

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 by ginerjm
Link to comment
https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610340
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610349
Share on other sites

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

Link to comment
https://forums.phpfreaks.com/topic/317056-variable-functions/#findComment-1610353
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.