[PHP] niewbie - call methods from another class
Hello, I have something like this: $stmt = $this->_dbh->prepare("INSERT INTO DOG (name_dog, race_dog, id_vet) VALUES (?, ?, ?)"); $stmt->bindParam(1, $this->getNameDog() ); $stmt->bindParam(2, $this->getRaceDog()); $stmt->bindParam(3, ); $stmt->execute(); } To make this insert function work, I need to fill the id_vet database column with some values. I cannot use $this->getIdVet() because this method is not in dog class, is on the veterinary class. So my question is: How can I access the getIdVet() that is on the veterinary class to put it on the insert dog method? Thanks a lot, Márcio
[PHP] self in inherited methods
Is it right that 'self' in inherited method still points to the parent? If it is, can you explain it? It makes me worry :) A piece of code below for example get_instance(); $c = $a->get_another_instance(); echo $a->get_name(),"\n"; echo get_class($b),"\n"; echo get_class($c),"\n"; ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] How do I access a local variable?
Hi guys, I have a function inside which I set alocal variable to store a result. Can I access this variable in another function? if yes then how? function tbl1($entrytitle, $entrytext) { global $conn; $result= mysql_query("INSERT INTO tbl1(tbl1_id, title, text) VALUES('NULL', '$entrytitle', '$entrytext')", $conn); $tbl_id=mysql_insert_id($conn);// this is the local variable I'm setting to get the last auto increment id } Now I wish to access that variable in another function thus: function tbl2($name, $entrytitle, $entrytext) { global $conn; $result =mysql_query("INSERT INTO tbl2(tbl1_id, name, title, text) VALUES('$tbl1_id', '$name', '$entrytitle', '$entrytext' )", $Conn); } Or is there a better way to store the variable? Thanks in advance. Alugo Abdulazeez www.frangeovic.com _ More than messages–check out the rest of the Windows Live™. http://www.microsoft.com/windows/windowslive/
Re: [PHP] How do I access a local variable?
abdulazeez alugo wrote: Hi guys, I have a function inside which I set alocal variable to store a result. Can I access this variable in another function? if yes then how? No, you can't. You either need to pass it back (recommended) or make it global (not recommended). function tbl1($entrytitle, $entrytext) { global $conn; $result= mysql_query("INSERT INTO tbl1(tbl1_id, title, text) VALUES('NULL', '$entrytitle', '$entrytext')", $conn); $tbl_id=mysql_insert_id($conn);// this is the local variable I'm setting to get the last auto increment id return $tbl_id; } Now I wish to access that variable in another function thus: function tbl2($name, $entrytitle, $entrytext) { $other_id = tbl1($entrytitle, $entrytext); echo $other_id; global $conn; $result =mysql_query("INSERT INTO tbl2(tbl1_id, name, title, text) VALUES('$tbl1_id', '$name', '$entrytitle', '$entrytext' )", $Conn); } PS : look up mysql_real_escape_string for when you save your data. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I access a local variable?
On Mon, Apr 20, 2009 at 12:54:27AM +0100, abdulazeez alugo wrote: > > Hi guys, > > I have a function inside which I set alocal variable to store a result. Can I > access this variable in another function? if yes then how? > > function tbl1($entrytitle, $entrytext) > > { > > global $conn; > > $result= mysql_query("INSERT INTO tbl1(tbl1_id, title, text) > > VALUES('NULL', '$entrytitle', '$entrytext')", $conn); > > $tbl_id=mysql_insert_id($conn);// this is the local variable I'm setting > to get the last auto increment id > > } > > > > Now I wish to access that variable in another function thus: > > function tbl2($name, $entrytitle, $entrytext) > > { > > global $conn; > > $result =mysql_query("INSERT INTO tbl2(tbl1_id, name, title, text) > >VALUES('$tbl1_id', '$name', '$entrytitle', > '$entrytext' )", $Conn); > > } > > > > Or is there a better way to store the variable? If a variable is local to a function, there is no way to access that variable outside that function. You can pass it back as a return value from the original function, or make it global (not advised) to make it visible in other functions. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] DATE / strtotime
Where $date_reference is 2009-04-18 the following code gives me a day of 1969-12-30. How do I get it to be 2009-04-17? $previous_date = strtotime("-1 days", $date_reference); $previous_date = date('Y-m-d', $previous_date); echo $previous_date; outputs 1969-12-30 Ron
Re: [PHP] DATE / strtotime
Ron Piggott wrote: Where $date_reference is 2009-04-18 the following code gives me a day of 1969-12-30. How do I get it to be 2009-04-17? $previous_date = strtotime("-1 days", $date_reference); $previous_date = date('Y-m-d', $previous_date); Slightly wrong syntax. $previous_date = strtotime("$date_reference -1 days"); -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DATE / strtotime
Ron Piggott wrote: Where $date_reference is 2009-04-18 the following code gives me a day of 1969-12-30. How do I get it to be 2009-04-17? $previous_date = strtotime("-1 days", $date_reference); $previous_date = date('Y-m-d', $previous_date); echo $previous_date; outputs 1969-12-30 Ron You need to read the strtotime page in the manual. http://php.net/strtotime It says that the second argument of the strtotime function is suppose to be a unix time stamp. Is the value that you gave us for $date_reference a unix time stamp? No Your code should be like this. // This converts 2009-04-19 00:00:00 into 1240099200 $date_reference_unix = strtotime($date_reference); $previous_date = strtotime("-1 days", $date_reference_unix); $previous_date = date('Y-m-d', $previous_date); echo $previous_date; outputs 1969-12-30 -- Jim Lucas "Some men are born to greatness, some achieve greatness, and some have greatness thrust upon them." Twelfth Night, Act II, Scene V by William Shakespeare -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] pup
Thanks for your idea. -Original Message- From: Phpster [mailto:phps...@gmail.com] Sent: Friday, April 17, 2009 5:39 PM To: Ramesh Marimuthu (WT01 - Telecom Equipment) Cc: ; ; Subject: Re: [PHP] pup On Apr 17, 2009, at 1:06, wrote: > > Thanks Jim. Is there a way to get the value of that unchecked box? > > -rummy > > -Original Message- > From: Jim Lucas [mailto:li...@cmsws.com] > Sent: Friday, April 17, 2009 10:35 AM > To: Ramesh Marimuthu (WT01 - Telecom Equipment) > Cc: geek...@gmail.com; php-general@lists.php.net > Subject: Re: [PHP] pup > > ramesh.marimu...@wipro.com wrote: >> >> Hi, >> >> I'm new to php. >> Say I have a check box which is checked already. Now I need to >> uncheck > >> it and when I press the submit button, I should get the unchecked > value. >> Can anyone help me on this. >> >> One.php >> >> if($qry[0]!=$login_type) >> { >> echo "> style=background-color:#CC66CC>> value=a".$count." checked DISABLED />".$slot_value.""; } >> else { echo "> style=background-color:#00>> value='--user ".$slot_value." --ne ".$nen." --timespec ".$slt."' >> checked >>> ".$slot_value.""; >> } >> >> One.php calls Two.php >> Two.php >> >> $enable_slot= $_POST['enable']; >> $uncheck_slot= $_POST['uncheck']; >> >> if ($enable_slot){ >> echo "$enable_slot"; >> foreach($enable_slot as &$a) { >> echo "".$a." --unreserve"; >> } >> } >> >> I get only the results only if checked. I think I'm doing a mistake >> in > >> the code in red font. >> >> regards, >> -rummy >> >> > > When you uncheck a checkbox in an HTML form, it will not be submitted. > > http://www.w3.org/TR/html401/interact/forms.html#checkbox > > The part on the above page talking about "only "on" checkbox controls > can become successful." is the key here. > > The successful part links here: > > http://www.w3.org/TR/html401/interact/forms.html#successful-controls > > This explains that the definition of a successful checkbox submission > is one that is "on". > To have a checkbox in the "on" state means that it has to be checked. > > So, any checkbox that is /not/ checked is considered "off" or > "undefined" will not be submitted because it is not valid. > > Or something like that... :) > > Jim Lucas > > Please do not print this email unless it is absolutely necessary. > > The information contained in this electronic message and any > attachments to this message are intended for the exclusive use of the > addressee(s) and may contain proprietary, confidential or privileged > information. If you are not the intended recipient, you should not > disseminate, distribute or copy this e-mail. Please notify the sender > immediately and destroy all copies of this message and any > attachments. > > WARNING: Computer viruses can be transmitted via email. The recipient > should check this email and any attachments for the presence of > viruses. The company accepts no liability for any damage caused by any > virus transmitted by this email. > > www.wipro.com > > -- > PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: > http://www.php.net/unsub.php > What I do in this case is define it to unchecked in the php code and then use the ternary operator to test it $checkbox1 = 0; $checkbox1 = (isset($_POST['check1'])) ? 1: 0 ; Bastien Please do not print this email unless it is absolutely necessary. The information contained in this electronic message and any attachments to this message are intended for the exclusive use of the addressee(s) and may contain proprietary, confidential or privileged information. If you are not the intended recipient, you should not disseminate, distribute or copy this e-mail. Please notify the sender immediately and destroy all copies of this message and any attachments. WARNING: Computer viruses can be transmitted via email. The recipient should check this email and any attachments for the presence of viruses. The company accepts no liability for any damage caused by any virus transmitted by this email. www.wipro.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] DATE / strtotime
Thanks Chris. It has been a while since I used this command. Ron On Mon, 2009-04-20 at 13:27 +1000, Chris wrote: > Ron Piggott wrote: > > Where $date_reference is 2009-04-18 the following code gives me a day of > > 1969-12-30. How do I get it to be 2009-04-17? > > > > $previous_date = strtotime("-1 days", $date_reference); > > $previous_date = date('Y-m-d', $previous_date); > > Slightly wrong syntax. > > $previous_date = strtotime("$date_reference -1 days"); >
Re: [PHP] pup
Ashley Sheridan wrote: On Fri, 2009-04-17 at 12:54 -0400, Bob McConnell wrote: From: tedd At 10:43 PM -0700 4/16/09, Jim Lucas wrote: Have your elements setup like such: Room #1 Room #2 Room #3 Room #4 Room #5 Then on your processing page, you know that you have 5 rooms, 1 - 5. With this information you can check to make sure that something exists Jim et al: Try this: Room #1 Room #2 Room #3 Room #4 Room #5 if (isset($_POST['reserve']) ) { foreach ($_POST['reserve'] as $key => $a) { echo("$key $a "); } } Here's the demo: http://www.webbytedd.com//post-array1/index.php Don't forget the on the end of those input lines. I've seen too many pages already where I had to fix that problem. Bob McConnell It shouldn't really be Room #1 but something like this: Room #1 Well, to quote the W3C Recommendation... http://www.w3.org/TR/html401/interact/forms.html#h-17.9.1 First Name Last Name The label tag should reference the input via the for attribute. Identifying the input tag by id attribute value. And using the for attribute of the label tag in conjunction with the id attribute of the input tag, you can separate the label and form element entirely, which is sueful if you still use tables to line up your forms! Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] How do I access a local variable?
On Sun, 2009-04-19 at 21:55 -0400, Paul M Foster wrote: > On Mon, Apr 20, 2009 at 12:54:27AM +0100, abdulazeez alugo wrote: > > > > > Hi guys, > > > > I have a function inside which I set alocal variable to store a result. Can > > I access this variable in another function? if yes then how? > > > > function tbl1($entrytitle, $entrytext) > > > > { > > > > global $conn; > > > > $result= mysql_query("INSERT INTO tbl1(tbl1_id, title, text) > > > > VALUES('NULL', '$entrytitle', '$entrytext')", $conn); > > > > $tbl_id=mysql_insert_id($conn);// this is the local variable I'm > > setting to get the last auto increment id > > > > } > > > > > > > > Now I wish to access that variable in another function thus: > > > > function tbl2($name, $entrytitle, $entrytext) > > > > { > > > > global $conn; > > > > $result =mysql_query("INSERT INTO tbl2(tbl1_id, name, title, text) > > > >VALUES('$tbl1_id', '$name', '$entrytitle', > > '$entrytext' )", $Conn); > > > > } > > > > > > > > Or is there a better way to store the variable? > > If a variable is local to a function, there is no way to access that > variable outside that function. You can pass it back as a return value > from the original function, or make it global (not advised) to make it > visible in other functions. > > Paul > > -- > Paul M. Foster > Or pass it by reference to the functions, so that both are able to make changes to it. Ash www.ashleysheridan.co.uk -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php