Re: [PHP] Help with Functions

2005-07-30 Thread sub
I would recomend for sanity and clean code that you define your functions
outside of the file you will be calling it from and include that file in any
file you need to call a function from.

Here's a function that I defined in my db.php file.

/***
 * FUNCTION: DBCheckByMin($min)
 * DESCRIPTION: Checks to see if the user's min already exists
 * RETURNED: exist (1 or 0)
 **/
function DBCheckByMin($min)
{
$record = mysql_query( SELECT `min` FROM `user` WHERE `min` LIKE '$min' );

for($i=0; $holder[$i]=mysql_fetch_array( $record ); $i++);

if($min==$holder[0][0])
 {
  $exist=1;
 }
else
 {
  $exist=0;
 }
return $exist;
}

The first line of the file I call this function in includes my function
list:
include db.php;

And my call to the function itself:
$check=DBCheckByMin($min);



Let's say my user is entering his MIN as 1234567890

What the function does is catch the value of the variable $min which is
1234567890 when it's called and pass it to the function. Then DBCheckByMin
takes the value 1234567890 and assignes it to the variable $min. (I've named
both variables the same so I know what they are) Now that the function has
it's own variable, $min that has a value of 1234567890 It then does some
basic SQL work to find if that MIN already exists in my databse. Then it
sets $exist to either 1 or 0. It sets it to 1 if this is a duplicate entry
and 0 if it's not a duplicate. And let's just say that it did indeed find a
duplicate record so $exist will have the value of 1.  Next on the return
line, the function sends back the value of $exist which is 1. Please
remember when I called the function I had a variable before the function was
called $check=DBCheckByMin($min);  This way $check will catch whatever
value the function returns, in this case, that value is 1. Now that check
has a value which indicates that this user already exists I can send a
message to the user saying that it already exists and to try again.

Did that make a bit more sense about how variables are passed between
functions? It's all in the call and definition.


Andrew Darrow
Kronos1 Productions
www.pudlz.com


- Original Message - 
From: Tom Chubb [EMAIL PROTECTED]
To: php-general@lists.php.net
Sent: Saturday, July 30, 2005 9:23 AM
Subject: [PHP] Help with Functions


I am trying to start using functions on some pages to layout a header
row in a table.
I have defined the function as below...

?php
function (headerrow)
{ ?
table width=750 border=0 cellpadding=0 cellspacing=0
bgcolor=#FF0066
tr
  td class=table_head?php echo $tablehead; ?/td
  td width=20img src=/nav/images/pspromo_table_rhs.gif
width=20 height=20/td
/tr
/table
?php
}
?


What I can't seem to work out is a way to set the text. Here I've
echoed the $tablehead value, but it I was to use more than one table
on the same page then it wouldn't work. Can I do something like
headerrow(text goes here) or something?
I can't understand the use of arguments and it's really confusing me!
Any help would be really appreciated.
Thanks,

Tom

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php





-- 
No virus found in this incoming message.
Checked by AVG Anti-Virus.
Version: 7.0.338 / Virus Database: 267.9.7/60 - Release Date: 7/28/2005

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with Functions

2005-07-30 Thread Rory Browne
You're declaring your function wrong.

You're doing:

function (function_name)

You should be doing 

function function_name($arg1, $arg2, $arg3) // with as many comma
seperated arguments as you want.

or if you don´t want to pass any arguments

function function_name()


Try this out:

function make_table($arg1, $arg2){
?
table
 tr
td?php echo $arg1; ?/td
td?php echo $arg2; ?/td
 /tr
 /table
?php
}

note that I have to go back into PHP twice to get the variables. 

I could also (although tbh you should wait until you have more
experience before  you read on)

function make_table($arg1, $arg2){
echo ENDOFTABLE
table
 tr
td$arg1/td
td$arg2/td
 /tr
/table
ENDOFTABLE;
}




On 7/30/05, Tom Chubb [EMAIL PROTECTED] wrote:
 I am trying to start using functions on some pages to layout a header
 row in a table.
 I have defined the function as below...
 
 ?php
 function (headerrow)
 { ?
table width=750 border=0 cellpadding=0 cellspacing=0
 bgcolor=#FF0066
tr
  td class=table_head?php echo $tablehead; ?/td
  td width=20img src=/nav/images/pspromo_table_rhs.gif
 width=20 height=20/td
/tr
/table
 ?php
 }
 ?
 
 
 What I can't seem to work out is a way to set the text. Here I've
 echoed the $tablehead value, but it I was to use more than one table
 on the same page then it wouldn't work. Can I do something like
 headerrow(text goes here) or something?
 I can't understand the use of arguments and it's really confusing me!
 Any help would be really appreciated.
 Thanks,
 
 Tom
 
 --
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php
 


--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with Functions

2005-07-30 Thread Tom Chubb
Thanks guys for all your help.
I've managed to get it working.
I tried calling the function from within the file and it turned out
that somehow I had messed up my include statement.
I understood about adding argument variables to the syntax, but I
needed to add a text argument as I couldn't think of a way of setting
the variable in a way that I could distinguish between different
values for different tables on the same page.

Anyway, thanks to you all for taking some time to help me out.
T

On 30/07/05, Rory Browne [EMAIL PROTECTED] wrote:
 You're declaring your function wrong.
 
 You're doing:
 
 function (function_name)
 
 You should be doing
 
 function function_name($arg1, $arg2, $arg3) // with as many comma
 seperated arguments as you want.
 
 or if you don´t want to pass any arguments
 
 function function_name()
 
 
 Try this out:
 
 function make_table($arg1, $arg2){
 ?
table
 tr
td?php echo $arg1; ?/td
td?php echo $arg2; ?/td
 /tr
 /table
 ?php
 }
 
 note that I have to go back into PHP twice to get the variables.
 
 I could also (although tbh you should wait until you have more
 experience before  you read on)
 
 function make_table($arg1, $arg2){
 echo ENDOFTABLE
table
 tr
td$arg1/td
td$arg2/td
 /tr
/table
 ENDOFTABLE;
 }
 
 
 
 
 On 7/30/05, Tom Chubb [EMAIL PROTECTED] wrote:
  I am trying to start using functions on some pages to layout a header
  row in a table.
  I have defined the function as below...
 
  ?php
  function (headerrow)
  { ?
 table width=750 border=0 cellpadding=0 cellspacing=0
  bgcolor=#FF0066
 tr
   td class=table_head?php echo $tablehead; ?/td
   td width=20img src=/nav/images/pspromo_table_rhs.gif
  width=20 height=20/td
 /tr
 /table
  ?php
  }
  ?
 
 
  What I can't seem to work out is a way to set the text. Here I've
  echoed the $tablehead value, but it I was to use more than one table
  on the same page then it wouldn't work. Can I do something like
  headerrow(text goes here) or something?
  I can't understand the use of arguments and it's really confusing me!
  Any help would be really appreciated.
  Thanks,
 
  Tom
 
  --
  PHP General Mailing List (http://www.php.net/)
  To unsubscribe, visit: http://www.php.net/unsub.php
 
 
 


-- 
Tom Chubb
[EMAIL PROTECTED]
07915 053312

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Help with functions()

2002-11-20 Thread Chris Hewitt
Beauford 2002 wrote:


Hi,

I have form that a user would input information and that info is sent to
a function, but I need to be able to return a result of this function
and is where I am having a problem. 

For example:

testfunction($var1, $var2, $var3, $var4);  //the form fills these
values.

echo $meat;

function testfunction($a, $b, $c, $d) {

	The $meat of the function goes here;

	Now I need to return the result of $meat;

	return $meat;
}

$return_value = testfunction (

echo $return_value;

HTH
Chris






--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help with functions()

2002-11-20 Thread Tracy Finifter Rotton
Try:

$meat = testfunction ($var1, $var2, $var3, $var4);
echo $meat;


Or, alternatively,

print (testfunction ($var1, $var2, $var3, $var4));


hope this helps.

--t

On 11/20/02 8:40 PM, Beauford 2002 [EMAIL PROTECTED] wrote:

 Hi,
 
 I have form that a user would input information and that info is sent to
 a function, but I need to be able to return a result of this function
 and is where I am having a problem.
 
 For example:
 
 testfunction($var1, $var2, $var3, $var4);  //the form fills these
 values.
 
 echo $meat;
 
 function testfunction($a, $b, $c, $d) {
 
 The $meat of the function goes here;
 
 Now I need to return the result of $meat;
 
 return $meat;
 }
 
 This does not work. I'm new to funtions and obviously missing something,
 but I haven't been able to find a good tutorial on this. The PHP manual
 isn't much help.
 
 Any help is appreciated.
 
 

-- 
Tracy F. Rotton
[EMAIL PROTECTED]
http://www.taupecat.com/

  ... I like the 49ers because they're pure of heart,
  Seattle because they've got something to prove,
  and the Raiders because they always cheat.
 -- Lisa Simpson, Lisa the Greek


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help with functions()

2002-11-20 Thread Jason Sheets
You don't need the () around print.

print testfunction($var1, $var2, $var3, $var4);

Jason


On Wed, 2002-11-20 at 17:48, Tracy Finifter Rotton wrote:
 Try:
 
 $meat = testfunction ($var1, $var2, $var3, $var4);
 echo $meat;
 
 
 Or, alternatively,
 
 print (testfunction ($var1, $var2, $var3, $var4));
 
 
 hope this helps.
 
 --t
 
 On 11/20/02 8:40 PM, Beauford 2002 [EMAIL PROTECTED] wrote:
 
  Hi,
  
  I have form that a user would input information and that info is sent to
  a function, but I need to be able to return a result of this function
  and is where I am having a problem.
  
  For example:
  
  testfunction($var1, $var2, $var3, $var4);  //the form fills these
  values.
  
  echo $meat;
  
  function testfunction($a, $b, $c, $d) {
  
  The $meat of the function goes here;
  
  Now I need to return the result of $meat;
  
  return $meat;
  }
  
  This does not work. I'm new to funtions and obviously missing something,
  but I haven't been able to find a good tutorial on this. The PHP manual
  isn't much help.
  
  Any help is appreciated.
  
  
 
 -- 
 Tracy F. Rotton
 [EMAIL PROTECTED]
 http://www.taupecat.com/
 
   ... I like the 49ers because they're pure of heart,
   Seattle because they've got something to prove,
   and the Raiders because they always cheat.
  -- Lisa Simpson, Lisa the Greek
 
 
 -- 
 PHP General Mailing List (http://www.php.net/)
 To unsubscribe, visit: http://www.php.net/unsub.php


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help with functions()

2002-11-19 Thread Leif K-Brooks
echo testfunction($var1, $var2, $var3, $var4);

Or if you need to do something else with the value before echo()ing it:

$meat = testfunction($var1, $var2, $var3, $var4);
//Do something with $meat

Beauford 2002 wrote:


Hi,

I have form that a user would input information and that info is sent to
a function, but I need to be able to return a result of this function
and is where I am having a problem. 

For example:

testfunction($var1, $var2, $var3, $var4);  //the form fills these
values.

echo $meat;

function testfunction($a, $b, $c, $d) {

	The $meat of the function goes here;

	Now I need to return the result of $meat;

	return $meat;
}

This does not work. I'm new to funtions and obviously missing something,
but I haven't been able to find a good tutorial on this. The PHP manual
isn't much help.

Any help is appreciated.



 


--
The above message is encrypted with double rot13 encoding.  Any unauthorized attempt to decrypt it will be prosecuted to the full extent of the law.




--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help with functions.

2002-02-28 Thread Greg Donald

 I need some help with functions. Does anyone know of a good place to learn
 about functions? Will someone be willing to teach me what I need to know
about
 functions in PHP? Thank you,

Here's a really simple example:

?
// regular variable that exists outside any functions
$global_var = 5;

// we will pass this variable to the function
$passed_var = 7;

// define the function
function function_name ($passed_var){

// pull in any needed global variables not local or passed to the function
global $global_var;

// regular variable that exists only in this function
$local_var = 10;

// build up the html
$html = Now inside function_name()...br\n;

// build up some more html
$html .= \$global_var + \$local_var + \$passed_var =  . $global_var +
$local_var + $passed_var . br\n;

// pass the $html back to the caller
return $html;
}

// call the function
echo function_name ($passed_var);

?

Usually you wanna use funtions for code you intend to use multiple times.


Greg Donald - http://destiney.com/
http://phprated.com/ | http://phplinks.org/ | http://phptopsites.com/



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




Re: [PHP] Help!! IP functions!!!

2001-02-19 Thread Jason Cox

Use the variable $REMOTE_ADDR.  It contains the request ip address.

Jason

- Original Message - 
From: "Bruno Freire" [EMAIL PROTECTED]
To: [EMAIL PROTECTED]
Sent: Monday, February 19, 2001 12:34 PM
Subject: [PHP] Help!! IP functions!!!


 Hi!! 
 
 My name is Bruno, From Brazil!!!
 
 I need to know how can i discovery the ip address when somebody access my
 home page
 
 What function can I use
 
 Thanks!!
 Bruno.
 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP] Help!! IP functions!!!

2001-02-19 Thread Martin A. Marques

Mensaje citado por: Bruno Freire [EMAIL PROTECTED]:

 Hi!! 
 
 My name is Bruno, From Brazil!!!
 
 I need to know how can i discovery the ip address when somebody access
 my
 home page
 
 What function can I use

Bruno, check the phpinfo() function, which will give you lots of information
about variables that are passed from the browser to the server.

I think that HTTP_SERVER_VARS["REMOTE_ADDR"] is what you're looking for.

Saludos... :-)

Martn Marqus

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]