[PHP] [JS question] : I want to block onChange event in Firefox...
Hi, I am blocked on this problem since so a long time that I prefer asking here my question... I'd like, if the data isn't correct, that the user stay in the input zone. Everything is ok with IE but not with Firefox. Here is my code : // Validation des données. function demarrage_controles() { if (FF) { document.captureEvents(Event.KEYPRESS); document.captureEvents(Event.CHANGE); document.onkeypress = process_keypress; document.onchange = process_change; } else { document.onkeypress = process_keypress; for (i=0; i < document.forms[0].elements.length ; i++) { document.forms[0].elements[i].attachEvent("onchange",process_change); } } } // On n'accepte que des chiffres. function process_keypress(e) { if (FF) { if (e.target.tagName == "input" && !((e.which > 47 && e.which < 58) || e.which == 0 || e.which == 8 || e.which == 13)) { return false; } } else { if ((window.event.keyCode < 47 || window.event.keyCode > 58) && window.event.keyCode != 13) { return false; } } } // On compare au dernier cumul. function process_change(e) { if (FF) { if (e.target.id.substr(0,3) == "var" && e.target.alt != "") { if (Number(e.target.value) < Number(e.target.alt)) { alert ("Vous ne pouvez pas saisir de données inférieures au dernier cumul !"); e.preventDefault(); e.stopPropagation(); e.returnValue=false; } } } else { if (window.event.srcElement.id.substr(0,3) == "var" && window.event.srcElement.alt != "") { if (Number(window.event.srcElement.value) < Number(window.event.srcElement.alt)) { alert ("Vous ne pouvez pas saisir de données inférieures au dernier cumul !"); window.event.returnValue = false; } } } } My problem comes from the process_change function in Firefox where I put everything I know (stopPropagation etc...) but without success. The user go to the next field. In IE, the window.event.returnValue = false is ok. Do you have any clue ? Thank you very much. David. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Stop process when user close window browser
Hi all, I am using PHP 4.3.2 and MYSQL database. I think this question has been asked many times, however not solutions. The problem is that I have a php script which connect to db and update data to db which took length of time to be completed. However sometimes user accidentally close the window browser or kill the window browser. The php which a server script language will not know that the window browser has been closed , so the program execution is keep running . This will choke the memory in the server and thus choke the web page. So ,are there ways to stop program from executing when user close the browser window. Thanks - weetat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [JS question] : I want to block onChange event in Firefox...
Hi, did you try to open the javascript console in firefox to see if there is any error ? (in the "tools" or "outils" menu). hope this'll help / bon courage N F David BERCOT a écrit : Hi, I am blocked on this problem since so a long time that I prefer asking here my question... I'd like, if the data isn't correct, that the user stay in the input zone. Everything is ok with IE but not with Firefox. Here is my code : // Validation des données. function demarrage_controles() { if (FF) { document.captureEvents(Event.KEYPRESS); document.captureEvents(Event.CHANGE); document.onkeypress = process_keypress; document.onchange = process_change; } else { document.onkeypress = process_keypress; for (i=0; i < document.forms[0].elements.length ; i++) { document.forms[0].elements[i].attachEvent("onchange",process_change); } } } // On n'accepte que des chiffres. function process_keypress(e) { if (FF) { if (e.target.tagName == "input" && !((e.which > 47 && e.which < 58) || e.which == 0 || e.which == 8 || e.which == 13)) { return false; } } else { if ((window.event.keyCode < 47 || window.event.keyCode > 58) && window.event.keyCode != 13) { return false; } } } // On compare au dernier cumul. function process_change(e) { if (FF) { if (e.target.id.substr(0,3) == "var" && e.target.alt != "") { if (Number(e.target.value) < Number(e.target.alt)) { alert ("Vous ne pouvez pas saisir de données inférieures au dernier cumul !"); e.preventDefault(); e.stopPropagation(); e.returnValue=false; } } } else { if (window.event.srcElement.id.substr(0,3) == "var" && window.event.srcElement.alt != "") { if (Number(window.event.srcElement.value) < Number(window.event.srcElement.alt)) { alert ("Vous ne pouvez pas saisir de données inférieures au dernier cumul !"); window.event.returnValue = false; } } } } My problem comes from the process_change function in Firefox where I put everything I know (stopPropagation etc...) but without success. The user go to the next field. In IE, the window.event.returnValue = false is ok. Do you have any clue ? Thank you very much. David. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [JS question] : I want to block onChange event in Firefox...
David BERCOT wrote: Hi, I am blocked on this problem since so a long time that I prefer asking here my question... I'd like, if the data isn't correct, that the user stay in the input zone. Everything is ok with IE but not with Firefox. Search for "javascript mailing list" in your favourite search engine. This is a PHP mailing list. -- 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] Stop process when user close window browser
By default, PHP will also stop execution when the browser is closed. See: http://de.php.net/manual/en/features.connection-handling.php on Friday 30 June 2006 09:06, weetat wrote: > Hi all, > > I am using PHP 4.3.2 and MYSQL database. > I think this question has been asked many times, however not solutions. > > The problem is that I have a php script which connect to db and update > data to db which took length of time to be completed. However sometimes > user accidentally close the window browser or kill the window browser. > The php which a server script language will not know that the window > browser has been closed , so the program execution is keep running . > This will choke the memory in the server and thus choke the web page. > > So ,are there ways to stop program from executing when user close the > browser window. > > Thanks > - weetat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [JS question] : I want to block onChange event in Firefox...
> Hi, > > did you try to open the javascript console in firefox to see if there is > any error ? > (in the "tools" or "outils" menu). Yes I did. No error... I was told to go to a JS list (here, it is a PHP one), so I'll look for one ;-) Thank you / merci. David. > hope this'll help / bon courage > > N F > > David BERCOT a écrit : > > Hi, > > > > I am blocked on this problem since so a long time that I prefer asking here > > my question... > > I'd like, if the data isn't correct, that the user stay in the input zone. > > Everything is ok with IE but not with Firefox. > > Here is my code : > > // Validation des données. > > function demarrage_controles() { > > if (FF) { > > document.captureEvents(Event.KEYPRESS); > > document.captureEvents(Event.CHANGE); > > document.onkeypress = process_keypress; > > document.onchange = process_change; > > } else { > > document.onkeypress = process_keypress; > > for (i=0; i < document.forms[0].elements.length ; i++) { > > > > document.forms[0].elements[i].attachEvent("onchange",process_change); > > } > > } > > } > > // On n'accepte que des chiffres. > > function process_keypress(e) { > > if (FF) { > > if (e.target.tagName == "input" && !((e.which > 47 && e.which < > > 58) || e.which == 0 || e.which == 8 || e.which == 13)) { > > return false; > > } > > } else { > > if ((window.event.keyCode < 47 || window.event.keyCode > 58) && > > window.event.keyCode != 13) { > > return false; > > } > > } > > } > > // On compare au dernier cumul. > > function process_change(e) { > > if (FF) { > > if (e.target.id.substr(0,3) == "var" && e.target.alt != "") { > > if (Number(e.target.value) < Number(e.target.alt)) { > > alert ("Vous ne pouvez pas saisir de données > > inférieures au dernier cumul !"); > > e.preventDefault(); > > e.stopPropagation(); > > e.returnValue=false; > > } > > } > > } else { > > if (window.event.srcElement.id.substr(0,3) == "var" && > > window.event.srcElement.alt != "") { > > if (Number(window.event.srcElement.value) < > > Number(window.event.srcElement.alt)) { > > alert ("Vous ne pouvez pas saisir de données > > inférieures au dernier cumul !"); > > window.event.returnValue = false; > > } > > } > > } > > } > > My problem comes from the process_change function in Firefox where I put > > everything I know (stopPropagation etc...) but without success. The user go > > to the next field. In IE, the window.event.returnValue = false is ok. > > > > Do you have any clue ? > > > > Thank you very much. > > > > David. > > > > > > > > --- > Orange vous informe que cet e-mail a ete controle par l'anti-virus mail. > Aucun virus connu a ce jour par nos services n'a ete detecte. > > > > [ (pas de nom de fichier) (0.1 Ko) ] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] �Թ����ʹ͡����µ��-����Ѻ����ӧҹ��Ш��������Ңͧ�Ԩ������ͼ�������ҡ�����˹���ѵ���ôԵ�����Թ��������Ҵ͡ᾧ
ÃÃ¹à ªÃèÃ´Ã¡à ºÃéõèÃ-ÃÃÃÃú¼Ãé·Ã§Ã¹»ÃèÃÃÃÃÃà ¨éâç¡Ã¨¡ÃÃÃÃÃüÃé·ÃèÃÃÃ¡à ¤ÃÃÃùÃéºÃµÃà ¤Ã´ÃµÃÃÃÃÃÃ¹à ªÃèÃà ¡èÃ´Ã¡á¾§æ ´éÃÃÃÃ¹à ªÃèÃ´Ã¡à ºÃé÷Ãèµèà 0.69 - 0.99% äÃèÃäèøÃÃÃà ¹ÃÃÃ㹡ÃÃãªéÃ§à §Ã¹ ¨ÃạÃÃÃÃùÃéÃç ´Ã¡à ºÃéÃá¾§ÃÃÃè·Ãäà ã¹à ÃÃèÃÃ֍à à Ãá·Ãè´Ã¡Ãèà âùùÃéºÃµÃà ¤Ã´ÃµÃÃÃÃÃÃ¹à ªÃèà Ãø¹Ã¤ÃþóêÃì ·Ãè´Ã¡à ºÃéõèáÃèà ¤Ã³Ãúõâç¼ÃéÃÃäà - à ¨éâç¡Ã¨¡ÃÃ/¢éÃÃê¡ÃÃ/ÃðÃÃÃÃáè ÃÃÃþ¹Ã¡§Ã¹»Ãèà - ºÃ¤¤à ·ÃèÃä»·ÃèÃÃÃÃÃä´é»ÃèÃäÃèµéçÃÃÃù·ÃþÃì ÃÃÃà ºÃ¤¤à ¤éûÃáù - ¼ÃéÃÃäÃà ¡èÃäÃèà ¤Ã¶Ã¡»Ãú 㹡ÃêÃÃÃà §Ã¹ã¹ªèçà Ãà à 6 à ´Ãù·Ãè¼èùÃà - ÃÃà ºÃÃìâ·ÃÃþ·ìºéù - ÃõÃÃ´Ã¡à ºÃéöáÃá ¤Ã¹Ã³áºº à ´µé¹à ´´Ã¡ (0.69 - 0.99%/à ´Ãù) - ÃÃÃÃö¡Ãéä´é 5 à ·èâçÃÃÃä´é ÃÃÃÃÃçÃô 1,500,000 ºÃ· - ¼èùªÃÃÃẺúÃÃæ 12 - 60 à ´Ãù - ¶éêÃÃõçà Ãà Ãã¹»Ãáá »Ã¶Ã´ä»à ´´Ã¡à ºÃéÃÃá»Ãà à 0.25% - ÃÃÃÃö»Ã´Ã§à §Ã¹·Ãèà Ãà ÃÃä´é¡èù¡Ãù´Ãà ç¨Ã¡ 1 »à â´ÃäÃè¤Ã´´Ã¡à ºÃéÃà à à 1. ¼ÃéÃúõÃà ¤Ã´Ãµ ÃÃÃÃÃÃÃÃ¹à ªÃèúä¤à ¢Ã§·Ã¡Ã¶ÃºÃ¹ - ùÃÃõ÷ù·Ãà ·èÃ¡ÃºÃ§à §Ã¹ÃçÃô㹺õà ÃÃÃÃÃ§à §Ã¹ÃÃ¹à ªÃè÷ÃèÃéçÃçÃà - äÃèà ªç¤ÃÃÃÃùÃéÃù¢Ã§·èù - äÃèµéçãªéÃà Ã»à §Ã¹à ´Ãù ÃÃÃà Ãà µ·à Ãé¹·ì - äÃèµéçÃúä¤à ÃÃÃÃÃà á·ÃþÃì¤éûÃáù - ¡ÃÃÃÃäçèÃà æ à áÃÃûÃáúäÃèÃÃè§Ãá à áÃÃûÃáú¡ÃÃÃÃäà - ÃÃà ¹ÃºÃµÃ»Ãêê¹ áà ÃÃÃà ¹Ã·Ãà ºÃùºéù - ãºá¨é§Ã¹ÃéºÃµÃà ¤Ã´ÃµÃÃÃÃÃÃ¹à ªÃèõÃèÃÃ§à ´Ãùà èÃÃôÃÃÃÃÃéùäÃèà ¡Ã¹2à ´Ãù - ÃÃà ¹ÃÃÃô¸¹Ã¤ÃÃùéÃáá·Ãè¨ÃãÃ鸹äÃÃâÃ¹à §Ã¹à ¢éà - ãºà »à ÃèùªÃèÃáÃà (¶éÃÃÃ) 2. ÃÃÃÃú¼Ãé·ÃèäÃèÃÃÃÃÃÃäÃèÃéçÃçºÃµÃà ¤Ã´ÃµÃÃÃÃÃÃ¹à ªÃèÃà ´Ãà - ÃÃÃä´éÃÃà 10,000 áà à 15,000 º./à ´Ãù¢Ãé¹ä» - ÃÃÃÃÃºà ¨éâç¡Ã¨¡ÃÃÃÃÃä´é 20,000 º./à ´Ãù¢Ãé¹ä» - ÃõÃÃ´Ã¡à ºÃéÃ¤Ã¹Ã³áººà ´µé¹à ´´Ã¡(à Ãà ÃÃäÃè¶Ã§1%µèÃà ´Ãù) - ÃÃÃÃö¡Ãéä´é 5 à ·èâçÃÃÃä´éµèÃà ´Ãù ¡Ãéä´é¶Ã§ 1,500,000 ºÃ· - ÃÃÃÃö¼èùªÃÃÃä´é µÃé§áµè 1 Ȉ - 5 Ȉ - à ÃÃèêÃÃõçà Ãà à »Ã¶Ã´ä»à ´ÃõÃÃ´Ã¡à ºÃéÃà §Ãá 0.25%-1% à áÃÃûÃáú¡ÃÃÃÃäà o ÃÃà ¹ÃºÃµÃ»Ãêê¹ áà ÃÃÃà ¹Ã·Ãà ºÃùºéù o Ãà Ã»à §Ã¹à ´Ãù ÃÃÃÃùçÃÃÃÃúÃÃ§à §Ã¹à ´Ãù(µÃèÃçäÃèà ¡Ã¹2à ´Ãù) o ÃÃà ¹ÃºÃªÃÃÃ÷ÃþÃìÃéùÃà ç 3 à ´Ãù(µèÃà ¹Ãèç¨Ã¡»Ã¨¨ÃºÃ¹) o ÃÃà ¹ÃÃÃô ¸.ùéÃáá·ÃèÃúêÃèø¹Ã¤ÃÃ-à à ¢ºÃªÃ-ªÃèüÃéÃÃäÃà ¾ÃèÃâÃ¹à §Ã¹à ¢éà o ãºà »à ÃèùªÃèÃáÃà (¶éÃÃÃ) 3. ÃÃÃÃÃºà ¨éâç¡Ã¨¡ÃÃ(·Ãà ºÃù¡ÃäéÃ-è¡.-º.Ãà Ã) - ÃÃà ¹ÃºÃµÃ»Ãêê¹ áà ÃÃÃà ¹Ã·Ãà ºÃùºéù - ÃÃà ¹Ã¡Ãè´·Ãà ºÃù¡ÃäéÃ(ÃÃºà ´·äÃèà ¡Ã¹6à ´Ãù) - ÃÃà µ·à ù·ìÃéùÃà ç 6 à ´Ãù - ÃÃà ¹ÃÃÃô ¸.ùéÃáÃ¡à ¾ÃèáÃÃâÃ¹à §Ã¹à ¢éúêà - ÃÃà ¹ÃºÃªÃÃÃêÃèüÃé¶ÃÃÃÃé¹ (¶éÃÃÃ) µÃÃÃÃèç à §Ã¹ÃÃ¹à ªÃèÃ
[PHP] Downloading page
Hi all... I'm interesting in a page (using PHP script) in internet, and I'd like to download that page with the complete script. the question is: Can I..? and How..? thank for your input... Best Regards BBC **o<0>o** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Downloading page
BBC wrote: Hi all... I'm interesting in a page (using PHP script) in internet, and I'd like to download that page with the complete script. the question is: Can I..? and How..? thank for your input... No you can't. And I thank $DEITY for that. If you really want the source code contact the website in question and ask them nicely. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] bug in php 5.1.4
Hi, I' ve discovered a bug in PHP 5.1.4. This version of PHP create a new session everytime you refresh the same php page or that you switch from 1 page to another page. I downgraded it to PHP 5.1.2 and it works correctly. It could be interesting to fix this bug. if you want moredetail, contact me. Alain
Re: [PHP] bug in php 5.1.4
There must be a special code in your script that causes it like this bug: http://bugs.php.net/bug.php?id=37926 on Friday 30 June 2006 11:39, Alain Roger wrote: > Hi, > > I' ve discovered a bug in PHP 5.1.4. This version of PHP create a new > session everytime you refresh the same php page or that you switch from 1 > page to another page. > I downgraded it to PHP 5.1.2 and it works correctly. > It could be interesting to fix this bug. > > if you want moredetail, contact me. > > Alain -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] bug in php 5.1.4
Alain Roger wrote: > Hi, > > I' ve discovered a bug in PHP 5.1.4. This version of PHP create a new > session everytime you refresh the same php page or that you switch from 1 > page to another page. > I downgraded it to PHP 5.1.2 and it works correctly. > It could be interesting to fix this bug. if it is a bug it sounds like it's rather critical! > > if you want moredetail, contact me. you might want to post a small repro script to internals to illustrate the problem... if you do you better off asking if it is a bug rather than declaring it to be so. chances are that you'll be asked to make a report at bugs.php.net if someone sees merit in your observation. > > Alain > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop process when user close window browser
Hi Thomas, Yes. I read the manual regarding the connection handling. However ,in my php program , the execution did not stop , because i have logger which log sql statement "INSERT" statement when inserted data to database is ok . When i close the browser , the sql execution still running, statement is logged. Any idea how to stop it ? Because it cause my web page to be slow. Thanks. Thomas Munz wrote: By default, PHP will also stop execution when the browser is closed. See: http://de.php.net/manual/en/features.connection-handling.php on Friday 30 June 2006 09:06, weetat wrote: Hi all, I am using PHP 4.3.2 and MYSQL database. I think this question has been asked many times, however not solutions. The problem is that I have a php script which connect to db and update data to db which took length of time to be completed. However sometimes user accidentally close the window browser or kill the window browser. The php which a server script language will not know that the window browser has been closed , so the program execution is keep running . This will choke the memory in the server and thus choke the web page. So ,are there ways to stop program from executing when user close the browser window. Thanks - weetat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Downloading page
BBC a écrit : Hi all... I'm interesting in a page (using PHP script) in internet, and I'd like to download that page with the complete script. the question is: Can I..? Hi, you can't directly. you have to ask the webmaster of the site. but the source code won't be helpfull if the script requires other scripts/packages/etc, and a webmaster won't give you the code of his page unless it's very simple. (for security reasons). N F and How..? thank for your input... Best Regards BBC **o<0>o** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop process when user close window browser
What kind of connection you use ( persistent ?) and which PHP and MySQL version? Normaly, PHP exit after the browser gets closed, but sended SQL to MySQL get finished executed. on Friday 30 June 2006 11:54, weetat wrote: > Hi Thomas, > >Yes. I read the manual regarding the connection handling. >However ,in my php program , the execution did not stop , because i > have logger which log sql statement "INSERT" statement when inserted > data to database is ok . > > When i close the browser , the sql execution still running, statement is > logged. > > Any idea how to stop it ? Because it cause my web page to be slow. > > Thanks. > > Thomas Munz wrote: > > By default, PHP will also stop execution when the browser is closed. See: > > > > http://de.php.net/manual/en/features.connection-handling.php > > > > on Friday 30 June 2006 09:06, weetat wrote: > >> Hi all, > >> > >> I am using PHP 4.3.2 and MYSQL database. > >> I think this question has been asked many times, however not > >> solutions. > >> > >> The problem is that I have a php script which connect to db and update > >> data to db which took length of time to be completed. However sometimes > >> user accidentally close the window browser or kill the window browser. > >> The php which a server script language will not know that the window > >> browser has been closed , so the program execution is keep running . > >> This will choke the memory in the server and thus choke the web page. > >> > >> So ,are there ways to stop program from executing when user close the > >> browser window. > >> > >> Thanks > >> - weetat -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] [NEWBIE] PHP General List Guide & Other Good Stuff
[snip] This was listed in another thread but I think would be a great tool and online refference for any one who is programming in PHP and especially for NEWBIES. http://www.hudzilla.org/phpbook/ [and snip] > "If you have a question about any of the pear packages, join the > appropriate list here: http://pear.php.net/support/lists.php"; [/end snippage] I will include both next time. Cool stuff...;. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop process when user close window browser
weetat wrote: Hi Thomas, Yes. I read the manual regarding the connection handling. However ,in my php program , the execution did not stop , because i have logger which log sql statement "INSERT" statement when inserted data to database is ok . When i close the browser , the sql execution still running, statement is logged. Any idea how to stop it ? Because it cause my web page to be slow. PHP doesn't know the browser has gone away until it tries to write something to it. So if you are inside a long-running SQL-query and the browser drops, nothing will happen until the query call returns and you try to write something. -Rasmus -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [NEWBIE] PHP General List Guide & Other Good Stuff
At 9:16 AM +1000 6/30/06, Chris wrote: >Jay Blanchard wrote: >>Recommended reading >> >>http://zirzow.dyndns.org/php-general/NEWBIE > >Should we add a link to the pear support page for pear related questions? > >Something as simple as: > >"If you have a question about any of the pear packages, join the appropriate >list here: http://pear.php.net/support/lists.php"; In similar fashion, "If you have a question about MySQL, join the appropriate list here: http://lists.nyphp.org/mailman/listinfo/mysql"; tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] [NEWBIE] PHP General List Guide & Other Good Stuff
At 4:45 PM -0700 6/29/06, Scott Heinrichs wrote: >This was listed in another thread but I think would be a great tool >and online refference for any one who is programming in PHP and >especially for NEWBIES. >http://www.hudzilla.org/phpbook/ > Also, in similar fashion: http://www.htmlgoodies.com/beyond/php/article.php/3472391 http://www.w3schools.com/php/default.asp http://www.weberdev.com/ViewArticle/433 http://www.weberdev.com/Manuals/ http://www.unf.edu/~rita0001/eresources/php_tutorials/index.htm There's lot's of links we could add to the NEWBIE guide -- it makes sense, doesn't it? tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] [NEWBIE] PHP General List Guide & Other Good Stuff
[snip] Also, in similar fashion: http://www.htmlgoodies.com/beyond/php/article.php/3472391 http://www.w3schools.com/php/default.asp http://www.weberdev.com/ViewArticle/433 http://www.weberdev.com/Manuals/ http://www.unf.edu/~rita0001/eresources/php_tutorials/index.htm There's lot's of links we could add to the NEWBIE guide -- it makes sense, doesn't it? [/snip] Yes, but how many is too much when we are trying to teach folks how to fish? We could buy books and distribute them too (think Gideon's of PHP) :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple "if()" statements
At 11:07 PM -0600 6/29/06, John Meyer wrote: >Larry Garfield wrote: >> >>switch is fine if your elseif comparisons are equality based. If they're not >>equality based, then they don't map to switch as well. > >In other words, if you look at a logical ladder as the roots of the tree, as >long as each root has the same number of forks (say each fork ends only one >way), your fine with a switch. If you have one, however, that has only one >condition, and another that has two, then you need an if...elseif logic tree. Interesting -- can you give me an example? Perhaps I'm showing my ignorance, but I never ran into an elseif problem that I couldn't better solve (for me) with a switch. I've never *had* to use one. tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] creating a threaded message system--sorting messages
On Jun 30, 2006, at 12:05 AM, Larry Garfield wrote: I've written such a system before more than once. You do the sorting in SQL, and then traverse the data recursively in PHP to build the tree. It's a single SQL query. Check the archives for this list for about 3-4 weeks ago, I think. We were just discussing it, and I showed some basic code examples. :-) -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 Did you mean this thread, Larry? --> http://news.php.net/php.general/238478 (on menus and submenu generation) Seems pretty identical to what I'm trying to do. Thanks and disregard my previous post if this is so. - Ben smime.p7s Description: S/MIME cryptographic signature
Re: [PHP] creating a threaded message system--sorting messages
Hi Larry, Thanks for the help. I was just coming to a similar conclusion last night after reading the warnings on this thread about querying the database recursively. I guess my test data with 7 posts is not a rigorous simulation. :-) I've looked through the posts on the PHP general list going back about 3-6 weeks and can't find the thread you speak of. I searched by your name assuming that you posted into the thread and searched by the string "recursive" and "recursion". If you could steer me to it in some other way (subject of the thread or subject word) I would appreciate it, but only if it is not too much trouble. I can take a go at it now that the basic approach is carved out: query once, recurse the data in PHP. Thanks, Ben On Jun 30, 2006, at 12:05 AM, Larry Garfield wrote: I've written such a system before more than once. You do the sorting in SQL, and then traverse the data recursively in PHP to build the tree. It's a single SQL query. Check the archives for this list for about 3-4 weeks ago, I think. We were just discussing it, and I showed some basic code examples. :-) -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 smime.p7s Description: S/MIME cryptographic signature
Re: [PHP] Re: Find out cookies on a computer?
Adam Zey wrote: > Peter Lauri wrote: >> Is it possible to some how find out all cookies on a specific computer >> and >> their name and value? I assume not :) >> >> >> >> /Peter >> > > No, because you don't OWN them, therefore you have no right (either > technologically or ethically) to see them. the 'right' that he has to see them (or others have to see his cookies) has nothing to do with whether it is technically possible. the HTTP specifications state that a site should only have access to cookies set within it's own domain - so in a perfect world Peter doesn't have access. BUT: 1. security flaws in browsers (and/or webservers?) can (and have) occassionally make cookies available to third parties unintentionally. 2. cross-site-scripting (XSS) hacking techniques are capable of stealing cookie data from third parties. you can't do much about 1. but you can take measures to protect your site from XSS. http://www.phpsec.org is a great place to learn more about XSS and other security issues. > Asking such unethical > questions on this list is, well, pretty dumb. there are no unethical questions and to presume that Peter is out to steal other peoples cookies is shortsighted - there is no evidence to back this up... turn it around - maybe he wanted to know if it was possible for other people/sites to view *his* cookies. the ethical issue arises if Peter would try to read cookies that don't belong to him/his site. I feel it was unfair to insinuate dumbness; if you want to call people dumb why not take it out on "Suresh 'I have one problem, awaiting you reply asap' Kumar"? he's an easy target and apparently doesn't even know of the eixstence of the 'Reply' button ;-) (okay so that last bit was unfair - pot calling the kettle black heh :-P) > > Regards, Adam. > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop process when user close window browser
At 5:54 PM +0800 6/30/06, weetat wrote: >Hi Thomas, > > Yes. I read the manual regarding the connection handling. > However ,in my php program , the execution did not stop , because i have > logger which log sql statement "INSERT" statement when inserted data to > database is ok . > >When i close the browser , the sql execution still running, statement is >logged. > >Any idea how to stop it ? Because it cause my web page to be slow. > >Thanks. It must be one heck of a involved statement to cause your web site to slow down. All my MySQL request are very quick. Just curious, how do you know your "web page to be slow" when you close your browser? tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] [NEWBIE] PHP General List Guide & Other Good Stuff
At 8:09 AM -0500 6/30/06, Jay Blanchard wrote: >[snip] >Also, in similar fashion: > >http://www.htmlgoodies.com/beyond/php/article.php/3472391 >http://www.w3schools.com/php/default.asp >http://www.weberdev.com/ViewArticle/433 >http://www.weberdev.com/Manuals/ >http://www.unf.edu/~rita0001/eresources/php_tutorials/index.htm > >There's lot's of links we could add to the NEWBIE guide -- it makes >sense, doesn't it? >[/snip] > >Yes, but how many is too much when we are trying to teach folks how to >fish? We could buy books and distribute them too (think Gideon's of PHP) >:) Point well taken -- but how about placing one link to the "best" reference? We can decide on which one is the best later. At least we can say "Did you read the intro?" or "Please read the intro." when dealing with very basic questions. tedd PS: But, I did like the "buy and distribute books" thing. Put me first on that list -- I'll add it to the other dozens of php books I've read and can't remember. -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] design?
On 6/29/06, Sjef <[EMAIL PROTECTED]> wrote: Hi there, Hi Sjef, First off, I think David has a good point with regards to the OO vs Procedural approach. If you're looking to do this quick and easy, it might not be worth your time fussing with OO. Unless you'd like to just for the exercise, which I wholly support, so go for it! I want to create a class Question for dealing wiht the questions and a class answer for the answers. Each could contain an array with the their part of the content of the database table. As far as how to design it OO-style, I'd first urge you *not* to have separate classes managing lists of questions and answers. Say for example you query your db for questions, build up your array inside your questions class, and then while doing the same for your answers class, you inadvertently introduce a looping bug that drops one of the answers from the array, or possibly changes the order that you create your array, or any other number of possible mistakes (human or otherwise). Point is, in the end you'd have two out-of-synch classes that really should've been built separately to begin with. A single question and it's answer(s) are tied together, so keep it that way in your class abstraction. That said, I'd suggest building a question-answer *pair* as a class, and then you'd have an array of these question-answer pairs representing your entire list (which could be encapsulated into a container class if you wished). You could, to be even more abstract, create base question and answer classes to represent the most basic type of question or answer, and then hold individual, **related** instances of these within your question-answer pair class. Do you see the difference? You could even take it a step further and build derivatives of your base answer class to represent different types (string, multiple choice with one answer, multiple choice with many answers, etc)...But I'm sure I'm already getting far ahead of your original design. But David started it! :) HTH, John W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] creating a threaded message system--sorting messages
On Friday 30 June 2006 07:19, Ben Liu wrote: > Hi Larry, > I've looked through the posts on the PHP general list going back > about 3-6 weeks and can't find the thread you speak of. I searched by > your name assuming that you posted into the thread and searched by > the string "recursive" and "recursion". If you could steer me to it > in some other way (subject of the thread or subject word) I would > appreciate it, but only if it is not too much trouble. I can take a > go at it now that the basic approach is carved out: query once, > recurse the data in PHP. Well I checked my Sent file and apparently it somehow got sent to just one person rather than the entire list. I HATE it when that happens. Here's a copy of it below. *sigh* -- Forwarded Message -- Subject: Re: [PHP] How do I make a HTML tree for a set of nodes? Date: Sunday 04 June 2006 12:38 From: Larry Garfield <[EMAIL PROTECTED]> To: [EMAIL PROTECTED] On Sunday 04 June 2006 11:27, Niels wrote: > This sounds fine -- recursion is obviously the way to go. Where can I see > your function? > > I tried several different solutions over the last couple of hours, and I've > settled on only using indentation (like a nested list), not a > fancy graph with antialised branches. It's the simplest possible recursion > but I like the results, even if it's a bit harder to grasp without > connections clearly marked. > > > function tree($nodes, $start, $indent=-30) { > $indent+=30; > global $tree; > foreach ($nodes as $nodeID => $node) { > if ($node['parent']!=$start) {continue;} > $tree.=" style='margin-left:{$indent}px'>{$node['name']}"; tree($nodes, > $nodeID, $indent); > } > return $tree; > } Yep, you're on the right track here. If your tree is a directed acyclic graph (read: every node has at most one parent, and never loops back on itself), then it's quite easy to do with one SQL table and one SQL query. (Or similar, if you're not using SQL, but I've done this many times in SQL.) First, fetch a list of all nodes, in whatever sort order you want (say, alphabetical), ignoring the nesting. You want an array of records (an SQL result works, or an array of objects, or an array of arrays), where each record has at minimum its own ID and its parent ID (0 meaning it's a root node), and some sort of label. Then, starting at parentid=0, iterate over the list and process just those with that parent id. "Process" means, in this case, for example, to print out a list item with the name, save the current cursor, and call the function again recursively with the id of the active node as the new parent node. When you return, reset the cursor. The cursor stuff is so that you can pass the array by reference rather than by value and not waste a ton of memory. So the pseudo-code would look something like: function foo(&$nodes, $parentid) { reset($nodes); foreach ($nodes as $node) { if ($node's parent is $parent id) { $output .= "" . $node (or whatever portion of it you want) . foo($nodes, $node's id) . ""; } } if ($output) return "$output"; } $nodes = get_my_nodes(); $list = foo($nodes, 0); There's probably a small bug in the above somewhere since I haven't tested it, and it would vary a bit if you're operating on an SQL result directly, but that's the basic idea. The advantage is that you get HTML that is structurally representative of the relationship, as well as pre-styled for you by default by any browser. > Thanks, > > Ben > > On Jun 30, 2006, at 12:05 AM, Larry Garfield wrote: > > I've written such a system before more than once. You do the > > sorting in SQL, > > and then traverse the data recursively in PHP to build the tree. > > It's a > > single SQL query. Check the archives for this list for about 3-4 > > weeks ago, > > I think. We were just discussing it, and I showed some basic code > > examples. :-) > > > > -- > > Larry Garfield AIM: LOLG42 > > [EMAIL PROTECTED] ICQ: 6817012 -- Larry Garfield AIM: LOLG42 [EMAIL PROTECTED] ICQ: 6817012 "If nature has made any one thing less susceptible than all others of exclusive property, it is the action of the thinking power called an idea, which an individual may exclusively possess as long as he keeps it to himself; but the moment it is divulged, it forces itself into the possession of every one, and the receiver cannot dispossess himself of it." -- Thomas Jefferson -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple "if()" statements
On 6/30/06, tedd <[EMAIL PROTECTED]> wrote: At 11:07 PM -0600 6/29/06, John Meyer wrote: >Larry Garfield wrote: >> >>switch is fine if your elseif comparisons are equality based. If they're not equality based, then they don't map to switch as well. > Not true. I've come to really appreciate the structure of switches. What helps to "unlock" their power is that you don't *have* to compare your switch() param with your case() params. Building on Paul's good advice of splitting logic from presentation: [code] $display_name = ''; switch('set_display_name') { case($row[1] == 'none'): case($row[1] == $row[2]): $display_name = $row[0] . ' ' . $row[2]; break; default: $display_name = $row[0] . ' (' . $row[1] . ') ' . $row[2]; break; } // now print table, using $display_name [/code] HTH, John W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Templates, PHP Frameworks, and DB Abstraction?
I'd like to get some feedback on what the list thinks is a good template engine other than smarty. I'd also like to do some quick prototyping using a PHP framework does anyone have any recommendations for one that is easy to pick up and run with? Finally, does anyone have any suggestions for a good PHP database abstraction library? Thanks for any help! -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] apc and ZendPlatform
We're running Zend Platform on a server that also has apc installed; we're using apc in the scripts to cache data, and I understand (I think) that it also does bytecode caching. Zend Platform includes a php accelerator, which (I think) is also caching bytecode. Does anybody know if we'll see adverse effects from this? apc comes with a cool page (apc.php) that shows information about its cache. While it shows that scripts are being cached, it's showing 0 hits for all of them. That seems wrong to me, but I may be mis-understanding it. Does anybody have any insight? Thanks in advance, Rick -- Rick Emery "When once you have tasted flight, you will forever walk the Earth with your eyes turned skyward, for there you have been, and there you will always long to return" -- Leonardo Da Vinci -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop process when user close window browser
On the other hand, you can tell the web server that the browser has been closed or the page has 'exited'. Not 100% reliable, but in theory you could use the "onUnload" (think that was it) event for a web page that does something sloppy like spawn a popup window that hits a PHP script that then checks MySQL processes or something. Not a great solution, but if you really need some kind of feedback to the server if someone leaves a page, that may be one way to do it. Also, another thing to think about, don't confuse an active query and an active database connection. What you may be seeing is just the database connection still active. You can use the database query "show processlist" to see if the connection is just open or there's actually a query still running. -TG = = = Original message = = = weetat wrote: > Hi Thomas, > > Yes. I read the manual regarding the connection handling. > However ,in my php program , the execution did not stop , because i > have logger which log sql statement "INSERT" statement when inserted > data to database is ok . > > When i close the browser , the sql execution still running, statement is > logged. > > Any idea how to stop it ? Because it cause my web page to be slow. PHP doesn't know the browser has gone away until it tries to write something to it. So if you are inside a long-running SQL-query and the browser drops, nothing will happen until the query call returns and you try to write something. -Rasmus ___ Sent by ePrompter, the premier email notification software. Free download at http://www.ePrompter.com. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] apc and ZendPlatform
Rick Emery wrote: > We're running Zend Platform on a server that also has apc installed; > we're using apc in the scripts to cache data, and I understand (I think) > that it also does bytecode also often referred to as 'opcode' caching > caching. correct. > > Zend Platform includes a php accelerator, which (I think) is also > caching bytecode. AFAIK also correct. > > Does anybody know if we'll see adverse effects from this? only if you turn on both accelerators (opcode caches) - at least trying to run both is more than likely to open up a whole can of worms and leave your webpages fairly blank. I can't see how they could work together and given that they do the same job (as far as opcode caching is concerned) there is nothing to be gained from running both (for opcode caching) > > apc comes with a cool page (apc.php) that shows information about its > cache. While it shows that scripts are being cached, it's showing 0 hits > for all of them. That seems wrong to me, but I may be mis-understanding it. > > Does anybody have any insight? check what phpinfo() is saying about your apc settings. my guess is apc.cache_by_default is set to false and apc.filters is empty ... which affectively means no files will be cached ... it could be then the zend platform is forcefully setting this at start up to avoid a conflict/crash/segfault/whatever. > > Thanks in advance, > Rick > --Rick Emery > > "When once you have tasted flight, you will forever walk the Earth > with your eyes turned skyward, for there you have been, and there > you will always long to return" > -- Leonardo Da Vinci > > --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] design?
How about answer extends question? -Original Message- From: David Tulloh [mailto:[EMAIL PROTECTED] Sent: Friday, June 30, 2006 9:36 AM To: Sjef Cc: php-general@lists.php.net Subject: Re: [PHP] design? Sjef wrote: > Hi there, > > I am starting a new, very small project. A simple question and answering > form. In one screen, question and answer can be typed, the strings will be > saved in a database table questions which holds question and answer (as > there is only one answer to a question). There will be a webpage displaying > all the questions, clickable to the webpage of the answer to the question > clicked. > > I want to create a class Question for dealing wiht the questions and a class > answer for the answers. Each could contain an array with the their part of > the content of the database table. The class Question manages the class > Answer, so when instantiating the Question, the Answer will follow. > Beside of this I want to create a 'visual' component class that creates the > lists as displayed on the webpage. > > Is this a good idea? Or should I not bother, and just create one class > Question that also deals with the Answers. > You have essentially three pages: one that displays a form and inputs the entered data to a database; one that gets a list of questions from the database; one that displays a specific question/answer pair. As a ballpark estimate, I'd say that the above should be possible in under 100 lines of PHP code. You are looking at creating a Question class, an Answer class and a Visual/List class. The net result being that you double the number of PHP files and considerably increase the amount of code, there isn't much opportunity for code reuse here. Now, if the objective is to play with php OOP then go ahead. I would even suggest a DB class, a TableRow class, the Question and Answer then inherit from the TableRow, a TableRows class from which your List class would inherit. Maybe throw a few in to control the templates etc. as well. If the objective is just to get the job done and the site out, I don't see why you should bother with OOP at all. David -- 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] Re: creating a threaded message system--sorting messages
Dan McCullough wrote: I've come into this discussion pretty late so please bear with me if I go over something that has been ruled out. You are trying to print out in a threaded method the first post in a thread followed by each post after that, that is a child/reply to that post. Is that correct? So something like Example 1 Thread1 Post1 Post2 Post3 Post4 . or Example 2 Thread1 Post1 Post2 - reply to post 1 Post3 - reply to post 2 Post4 - reply to post 1 Post5 - reply to post 1 Post6 - reply to post 2 Post7 - reply to post 3 Not a valid example, because there is no guaruntee that the posts are in order. In your example, the order could easily be: Thread 1 Post 1 Post 6 Post 7 Post 2 Post 3 Post 4 Post 5 Since somebody can reply to any leaf in the tree at any time. Example 1 is very common and is the easiest to implement. From what I remember you would need a couple of DB tables for post, post_thread, post_post, thread So for your question thread isnt very relative but I thought I would throw it in. thread { threadid int(11) auto_increment, threadname threadsort ... thread_post { threadid int(11) postid int(11) Tables that serve only to tie two other tables together are a waste. I suggest you look up your normal forms again. But to sum up the reasoning, there is no point to have thread_post because you can simply have a "threadid" field in the "post" table, because it's a one-to-many relationship. A post can't belong to more than one thread. post { postid int(11) auto_increment, postname posttext ... post_post postid int(11), postid2 int(11) Same thing, I think. A post can't have more than one parent, so you might as well put the parent id into the post table. Unless you have one "post_post" row for every parent that a post has. This spams the database like nobody's business, but makes queries easier. Please note I have two kids fighting over the cat, trying to cook dinner and stave off a flood of water from the rising river so the SQL structure is for example. You can get everything in one query from the DB and lay it out based on the id of the post, if you DB is properly indexed and setup and queries are optimized you'll hardly notice a blip when the load gets up. You do not want to be doing multiple queries on a page when one well written query will do the trick. I'm not seeing it. Unless you have a many to many relationship on post_post, you're going to need multiple queries. Unless I'm missing some SQL syntax that allows references to previously found rows. It's been a long while since I did advanced SQL queries. I think your example relies on getting everything in one query by getting all posts with the same threadid, and then sorting by ID, but the problem is that we don't want to sort posts by ID, since a higher ID might could easily go before a post with a lower ID based on where people replied. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Templates, PHP Frameworks, and DB Abstraction?
> Finally, does anyone have any suggestions for a good PHP database > abstraction library? PHP5 has PDO for database abstraction; check the manual for information on that one. If you're stuck with PHP4 then PEAR has several offerings: http://pear.php.net/package/DB/ http://pear.php.net/package/MDB2/ I've used PEAR DB and never had problems with it. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Re: creating a threaded message system--sorting messages
Thanks to everybody who posted on this thread. I wanted to post back the solution I came up with after removing the DB query from the recursion. In case anyone else is trying to accomplish the same thing, this is how I solved it (criticisms welcome, and note that I have not tested it extensively yet): DB structure table: discussion_posts post_id (auto increment, unique, primary index) parent_id (post_id corresponding to this post's parent) discussion_id (to allow multiple discussions, not required but I added a discussions member_id (to identify the post to the particular member posting the post) table as well to store the discussion description and unique ID for each discussion) dt_posted (date/time the post was posted) subject (title of the particular post) post_text (substance of the post) So the user selects a particular discussion from a list of discussions. We query the database for the post_id of the first post in the discussion requested, this post will have a parent_id of '0' or NULL since it has no parent. We then query the DB for all the posts in the discussion joining the members table using member_id to grab the member's first and last name (or any other member info desired). We order this query info by dt_posted. We then write the contents of our second query into a two-dimensional array ($workArr): while ([EMAIL PROTECTED]($result)) { foreach ($row as $key => $value) { if ($key=="post_id") $numerKey=value; $workArr[$key][$numerKey]=$value; } } The processing of the threads into proper order looks like this: function processthread($post_id, $workArr) { echo ""; echo "{$workArr['subject'][$post_id]} (#{$post_id})\n"; echo "by {$workArr['first_name'][$post_id]} {$workArr['last_name'][$post_id]} "."• on " . fixdate($workArr['dt_posted'][$post_id]) . ""; echo "{$workArr['post_text'][$post_id]}\n"; echo "reply to this"; // find all children, call itself on those too foreach ($workArr['post_id'] as $value) { if ($workArr['parent_id'][$value]==$post_id) { processthread($workArr['post_id'][$value], $workArr); } // end if } // foreach echo ""; } And somewhere in the HTML, where appropriate, the function processthread is called for the first time passing it the $post_id value we determined in the first query (the very first post of the discussion) and the $workArr array. Use of unordered lists for design/layout is helpful here since browsers will by default indent lists within lists and list items within their respective list. This saves some PHP and CSS troubles if one were to use or structure instead, as I found out. Apologies for any formatting issues and vagaries about the data structure and variable naming in this post. - Ben -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Multiple "if()" statements
On 30 June 2006 13:37, tedd wrote: > At 11:07 PM -0600 6/29/06, John Meyer wrote: > > Larry Garfield wrote: > > > > > > switch is fine if your elseif comparisons are equality > based. If they're not equality based, then they don't map to > switch as well. > > > > In other words, if you look at a logical ladder as the roots > of the tree, as long as each root has the same number of > forks (say each fork ends only one way), your fine with a > switch. If you have one, however, that has only one > condition, and another that has two, then you need an > if...elseif logic tree. > > Interesting -- can you give me an example? How about this -- a paraphrase of which occurs in many of my scripts: if (isset($_POST['id'])): $id = $_POST['id']; // etc. -- other initializations based on $id elseif ($_POST['action']=='add'): $id = generate_id(); // initialize stuff to empty values elseif (potential_other_test_to_detect_other_valid_states()): // other stuff else: KaBlooie(); endif; Of course, that *could* still be implemented using the switch(TRUE) technique (and I've used that elsewhere), but in a case like this instance I prefer the if/elseif construct. Cheers! Mike - Mike Ford, Electronic Information Services Adviser, Learning Support Services, Learning & Information Services, JG125, James Graham Building, Leeds Metropolitan University, Headingley Campus, LEEDS, LS6 3QS, United Kingdom Email: [EMAIL PROTECTED] Tel: +44 113 283 2600 extn 4730 Fax: +44 113 283 3211 To view the terms under which this email is distributed, please go to http://disclaimer.leedsmet.ac.uk/email.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] design?
Thanks, John, I'm not sure I completely get the idea of a pair class. As an question and answer are in the same database tabel I now created a questionDepot class that gets the array from the db, does save and update operations, and for example, sets a flag in the db tabel when a question is accepted for the list. My question was asked with the experience that a complete procedural approach often turns out to become messy, you have to use certain visual objects more often in teh app, therefore why not create a visual class to use more than once. So, it was just an urge to write cleaner code By the way: as always, I already exceded the 3 or 4 pages David mentioned, if only for the idea to add a 'placed' tag in the db. Sjef ""John Wells"" <[EMAIL PROTECTED]> schreef in bericht news:[EMAIL PROTECTED] > On 6/29/06, Sjef <[EMAIL PROTECTED]> wrote: >> Hi there, >> > Hi Sjef, > > First off, I think David has a good point with regards to the OO vs > Procedural approach. If you're looking to do this quick and easy, it > might not be worth your time fussing with OO. Unless you'd like to > just for the exercise, which I wholly support, so go for it! > >> I want to create a class Question for dealing wiht the questions and a >> class >> answer for the answers. Each could contain an array with the their part >> of >> the content of the database table. > > As far as how to design it OO-style, I'd first urge you *not* to have > separate classes managing lists of questions and answers. Say for > example you query your db for questions, build up your array inside > your questions class, and then while doing the same for your answers > class, you inadvertently introduce a looping bug that drops one of the > answers from the array, or possibly changes the order that you create > your array, or any other number of possible mistakes (human or > otherwise). > > Point is, in the end you'd have two out-of-synch classes that really > should've been built separately to begin with. A single question and > it's answer(s) are tied together, so keep it that way in your class > abstraction. > > That said, I'd suggest building a question-answer *pair* as a class, > and then you'd have an array of these question-answer pairs > representing your entire list (which could be encapsulated into a > container class if you wished). > > You could, to be even more abstract, create base question and answer > classes to represent the most basic type of question or answer, and > then hold individual, **related** instances of these within your > question-answer pair class. Do you see the difference? > > You could even take it a step further and build derivatives of your > base answer class to represent different types (string, multiple > choice with one answer, multiple choice with many answers, etc)...But > I'm sure I'm already getting far ahead of your original design. But > David started it! :) > > HTH, > John W -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Recursing sessions?
Here is a problem I am seeing, A browser hits a site the uses frames, for the sake of argument, lets call this site a squirrelmail web mail server. The browser seems to spawn a number of requests at the same time (I think one for each content frame), I get multiple PS_READ_FUNC calls, and then get multiple PS_WRITE_FUNC calls. Last PS_WRITE_FUNC call wins. Anyone else see this? Anyone have a good fix? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Recursing sessions?
[snip] Here is a problem I am seeing, A browser hits a site the uses frames, for the sake of argument, lets call this site a squirrelmail web mail server. The browser seems to spawn a number of requests at the same time (I think one for each content frame), I get multiple PS_READ_FUNC calls, and then get multiple PS_WRITE_FUNC calls. Last PS_WRITE_FUNC call wins. Anyone else see this? Anyone have a good fix? [/snip] I have a question. This is PHP related how? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Recursing sessions?
> [snip] > Here is a problem I am seeing, > > A browser hits a site the uses frames, for the sake of argument, lets > call > this site a squirrelmail web mail server. > > The browser seems to spawn a number of requests at the same time (I > think > one for each content frame), I get multiple PS_READ_FUNC calls, and > then > get multiple PS_WRITE_FUNC calls. > > Last PS_WRITE_FUNC call wins. > > Anyone else see this? > Anyone have a good fix? > [/snip] > > I have a question. This is PHP related how? > I am debugging a PHP session manager and this behavior is keeping the system from working correctly. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Recursing sessions?
[snip] I am debugging a PHP session manager and this behavior is keeping the system from working correctly. [/snip] A more descriptive explanation along with some code will help us to help you. AFAICS we do not have enough information to go on. Does each frame generate its own session? Can you show us that? The last session setter always wins if the variables are the same. So, if I say; $_SESSION['user'] = 'foo'; $_SESSION['user'] = 'bar'; echo $_SESSION['user']; Like any good variable will return its last given value; bar -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] mysqli_stmt::bind_param(), Number of variables doesn't match number of parameters in prepared statement
I wanted to use the prepared statements of mysqli, but the following problem occured: If I just use one parameter everything works fine $prep = $this->mysqli->prepare('INSERT INTO guestbook (Von, Datum) VALUES (?, NOW())'); $prep->bind_param('s', $this->Von); but if I try to use two $prep = $this->mysqli->prepare('INSERT INTO guestbook (Von, Betreff, Datum) VALUES (?, ?, NOW())'); echo $prep->param_count; // echos 2 $prep->bind_param('ss', $this->Von, $this->Betreff); I get an error Warning: mysqli_stmt::bind_param() : Number of variables doesn't match number of parameters in prepared statement in ... Am I doing something wrong or is it a bug or whatever? php version is 5.1.4 on winXP Best regards, Ulrich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] ONE PAGE CONNECTS MANY DATABASE
Hi again.. I'm wondering is it possible to make one page which connects to many DataBase? If it's possible please tell me where can I get the references? Thank Best Regards BBC **o<0>o** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] apc and ZendPlatform
Quoting Jochem Maas <[EMAIL PROTECTED]>: Rick Emery wrote: We're running Zend Platform on a server that also has apc installed; we're using apc in the scripts to cache data, and I understand (I think) that it also does bytecode also often referred to as 'opcode' caching That's what I meant; sorry. caching. correct. Zend Platform includes a php accelerator, which (I think) is also caching bytecode. AFAIK also correct. Does anybody know if we'll see adverse effects from this? only if you turn on both accelerators (opcode caches) - at least trying to run both is more than likely to open up a whole can of worms and leave your webpages fairly blank. I can't see how they could work together and given that they do the same job (as far as opcode caching is concerned) there is nothing to be gained from running both (for opcode caching) Okay. We haven't seen any problems so far. I just "discovered" the documentation (which was in such an obvious location that I'm embarassed I didn't find it last time I looked: http://www.php.net/apc), and it looks like we have apc.optimization turned off. In the documentation, it looks like optimization is experimental, so I guess we'd be better off sticking with Zend Optimizer and using apc for data caching (I guess what I really want is to know if people agree or disagree)? apc comes with a cool page (apc.php) that shows information about its cache. While it shows that scripts are being cached, it's showing 0 hits for all of them. That seems wrong to me, but I may be mis-understanding it. Does anybody have any insight? check what phpinfo() is saying about your apc settings. my guess is apc.cache_by_default is set to false and apc.filters is empty ... which affectively means no files will be cached ... it could be then the zend platform is forcefully setting this at start up to avoid a conflict/crash/segfault/whatever. apc.cache_by_default is on, but apc.filters says "no value". Let me see if I'm understanding the documentation correctly...it looks like apc does (basically) three things: 1. Cache data (such as information retrieved from a database) 2. Optimize opcode 3. Cache opcode I need to be able to cache data. If I set apc.cache_by_default to off, can I still cache data within the application using apc_store and apc_fetch? Thanks, Rick -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ONE PAGE CONNECTS MANY DATABASE
BBC wrote: Hi again.. I'm wondering is it possible to make one page which connects to many DataBase? Yes. If it's possible please tell me where can I get the references? Look at the connection functions for whatever database engine you're using. -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] ONE PAGE CONNECTS MANY DATABASE
On 30/06/06, John Nichel <[EMAIL PROTECTED]> wrote: BBC wrote: > Hi again.. > > I'm wondering is it possible to make one page which connects to many > DataBase? > Yes. If you are using mysql, why not create connection functions that sit outside the server root (in the include path) for security and pass in the database names to the function (if they all reside on the same server). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php -- http://www.web-buddha.co.uk http://www.projectkarma.co.uk
Re: [PHP] ONE PAGE CONNECTS MANY DATABASE
Yes. For Mysql.. http://www.php.net/manual/en/function.mysql-connect.php -B BBC wrote: Hi again.. I'm wondering is it possible to make one page which connects to many DataBase? If it's possible please tell me where can I get the references? Thank Best Regards BBC **o<0>o** -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Recursing sessions?
Jay Blanchard wrote: > [snip] > I am debugging a PHP session manager and this behavior is keeping the > system from working correctly. > [/snip] > > A more descriptive explanation along with some code will help us to help > you. AFAICS we do not have enough information to go on. Does each frame > generate its own session? Can you show us that? The last session setter > always wins if the variables are the same. So, if I say; > > $_SESSION['user'] = 'foo'; > $_SESSION['user'] = 'bar'; > > echo $_SESSION['user']; > > Like any good variable will return its last given value; Sorry, here's more information: I have a remote session system, like a database or a cache. I have an Apache server running PHP 5 (although it does it on 4.x as well) I am running Squirrelmail on the server. Squirrelmail has frames. The frames on squirrelmail each use the same session information Multiple frame requests are sent from the browser at the same time. The time to handle the requests is a non-zero amount of time that varies with each frame session_start is called for each frame request The frame pages are processed The session information saved via (I believe) session_write_close for the frame requests as each frames modifications to the session data is saved, the last session to finish ends up writing the final version of the session data. A log looks like this: PS_READ_FUNC() PS_READ_FUNC() PS_WRITE_FUNC() PS_WRITE_FUNC() It should look like this: PS_READ_FUNC() PS_WRITE_FUNC() PS_READ_FUNC() PS_WRITE_FUNC() In my session handler code, I have added a loop that looks like this: for(tstart=time(0); elapsed < 30; elapsed = time(0) - tstart) { stat = network_lock(xkey); if(stat==LOCK_OK) { NETLOCK_G(fdlock) = xkey; break; } sleep(1); // Connection is busy, sleep for a second } This fixes the problem, but requires that PHP poll. I can put the same login the the network system, but then that requires a socket and perhaps a thread. Does PHP have a way to tell the browser to respond once frame at a time, or some more efficient serialization methodology. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Functions
I was able to get the return to work but not the pass in the reference. One last question, what if I want to have each item on a separate line like: function cleaner($var) { trim($var); strip_tags($var); ucfirst($var); addslashes($var); str_replace ("$","",$var); } $var = "abc's"; echo $var; How would I return the results here, I tried various different ways none of them worked? On 6/29/06, Chris <[EMAIL PROTECTED]> wrote: [EMAIL PROTECTED] wrote: > I am trying to create a function to clean up variables that are user > inputted from a form. I am not getting this script to work. Can anyone > help. > > ---Start Script--- > function cleaner($var) > { > trim(strip_tags(ucfirst(addslashes($var; > } > > $var = "abc's"; > > echo $var; You need to return the value from the function: return trim(strip_tags(.) or pass in a reference: function cleaner (&$var) -- Postgresql & php tutorials http://www.designmagick.com/ -- ** The content of this e-mail message and any attachments are confidential and may be legally privileged, intended solely for the addressee. If you are not the intended recipient, be advised that any use, dissemination, distribution, or copying of this e-mail is strictly prohibited. If you receive this message in error, please notify the sender immediately by reply email and destroy the message and its attachments. *
Re: [PHP] apc and ZendPlatform
On Fri, June 30, 2006 9:27 am, Rick Emery wrote: > We're running Zend Platform on a server that also has apc installed; > we're using apc in the scripts to cache data, and I understand (I > think) that it also does bytecode caching. > > Zend Platform includes a php accelerator, which (I think) is also > caching bytecode. > > Does anybody know if we'll see adverse effects from this? > > apc comes with a cool page (apc.php) that shows information about its > cache. While it shows that scripts are being cached, it's showing 0 > hits for all of them. That seems wrong to me, but I may be > mis-understanding it. > > Does anybody have any insight? One wild theory would be that the Zend Cache has been holding your entire set of PHP scripts in RAM, so has never had to hit the "disk" for the source, and so APC, down in the chain later, has never had anybody even ASK for a page a second time... Using both Zend Cache and APC together seems decidedly "odd" to me, but there it is... -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Stop process when user close window browser
On Fri, June 30, 2006 4:54 am, weetat wrote: >Yes. I read the manual regarding the connection handling. >However ,in my php program , the execution did not stop , because i > have logger which log sql statement "INSERT" statement when inserted > data to database is ok . > > When i close the browser , the sql execution still running, statement > is > logged. > > Any idea how to stop it ? Because it cause my web page to be slow. Instead of trying to stop it, just "Don't Do That" Whatever it is you need the database to do, set something up to let it do that task "later" while the user isn't stuck waiting for your script. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Displaying data from a MySLQ table
Hi Have have a varchar field in a MySQL database which contains the following 905.362.6000"l""s"'L' I am trying to display it on my web page in a field but all I see is: 905.362.6000 I am wondering why the trailing characters do not display even though they are present in the database when I check using PhpMyAdmin. Please help. Thanks in advance My code snippet is as follows: Phone The query_database() function is my own and looks as follows: // smart function for querying a MySQL database function query_database($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number or a numeric string if (!is_numeric($value)) { $value = mysql_real_escape_string($value); } return $value; } Thanks _ Don Proshetsky, C.I.O. LCL Navigation This email and any files transmitted with it are strictly confidential and may be privileged information. It is intended solely for the individual or company to whom it is addressed and may not be copied, forwarded, transmitted or otherwise distributed in any manner or form to any other party. If you are not the intended recipient or the person responsible for delivering this e-mail to the intended recipient, please indicate so and return this email to the sender, after which, kindly delete it from your computer as well as your email server. Without limitation, LCL Navigation accepts no liability whatsoever and howsoever caused in connection with the use of this email. Are you on our eBLISS yet? It's simple yet amazing. Just click here: http://www.lclnav.com/createaccount.html to open a B2B account with us and do everything electronically 24/7. Tel: 905-362-6000, Ext. 230 Fax: 905-362-6001
[PHP] Quick Question re: Windows/Linux PHP
Hi, I'm just curious, because I come across this from time to time. Why does the code below work on Windows and not on Linux. PHP is 5.0 on Linux and 4.4 on Windows (still can't get 5 on Windows). The code at the very bottom is how I got it to work on Linux. Also, why is it with the same setup I can't call a function within a function in Linux, but can in Windows. Sorry I don't have the error, but something about calling a static function. Would this be a difference between OS's or with the different versions of PHP? Thanks B --- if (empty($subemail)) { $form->setError($field, emailnotentered); } else { $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)*" ."@[a-z0-9-]+(\.[a-z0-9-]{1,})*" ."\.([a-z]{2,}){1}$"; if(!eregi($regex,$subemail)){ $form->setError($field, emailinvalid); } $subemail = stripslashes($subemail); } elseif(in_array(strtolower($a), $language)) $form->setError($field, profanity); elseif(in_array(strtolower($b), $language)) $form->setError($field, profanity); elseif(in_array(strtolower($c), $language)) $form->setError($field, profanity); else { $query = "SELECT * FROM users WHERE $subemail = 'email'"; $result = mysql_query($query)or $mysqlerror = mysql_error(); if ($mysqlerror) { $form->setError($field, tberror); } else { $numrows = mysql_fetch_row($result); if($numrows = mysql_num_rows($result)) { $form->setError($field, duplicatepassword); } } } --- $field = "email"; list ($a, $b, $c) = split ('[EMAIL PROTECTED]', $subemail); $regex = "^[_+a-z0-9-]+(\.[_+a-z0-9-]+)[EMAIL PROTECTED](\.[a-z0-9-]{1,})*\.([a-z]{2,}){1} $"; if (empty($subemail)) { $form->setError($field, emailnotentered); } elseif(!eregi($regex,$subemail)){ $form->setError($field, emailinvalid); } elseif(in_array(strtolower($a), $language)) $form->setError($field, profanity); elseif(in_array(strtolower($b), $language)) $form->setError($field, profanity); elseif(in_array(strtolower($c), $language)) $form->setError($field, profanity); else { $query = "SELECT * FROM users WHERE $subemail = 'email'"; $result = mysql_query($query)or $mysqlerror = mysql_error(); if ($mysqlerror) { $form->setError($field, tberror); } else { $numrows = mysql_fetch_row($result); if($numrows = mysql_num_rows($result)) { $form->setError($field, duplicatepassword); } } } -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Find out cookies on a computer?
On Thu, June 29, 2006 4:23 pm, Peter Lauri wrote: > Is it possible to some how find out all cookies on a specific computer > and > their name and value? I assume not :) If you have physical access to it, Netscape and IE cache their non-session cookies in files you can dig out. Session cookies can be viewed through the browser, or browser plugins. >From server-side, you can var_dump($_COOKIES) to see all the cookies you sent. If you mean to ask if you can see from your server, the cookies I sent from my server, the answer is "No." -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: creating a threaded message system--sorting messages
Ben Liu wrote: Thanks to everybody who posted on this thread. I wanted to post back the solution I came up with after removing the DB query from the recursion. In case anyone else is trying to accomplish the same thing, this is how I solved it (criticisms welcome, and note that I have not tested it extensively yet): DB structure table: discussion_posts post_id (auto increment, unique, primary index) parent_id (post_id corresponding to this post's parent) discussion_id (to allow multiple discussions, not required but I added a discussions member_id (to identify the post to the particular member posting the post) table as well to store the discussion description and unique ID for each discussion) dt_posted (date/time the post was posted) subject (title of the particular post) post_text (substance of the post) So the user selects a particular discussion from a list of discussions. We query the database for the post_id of the first post in the discussion requested, this post will have a parent_id of '0' or NULL since it has no parent. We then query the DB for all the posts in the discussion joining the members table using member_id to grab the member's first and last name (or any other member info desired). We order this query info by dt_posted. We then write the contents of our second query into a two-dimensional array ($workArr): while ([EMAIL PROTECTED]($result)) { foreach ($row as $key => $value) { if ($key=="post_id") $numerKey=value; $workArr[$key][$numerKey]=$value; } } The processing of the threads into proper order looks like this: function processthread($post_id, $workArr) { echo ""; echo "{$workArr['subject'][$post_id]} (#{$post_id})\n"; echo "by {$workArr['first_name'][$post_id]} {$workArr['last_name'][$post_id]} "."• on " . fixdate($workArr['dt_posted'][$post_id]) . ""; echo "{$workArr['post_text'][$post_id]}\n"; echo "reply to this"; // find all children, call itself on those too foreach ($workArr['post_id'] as $value) { if ($workArr['parent_id'][$value]==$post_id) { processthread($workArr['post_id'][$value], $workArr); } // end if } // foreach echo ""; } And somewhere in the HTML, where appropriate, the function processthread is called for the first time passing it the $post_id value we determined in the first query (the very first post of the discussion) and the $workArr array. Use of unordered lists for design/layout is helpful here since browsers will by default indent lists within lists and list items within their respective list. This saves some PHP and CSS troubles if one were to use or structure instead, as I found out. Apologies for any formatting issues and vagaries about the data structure and variable naming in this post. - Ben I think that will work, but there is one huge improvement you can make. You are making millions of copies of your work array! Not only do you pass the entire array by value recursively, but foreach makes copies of the arrays it loops through! So who knows how many copies of the darned work array are being spawned left and right. This can be a memory leak, consuming lots of memory until it finishes the recursion. The first thing you can do is tell the function the array is to be handled by reference: function processthread($post_id, &$workArr) { You never change the work array, I think, so you can just keep referring back to the original. The second thing to do is to make the foreach work on references instead of copies. I actually think that since what we have in our function is now a reference, the foreach WILL NOT copy it. But if it still does, there is always the fallback of doing a foreach on array_keys($workArr). Then each $value would be the key, which you'd use to reference $workArr. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Recursing sessions?
On Fri, June 30, 2006 11:11 am, Mark wrote: > Here is a problem I am seeing, > > A browser hits a site the uses frames, for the sake of argument, lets > call > this site a squirrelmail web mail server. > > The browser seems to spawn a number of requests at the same time (I > think > one for each content frame), I get multiple PS_READ_FUNC calls, and > then > get multiple PS_WRITE_FUNC calls. > > Last PS_WRITE_FUNC call wins. > > Anyone else see this? Of course. > Anyone have a good fix? As I recall, you HAVE to get the OUTER php page, with the FRAMESET in it, to start the session, and then in that page, all the FRAME page requests will be using the same session, because it has already been established. I think I even went so far as embedding the session_id in the URLs for the FRAME SRC="...SID=SID" and then I made sure each frame page was using that ID. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Displaying data from a MySLQ table
Don wrote: Hi Have have a varchar field in a MySQL database which contains the following 905.362.6000"l""s"'L' I am trying to display it on my web page in a field but all I see is: 905.362.6000 I am wondering why the trailing characters do not display even though they are present in the database when I check using PhpMyAdmin. Please help. You need to run the value through htmlentities (http://php.net/htmlentities). This email and any files transmitted with it are strictly confidential and may be privileged information. It is intended solely for the individual or company to whom it is addressed and may not be copied, forwarded, transmitted or otherwise distributed in any manner or form to any other party. If you are not the intended recipient or the person responsible for delivering this e-mail to the intended recipient, please indicate so and return this email to the sender, after which, kindly delete it from your computer as well as your email server. Without limitation, LCL Navigation accepts no liability whatsoever and howsoever caused in connection with the use of this email. And this email is strictly confidential and may be privileged information. In fact you will break the law if you read it. When you hear the sirens please don't run. If you do run we'll still get you but we'll be mighty pissed off when we do. And you never want to piss us off. You have been warned. Have a nice day ;) -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Functions
On Fri, June 30, 2006 12:00 am, [EMAIL PROTECTED] wrote: > I am trying to create a function to clean up variables that are user > inputted from a form. I am not getting this script to work. Can > anyone > help. > > ---Start Script--- > function cleaner($var) > { > trim(strip_tags(ucfirst(addslashes($var; > } > > $var = "abc's"; > > echo $var; > ---End Script--- > > When I run the above script it produces nothing. Instead of a result > of > "Abc\'s". At the simplistic level, the problem is that you are not using "return" to actually RETURN the answer, so you do all that work and throw away the result. return trim(strip_tags(ucfirst(addslashes($var; At a higher level, the problem is that you are basically doing several things very very very wrong here... #1. addslashes should be replaced with the database-specific escaper, such as mysql_real_escape_string, or you should use prepared statements so that the DB cannot possibly mistake data for SQL. #2. Don't alter the case of the input data, if at all possible. Accept what the user has given, and take it as it is. You can make your application not care about case, and you can format the case on ouput (maybe even with fancy CSS stuff) but don't mess with their input. #3. strip_tags should probably happen first... Otherwise the escaping of the data going into the DB could, possibly, be defeated by clever arrangement of HTML tags that disguise the invalid data. #4. There is a complete lack of actual validation here... You'd be WAY better off to make sure the incoming data is what you expect, and not accept bad input, than to just blindly strip_tags on it. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Displaying data from a MySLQ table
Don wrote: Hi Have have a varchar field in a MySQL database which contains the following 905.362.6000"l""s"'L' I am trying to display it on my web page in a field but all I see is: 905.362.6000 Because it has quotes in it. I bet if you look at the source of the page, the full value is there. If your form field looks like this... It's going to output like this -^ So when the browser sees the first double quote in your value, it assumes that you're closing off the attribute. Try running the value thru htmlentities() I am wondering why the trailing characters do not display even though they are present in the database when I check using PhpMyAdmin. Please help. Thanks in advance My code snippet is as follows: Phone The query_database() function is my own and looks as follows: // smart function for querying a MySQL database function query_database($value) { // Stripslashes if (get_magic_quotes_gpc()) { $value = stripslashes($value); } // Quote if not a number or a numeric string if (!is_numeric($value)) { $value = mysql_real_escape_string($value); } return $value; } Why are you running mysql_real_escape_string() after selecting data? -- John C. Nichel IV Programmer/System Admin (ÜberGeek) Dot Com Holdings of Buffalo 716.856.9675 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Functions
[EMAIL PROTECTED] wrote: I was able to get the return to work but not the pass in the reference. One last question, what if I want to have each item on a separate line like: function cleaner($var) { trim($var); strip_tags($var); ucfirst($var); addslashes($var); str_replace ("$","",$var); } $var = "abc's"; echo $var; How would I return the results here, I tried various different ways none of them worked? From your code snippet there are clearly too many fundamentals that you don't seem to understand. I suggest you Google for a PHP beginners tutorial, read it and then start again. You may have better luck after you understand how PHP works. You may also want to look in the PHP manual for the documentation for the functions you are using above, and also at the section on functions. Everything you need is there - absorb it. -Stut -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: Re: [PHP] Re: creating a threaded message system--sorting messages
On 6/30/06, Adam Zey <[EMAIL PROTECTED]> wrote: I think that will work, but there is one huge improvement you can make. You are making millions of copies of your work array! Not only do you pass the entire array by value recursively, but foreach makes copies of the arrays it loops through! So who knows how many copies of the darned work array are being spawned left and right. This can be a memory leak, consuming lots of memory until it finishes the recursion. Yipes! The first thing you can do is tell the function the array is to be handled by reference: function processthread($post_id, &$workArr) { Added your suggestion, works fine. You never change the work array, I think, so you can just keep referring back to the original. yes, that is correct. $workArr is never modified. The second thing to do is to make the foreach work on references instead of copies. I actually think that since what we have in our function is now a reference, the foreach WILL NOT copy it. Anyone have any ideas on this? Is the foreach loop in fact copying $workArr? And how could we tell (test for it) if it were? But if it still does, there is always the fallback of doing a foreach on array_keys($workArr). Then each $value would be the key, which you'd use to reference $workArr. I'm sorry, you lost me here a bit. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] creating a threaded message system--sorting messages
On Thu, June 29, 2006 9:11 am, Ben Liu wrote: > I'm trying to present the messages to the users in > threaded order rather than flat. I'm having a lot of trouble figuring > out how to sort the posts so they appear in the correct threaded > order. I don't think I can do this purely with a SQL query. You can. The thing to do is to store the "pre-order traversal" as a "threaded tree" in your database. If you Google for those terms along with SQL, you should find some articles that will help you tame this beast. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Displaying data from a MySLQ table
Ok, better but stil not displayting properly. Here is what my database field has: import.csv'<">/\ Here is what is displaying: import.csv' It's choking on the double quote in the database field. Here is the code snippet from my form: function display_database($value) { $value = htmlentities($value,ENT_COMPAT); if (!get_magic_quotes_gpc()) { $value = stripslashes($value); } return $value; } -Original Message- From: Stut [mailto:[EMAIL PROTECTED] Sent: Friday, June 30, 2006 3:49 PM To: Don Cc: php list Subject: Re: [PHP] Displaying data from a MySLQ table Don wrote: > Hi Have have a varchar field in a MySQL database which contains the > following > > 905.362.6000"l""s"'L' > > I am trying to display it on my web page in a field but > all I see is: > > 905.362.6000 > > I am wondering why the trailing characters do not display even though > they are present in the database when I check using PhpMyAdmin. Please help. You need to run the value through htmlentities (http://php.net/htmlentities). -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Programming question - New to PHP
On Wed, June 28, 2006 6:58 pm, Russbucket wrote: > I took an example of a script from the PHP documentation and try to > connect > to my database. If I leave in the or die part of line 3, I get > nothing, if > I comment out that part I get the echo message on line 4. > > // Connecting and selecting the database > $conn = mysql_connect ('localhost', 'finemanruss', 'XXXl') or die > ('Could > not connect : ' . mysql_error()); > echo 'Connected successfully'; > mysql_select_db ("Lions", $conn); > > // Preform SQL query > $query = 'SELECT * FROM Moses_Lake_Lions'; > $result = mysql_query ($query) or die ( 'Query failed; ' . > mysql_error()); > ?> > > I know line three works without the or die part since I have a 2nd > script that > is almost the same (no or die) and it retrieves info from my DB. > > Can anyone point me to some tips or solutions to the or die problem? > This > script is located in the mysql ref section of the php manual. I'm > using php5 > on SUSE Linux 10.0 with a mysql database. Odds are REALLY GOOD that the "or die" is fine... Try this: Change line 4 to be: echo 'Successfully connected: ', $conn; If $conn shows something like "Resource #4" then you know you have a good connection. If it shows "false" or nothing, then you know the connection is not working, and or die() is doing the right thing. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Multiple "if()" statements
On Thu, June 29, 2006 11:07 pm, Larry Garfield wrote: > switch is fine if your elseif comparisons are equality based. If > they're not > equality based, then they don't map to switch as well. Except in PHP which supports: switch(TRUE) { case _boolean_expression_: break; } So you can have case statements of whatever complexity is appropriate. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] apc and ZendPlatform
Rick Emery wrote: ... >> be gained from running both (for opcode caching) > > Okay. We haven't seen any problems so far. I just "discovered" the > documentation (which was in such an obvious location that I'm > embarassed I didn't find it last time I looked: http://www.php.net/apc), > and it looks like we have apc.optimization turned off. In the > documentation, it looks like optimization is experimental, so I guess > we'd be better off sticking with Zend Optimizer and using apc for data > caching (I guess what I really want is to know if people agree or > disagree)? apc optimization is in the words of the author still an experiment - I don't think it will give you anything much at all at this stage in it's development. NB: optimization != opcode caching. optimization involves juggling the compiled code (the opcodes) so that they do [exactly] the same in less operations opcode caching involves caching whatever [possibly optimized] opcodes were created when compiling a script so that second and subsequent calls to a script can skip the compile stage completely (which would mean that if an opcode cache was in affect the optimization would also only need to occur 'once') find the file named apc.php and use it (as documented) to discover exactly what apc is doing on your setup... my guess is that apc is caching opcodes for you (given the settings you mentioned) and that your Zend setup does not include an opcode cache [but it is optimizing whatever is being compiled] - my knowledge of the Zend stuff is patchy at best - I don't really know which of their various packages offer what kind of functionality. > > I need to be able to cache data. If I set apc.cache_by_default to off, > can I still cache data within the application using apc_store and > apc_fetch? yes. > > Thanks, > Rick > > --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] Displaying data from a MySLQ table
On Fri, June 30, 2006 1:39 pm, Don wrote: > 905.362.6000"l""s"'L' > So you end up with this: value="905.362.6000"1""s"'L'" ^ And, in HTML, this | marks the end of the string. You know how you do mysql_real_escape_string to put data in a database? In the same way, you need http://php.net/htmlentities to put data into HTML. In fact, if you think about it, almost every time you put data from point A to point B, you need to "escape" it for that specific usage. data -> MySQL : mysql_real_escape_string data -> HTML : htmlentities data -> URL : urlencode You can frequently "get away" with not doing the escape only because the data doesn't happen, by mere chance, to have any 'bad' characters in it. That doesn't make your code correct. It just happens to sort of work. -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Displaying data from a MySLQ table
The fact that you are calling stripslashes tells me that one of two things has occurred. #1. You escaped data coming into the DB *twice*, which often happens with Magic Quotes GPC + (addslashes || mysql_real_escape_string) used together. Your data is corrupt, and until you fix that, you'll just have nightmares. #2. You just don't understand the purpose of escaping data to go into MySQL. The purpose of the escaping is not to STORE the data with extra slashes. The purpose is to add extra slashes so that MySQL parser/reader can "eat" them and end up with the correct raw data you had before you escaped it. RIGHT WAY Raw Data Escaped Data What MySQL puts on hard drive can'tcan\'t can't WRONG WAY Raw Data Doubly-escaped What MySQL puts on hard drive can'tcan\\\'t can\'t If you're getting can\'t "out" of MySQL with mysql_fetch_row, then you are in situation #1. If you don't but you are calling stripslashes() anyway, you are in situation #2 On Fri, June 30, 2006 3:14 pm, Don wrote: > Ok, better but stil not displayting properly. > Here is what my database field has: > > import.csv'<">/\ > > Here is what is displaying: > > import.csv' noenter()"> > > It's choking on the double quote in the database field. Here is the > code > snippet from my form: > > > > function display_database($value) > { >$value = htmlentities($value,ENT_COMPAT); >if (!get_magic_quotes_gpc()) { >$value = stripslashes($value); >} >return $value; > } > > -Original Message- > From: Stut [mailto:[EMAIL PROTECTED] > Sent: Friday, June 30, 2006 3:49 PM > To: Don > Cc: php list > Subject: Re: [PHP] Displaying data from a MySLQ table > > Don wrote: >> Hi Have have a varchar field in a MySQL database which contains the >> following >> >> 905.362.6000"l""s"'L' >> >> I am trying to display it on my web page in a field >> but >> all I see is: >> >> 905.362.6000 >> >> I am wondering why the trailing characters do not display even >> though >> they are present in the database when I check using PhpMyAdmin. >> Please > help. > > You need to run the value through htmlentities > (http://php.net/htmlentities). > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Like Music? http://l-i-e.com/artists.htm -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Update or add?
I have a table where I want to update each record with today's date as it's hit, or add the record if it's not in there: +--+-++ | id | creation_date | last_hit | +--+-++ I'm trying to do this with a minimum of hits to the db, so rather than first searching to see if a matching record is in there, I thought I'd just go ahead and update the matching record, check to see if it failed, and if it failed then add a new one, like this: $id = $_GET['id']; // Update $query = "update table set last_hit=NOW() where id='$id'"; $result = mysql_query($query); // Add if(the update failed) { $query = "insert into table (id,creation_date,last_hit) values ('$id',NOW(),NOW())"; $result = mysql_query($query); } What's the fastest way to check if the update failed? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: creating a threaded message system--sorting messages
Ben Liu wrote: The second thing to do is to make the foreach work on references instead of copies. I actually think that since what we have in our function is now a reference, the foreach WILL NOT copy it. Anyone have any ideas on this? Is the foreach loop in fact copying $workArr? And how could we tell (test for it) if it were? I should note that the DEFAULT behaviour of foreach is to make a copy of the array you pass it. What I'm saying is that, now that we're passing it a reference to an array instead of an actual array, is that enough to stop it from copying? The manual seems to indicate that, but is a bit vague. But if it still does, there is always the fallback of doing a foreach on array_keys($workArr). Then each $value would be the key, which you'd use to reference $workArr. I'm sorry, you lost me here a bit. I mean, do this: foreach ( array_keys($workArr) as $key ) { echo $workArr[$key]['foo']; } instead of this: foreach ( $workArr as $key => $value ) { echo $value['foo']; } Both let you do the same thing, you just reference data differently, and the first example involves working with the original array, so foreach has no chance to copy it. HOWEVER, if my above supposition about foreach not copying a reference is correct, you wouldn't need to do this. It's just a backup plan. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] Update or add?
> > I have a table where I want to update each record with today's date > as it's hit, or add the record if it's not in there: > > +--+-++ > | id | creation_date | last_hit | > +--+-++ > > I'm trying to do this with a minimum of hits to the db, so rather > than first searching to see if a matching record is in there, I > thought I'd just go ahead and update the matching record, check to > see if it failed, and if it failed then add a new one, like this: > > $id = $_GET['id']; > // Update > $query = "update table set last_hit=NOW() where id='$id'"; > $result = mysql_query($query); > // Add > if(the update failed) { >$query = "insert into table (id,creation_date,last_hit) values > ('$id',NOW(),NOW())"; >$result = mysql_query($query); > } > > What's the fastest way to check if the update failed? > Maybe you should be looking at using REPLACE instead of INSERT or UPDATE. REPLACE will update the record if it exists, OR add it if it doesn't. JM -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Update or add?
On Friday 30 June 2006 14:37, Brian Dunning wrote: > I have a table where I want to update each record with today's date > as it's hit, or add the record if it's not in there: > > +--+-++ > > | id | creation_date | last_hit | > > +--+-++ > > I'm trying to do this with a minimum of hits to the db, so rather > than first searching to see if a matching record is in there, I > thought I'd just go ahead and update the matching record, check to > see if it failed, and if it failed then add a new one, like this: > > $id = $_GET['id']; > // Update > $query = "update table set last_hit=NOW() where id='$id'"; > $result = mysql_query($query); > // Add > if(the update failed) { >$query = "insert into table (id,creation_date,last_hit) values > ('$id',NOW(),NOW())"; >$result = mysql_query($query); > } > > What's the fastest way to check if the update failed? This is from the php.net docs. Return Values For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. So if($result == 0){ do something; } -- Paul Nowosielski Webmaster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Update or add?
Paul Nowosielski wrote: On Friday 30 June 2006 14:37, Brian Dunning wrote: I have a table where I want to update each record with today's date as it's hit, or add the record if it's not in there: +--+-++ | id | creation_date | last_hit | +--+-++ I'm trying to do this with a minimum of hits to the db, so rather than first searching to see if a matching record is in there, I thought I'd just go ahead and update the matching record, check to see if it failed, and if it failed then add a new one, like this: $id = $_GET['id']; // Update $query = "update table set last_hit=NOW() where id='$id'"; $result = mysql_query($query); // Add if(the update failed) { $query = "insert into table (id,creation_date,last_hit) values ('$id',NOW(),NOW())"; $result = mysql_query($query); } What's the fastest way to check if the update failed? This is from the php.net docs. Return Values For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a resource on success, or FALSE on error. For other type of SQL statements, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error. So if($result == 0){ do something; } No no no no no! Never like that! What you want is this: if($result === false){ do something; } Never use 0 as a placeholder for false, and never use == to compare boolean values. 0 is an integer, false is a boolean. Using === ensures that result is false, and that it is a boolean that is false. It compares the value AND the type. Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: creating a threaded message system--sorting messages
On Jun 30, 2006, at 5:04 PM, Adam Zey wrote: I mean, do this: foreach ( array_keys($workArr) as $key ) { echo $workArr[$key]['foo']; } instead of this: foreach ( $workArr as $key => $value ) { echo $value['foo']; } Okay, I think I get the idea. So using my code example... this: foreach ($workArr['post_id'] as $value) { if ($workArr['parent_id'][$value]==$post_id) { processthread($workArr['post_id'][$value], &$workArr); } // end if would become this?: foreach (arraykeys($workArr['post_id'] as $key) { if ($workArr['parent_id'][$key]==$post_id) { processthread($workArr['post_id'][$key], &$workArr); } // end if Seems to work just fine. Will take the hamsters running in my brain a little more time to fully understand it... :-) Thanks again for all your help. - Ben Both let you do the same thing, you just reference data differently, and the first example involves working with the original array, so foreach has no chance to copy it. HOWEVER, if my above supposition about foreach not copying a reference is correct, you wouldn't need to do this. It's just a backup plan. Regards, Adam. smime.p7s Description: S/MIME cryptographic signature
Re: [PHP] Update or add?
Good advice , Thank you! -- Paul Nowosielski Webmaster On Friday 30 June 2006 15:45, Adam Zey wrote: > Paul Nowosielski wrote: > > On Friday 30 June 2006 14:37, Brian Dunning wrote: > >> I have a table where I want to update each record with today's date > >> as it's hit, or add the record if it's not in there: > >> > >> +--+-++ > >> > >> | id | creation_date | last_hit | > >> > >> +--+-++ > >> > >> I'm trying to do this with a minimum of hits to the db, so rather > >> than first searching to see if a matching record is in there, I > >> thought I'd just go ahead and update the matching record, check to > >> see if it failed, and if it failed then add a new one, like this: > >> > >> $id = $_GET['id']; > >> // Update > >> $query = "update table set last_hit=NOW() where id='$id'"; > >> $result = mysql_query($query); > >> // Add > >> if(the update failed) { > >>$query = "insert into table (id,creation_date,last_hit) values > >> ('$id',NOW(),NOW())"; > >>$result = mysql_query($query); > >> } > >> > >> What's the fastest way to check if the update failed? > > > > This is from the php.net docs. > > > > Return Values > > > > For SELECT, SHOW, DESCRIBE or EXPLAIN statements, mysql_query() returns a > > resource on success, or FALSE on error. > > > > For other type of SQL statements, UPDATE, DELETE, DROP, etc, > > mysql_query() returns TRUE on success or FALSE on error. > > > > > > So if($result == 0){ > > do something; > > } > > No no no no no! Never like that! What you want is this: > > > if($result === false){ > do something; > } > > Never use 0 as a placeholder for false, and never use == to compare > boolean values. 0 is an integer, false is a boolean. Using === ensures > that result is false, and that it is a boolean that is false. It > compares the value AND the type. > > Regards, Adam. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Update or add?
Hi All, there is not-so-used format of SQL format that is INSERT INTO table SET col1=data1, col2=data2... ON DUPLICATE KEY UPDATE col1=data1, col2=data2...; you have to define a primary or unique key in the table and all will work well. for more info http://dev.mysql.com/doc/refman/4.1/en/insert-on-duplicate.html Cheers /V Brian Dunning wrote: I have a table where I want to update each record with today's date as it's hit, or add the record if it's not in there: +--+-++ | id | creation_date | last_hit | +--+-++ I'm trying to do this with a minimum of hits to the db, so rather than first searching to see if a matching record is in there, I thought I'd just go ahead and update the matching record, check to see if it failed, and if it failed then add a new one, like this: $id = $_GET['id']; // Update $query = "update table set last_hit=NOW() where id='$id'"; $result = mysql_query($query); // Add if(the update failed) { $query = "insert into table (id,creation_date,last_hit) values ('$id',NOW(),NOW())"; $result = mysql_query($query); } What's the fastest way to check if the update failed? --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] Multiple "if()" statements
At 4:26 PM +0100 6/30/06, Ford, Mike wrote: >On 30 June 2006 13:37, tedd wrote: > >> At 11:07 PM -0600 6/29/06, John Meyer wrote: >> > Larry Garfield wrote: >> > > >> > >[1] switch is fine if your elseif comparisons are equality > > based. If they're not equality based, then they don't map to >> switch as well. >> > > > > [2] In other words, if you look at a logical ladder as the roots > > of the tree, as long as each root has the same number of >> forks (say each fork ends only one way), your fine with a >> switch. If you have one, however, that has only one >> condition, and another that has two, then you need an >> if...elseif logic tree. >> >> Interesting -- can you give me an example? > >How about this -- a paraphrase of which occurs in many of my scripts: > > if (isset($_POST['id'])): > $id = $_POST['id']; > // etc. -- other initializations based on $id > elseif ($_POST['action']=='add'): > $id = generate_id(); > // initialize stuff to empty values > elseif (potential_other_test_to_detect_other_valid_states()): > // other stuff > else: > KaBlooie(); > endif; > >Of course, that *could* still be implemented using the switch(TRUE) technique >(and I've used that elsewhere), but in a case like this instance I prefer the >if/elseif construct. I think the point here is that you said [1] and [2], but you still haven't provided an example. The following works just as well as your elseif example. switch (TRUE) { case isset($_POST['id']: $id = $_POST['id']; break; case $_POST['action']=='add': $id = generate_id(); break; case (potential_other_test_to_detect_other_valid_states()): break; default KaBlooie(); break; } Additionally, in my timed tests, I find both control structures to be generally equal in speed -- so I don't find any support for elsif being better matched than switch in any equality based computations. So, I believe the choice to use one control structure in preference to the other is purely a personal one -- and one that has no support stemming from any performance differences, because there are none. Thanks for your reply. tedd -- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] mysqli_stmt::bind_param(), Number of variables doesn't match number of parameters in prepared statement
On 7/1/06, gg15 <[EMAIL PROTECTED]> wrote: I wanted to use the prepared statements of mysqli, but the following problem occured: If I just use one parameter everything works fine $prep = $this->mysqli->prepare('INSERT INTO guestbook (Von, Datum) VALUES (?, NOW())'); $prep->bind_param('s', $this->Von); but if I try to use two $prep = $this->mysqli->prepare('INSERT INTO guestbook (Von, Betreff, Datum) VALUES (?, ?, NOW())'); echo $prep->param_count; // echos 2 $prep->bind_param('ss', $this->Von, $this->Betreff); I get an error Warning: mysqli_stmt::bind_param() : Number of variables doesn't match number of parameters in prepared statement in ... Is $this->Betreff empty? I wonder if its having issues with an empty var.. -- Postgresql & php tutorials http://www.designmagick.com/ -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Sad PHP Poem
2006/6/26, Martin Alterisio <[EMAIL PROTECTED]>: A sad poem of an algorithm where solitude brought excessive use of cpu cycles and memory allocation for redundant data (it copied over and over again the same image till all memory was filled with it) -- $timeWaiting = 0; while (!$you->near($me)) { $me->thinkAbout($you); switch (true) { case $timeWaiting < 5: $me->wait($you); break; case $timeWaiting < 10: $me->worry(); break; case $timeWaiting < 20: $me->lookFor($you) ; break; case $timeWaiting < 40: $me->worry(); $me->lookFor($you) ; break; case $timeWaiting < 80: $me->worry(); $me->cry(); $me->lookFor($you) ; $me->lookFor($you) ; $me->lookFor($you) ; break; case $timeWaiting < 160: $me->worry(); $me->cry(); $me->drink(); $me->lookFor($you) ; $me->lookFor($you) ; $me->lookFor($you) ; $me->thinkAbout($you); $me->thinkAbout($you); $me->cry(); $me->lookFor($you) ; $me->lookFor($you) ; $me->drink(); $me->drink(); break; default: throw new CantLiveWithoutYou(); die("alone"); } $timeWaiting++; } $me->happy = true; -- I hope you enjoyed the poem and the fact that I didn't ask you to fix it or find the bug in it =D PD: Run in your web server at your own risk. I guy over here completed the code to allow its execution http://devzone.zend.com/node/view/id/576 (see the comments). --- Then, I having trouble with this code, would you be so kind to look at it: // He says he did it, but he's crazy. Who knows... $poem->author = new Person("Martin Alterisio"); // TO DO: Person might not be the proper class here. Check that. foreach (Person::$all as $you) { if ($you->like($poem)) { $poem->author->thank($you); } else { // TO DO: Spread the geekness // On second thought, maybe that's not a good idea } } That's all folks. Coming up next: an innovative realistic soccer simulation game: "Fix the World Cup". Everything from bribing a referee to fixing the team sorting. Do you lack the morality to make your team the world champion by any means necessary? Take this chance to prove it! (just joking... really but it would be a good game, wouldn't it?)