Re: [PHP] Custom function

2011-05-03 Thread Ashley Sheridan
"Andre Polykanine" wrote: >Hello Ashley, > >By the way, the non-last optional parameter can't be missed, am I >right? In some languages we could write something like: >function test ($a, $foo=50, $bar=true) { >// ... >} > >Then call it like this: > >$m=test("blah", , false); > >meaning > >$m

Re: [PHP] Custom function

2011-05-03 Thread Andre Polykanine
Hello Ashley, By the way, the non-last optional parameter can't be missed, am I right? In some languages we could write something like: function test ($a, $foo=50, $bar=true) { // ... } Then call it like this: $m=test("blah", , false); meaning $m=test("blah", 50, false); This is impossibl

Re: [PHP] Custom function

2011-05-02 Thread Ashley Sheridan
On Mon, 2011-05-02 at 18:28 -0400, Ron Piggott wrote: > On Mon, May 2, 2011 at 3:16 PM, Ron Piggott > wrote: > > > Is it possible to write a function with an optional flag? What would the > syntax look like? > > So far I have: > > function load_advertisement( $web_page_reference , >

Re: [PHP] Custom function

2011-05-02 Thread Ron Piggott
On Mon, May 2, 2011 at 3:16 PM, Ron Piggott wrote: Is it possible to write a function with an optional flag? What would the syntax look like? So far I have: function load_advertisement( $web_page_reference , $web_advertising_sizes_reference ) { Hi Ron: I'm not sure what you mean

Re: [PHP] Custom function

2011-05-02 Thread Richard S. Crawford
On Mon, May 2, 2011 at 3:16 PM, Ron Piggott wrote: > > Is it possible to write a function with an optional flag? What would the > syntax look like? > > So far I have: > > function load_advertisement( $web_page_reference , > $web_advertising_sizes_reference ) { > Hi Ron: I'm not sure what you m

Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 22:04, Paul M Foster wrote: > On Wed, Feb 16, 2011 at 09:21:20PM +0100, Peter Lind wrote: > >> On 16 February 2011 21:00, Dan Schaefer wrote: >> > In my code, I set the optional parameter to NULL and check for triple >> equals >> > "===" or "!==" to see if the variable has bee

Re: [PHP] Custom function

2011-02-16 Thread Paul M Foster
On Wed, Feb 16, 2011 at 09:21:20PM +0100, Peter Lind wrote: > On 16 February 2011 21:00, Dan Schaefer wrote: > > In my code, I set the optional parameter to NULL and check for triple > equals > > "===" or "!==" to see if the variable has been passed with a value. IMO, > > this is the safest way.

Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:45, Adam Richardson wrote: > On Wed, Feb 16, 2011 at 3:21 PM, Peter Lind wrote: > >> On 16 February 2011 21:00, Dan Schaefer wrote: >> > In my code, I set the optional parameter to NULL and check for triple >> equals >> > "===" or "!==" to see if the variable has been pass

Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:45, Andre Polykanine wrote: > Hello Peter, > > So is > func_get_args() >     the unique way? > Not really sure what you mean by the unique way. Most things proposed so far in the thread would be fine for most purposes, I'd say. If you really need finegrained control, I'd su

Re: [PHP] Custom function

2011-02-16 Thread Adam Richardson
On Wed, Feb 16, 2011 at 3:21 PM, Peter Lind wrote: > On 16 February 2011 21:00, Dan Schaefer wrote: > > In my code, I set the optional parameter to NULL and check for triple > equals > > "===" or "!==" to see if the variable has been passed with a value. IMO, > > this is the safest way. > > > >

Re: [PHP] Custom function

2011-02-16 Thread Andre Polykanine
Hello Peter, So is func_get_args() the unique way? -- With best regards from Ukraine, Andre Skype: Francophile My blog: http://oire.org/menelion (mostly in Russian) Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com/menelion Original message From

Re: [PHP] Custom function

2011-02-16 Thread Peter Lind
On 16 February 2011 21:00, Dan Schaefer wrote: > In my code, I set the optional parameter to NULL and check for triple equals > "===" or "!==" to see if the variable has been passed with a value. IMO, > this is the safest way. > > function MyFunction($x, $y, $z=NULL) { > if ($z !== NULL) { > // Do

Re: [PHP] Custom function

2011-02-16 Thread Dan Schaefer
In my code, I set the optional parameter to NULL and check for triple equals "===" or "!==" to see if the variable has been passed with a value. IMO, this is the safest way. function MyFunction($x, $y, $z=NULL) { if ($z !== NULL) { // Do Something } } Dan Schaefer Web Developer/Systems Analyst

Re: [PHP] Custom function

2011-02-16 Thread Mark Kelly
Hi. On Wednesday 16 Feb 2011 at 00:49 Simon J Welsh wrote: > As $z is converted to a boolean and exists, that works just the same way as > !empty(). --- First I'd like to apologise for handing out bad advice, and second, to thank Simon and Andre for pointing out my mistake. I'll go back to kee

Re: [PHP] Custom function

2011-02-15 Thread Simon J Welsh
On 16/02/2011, at 1:21 PM, Mark Kelly wrote: > In this way almost any value in $z will trigger the conditional code, > including 0 or an empty string. The exceptions are FALSE and NULL. If you > explicitly need to react to a NULL value, use is_null() to detect it. http://nz.php.net/boolean#lan

Re: [PHP] Custom function

2011-02-15 Thread Andre Polykanine
Hello Mark, Hm... will if ($z) evaluate to true if $z==0? I thought no... Actually, we can use if (isset($z)) -- With best regards from Ukraine, Andre Skype: Francophile My blog: http://oire.org/menelion (mostly in Russian) Twitter: http://twitter.com/m_elensule Facebook: http://facebook.com

Re: [PHP] Custom function

2011-02-15 Thread Richard Quadling
On 16 February 2011 00:21, Mark Kelly wrote: > Hi. > > On Tuesday 15 Feb 2011 at 23:41 Andre Polykanine wrote: > >> Give it a default (possible empty) value: >> >> function MyFunction($x, $y, $z="") { >> // function goes here >> if (!empty($z)) { >> // The optional parameter is given >> } >> } > >

Re: [PHP] Custom function

2011-02-15 Thread Mark Kelly
Hi. On Tuesday 15 Feb 2011 at 23:41 Andre Polykanine wrote: > Give it a default (possible empty) value: > > function MyFunction($x, $y, $z="") { > // function goes here > if (!empty($z)) { > // The optional parameter is given > } > } Using an empty string and the empty() function in this way can

Re: [PHP] Custom function

2011-02-15 Thread Andre Polykanine
Hello Ron, Give it a default (possible empty) value: function MyFunction($x, $y, $z="") { // function goes here if (!empty($z)) { // The optional parameter is given } } -- With best regards from Ukraine, Andre Skype: Francophile My blog: http://oire.org/menelion (mostly in Russian) Twitter: htt

RE: [PHP] Custom function for inserting values into MySQL

2009-11-05 Thread Daevid Vincent
> -Original Message- > From: Shawn McKenzie [mailto:nos...@mckenzies.net] > Sent: Thursday, November 05, 2009 6:14 AM > To: Daevid Vincent > Cc: 'Allen McCabe'; 'PHP General' > Subject: Re: [PHP] Custom function for inserting value

RE: [PHP] Custom function for inserting values into MySQL

2009-11-04 Thread Daevid Vincent
> -Original Message- > From: Shawn McKenzie [mailto:nos...@mckenzies.net] > Sent: Wednesday, November 04, 2009 6:20 AM > To: Allen McCabe; PHP General > Subject: Re: [PHP] Custom function for inserting values into MySQL > > In your example, I would name my form i

Re: [PHP] Custom function for inserting values into MySQL

2009-11-04 Thread Nathan Rixham
Shawn McKenzie wrote: Allen McCabe wrote: Do you see any major hangups or screwups on first glance? And is my fear of trying this out on my database unfounded? Does this even seem that useful? in all honesty.. loads of screwups - don't try it out on your database & ultimately if it isn't re

Re: [PHP] Custom function for inserting values into MySQL

2009-11-04 Thread Shawn McKenzie
In your example, I would name my form inputs similar to name ="data[user_id]". Then you just pass the $_POST['data'] array to your function. -Shawn Allen McCabe wrote: > You raise some good points. I always name my input fields after the > entity names ( eg. input type="hidden" name ="user_id" v

Re: [PHP] Custom function for inserting values into MySQL

2009-11-03 Thread Shawn McKenzie
Allen McCabe wrote: > Okay friends, I have been wondering about writing a simple function that > will help me with my MySQL inserting. Not because I need to save time and > space, but because I wanted to. > > I wrote a function for inserting 10 values (I have not been able to come up > with an ide

Re: [PHP] Custom function for inserting values into MySQL

2009-11-02 Thread Phpster
I would take a look at some of the frameworks like codeignter to see how they do things. But like Davied mentioned a simpler way to handle the passing into the function would be Function save($table, $data) Where data is an array of key value pairs which takes your 22 parameters down to

RE: [PHP] Custom function for inserting values into MySQL

2009-11-02 Thread Daevid Vincent
> Do you see any major hangups or screwups on first glance? Yes. There is so much wrong with this I don't even know where to begin... > This function takes 22 parameters: #1 is the table name, > #2-21 are the row > names and the values, and #22 is the "integar string". Dude. Seriously? TWENTY