[PHP] Fork and zombies
I periodically run a script that makes a call against a remote API, which takes some time to return. In an attempt to increase thoroughput, I decided to investigate using pnctl_fork to spawn off multiple processes to make the call, since the slowest part is the network part of it (and waiting for the server response). I ended up writing a script that did this: $pid = pnctl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { echo parent $pid\n; return; } else { // make API call } While this works, it unfortunately leaves behind a zombie process every single time. I could rewrite this to instead call fork multiple times, then wait on all of them to return, but as my system is currently architected, the easiest way would be to fire and forget for this script. Does anyone have any ideas on the best way to do it? The other way I've done this is to use exec(php foo.php) and redirecting stdout and stderr to /dev/null. Waynn
Re: [PHP] Re: GeoIP?
Michelle Konzack wrote: Hello Per, Am 2009-03-15 15:12:47, schrieb Per Jessen: The easiest is to use a DNS service - this is the best one I know: http://countries.nerd.dk/ This is cool... I'm glad you like it - it really is cool. /Per -- Per Jessen, Zürich (4.1°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fork and zombies
Waynn Lue wrote: I periodically run a script that makes a call against a remote API, which takes some time to return. In an attempt to increase thoroughput, I decided to investigate using pnctl_fork to spawn off multiple processes to make the call, since the slowest part is the network part of it (and waiting for the server response). I ended up writing a script that did this: $pid = pnctl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { echo parent $pid\n; return; } else { // make API call } While this works, it unfortunately leaves behind a zombie process every single time. You need to call pcntl_wait() or pcntl_waitpid(). /Per -- Per Jessen, Zürich (4.2°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Re: GeoIP?
Thanks for this! -- Louie Miranda (lmira...@gmail.com) http://www.louiemiranda.net Quality Web Hosting - www.axishift.com Pinoy Web Hosting, Web Hosting Philippines On Mon, Mar 16, 2009 at 3:48 PM, Per Jessen p...@computer.org wrote: Michelle Konzack wrote: Hello Per, Am 2009-03-15 15:12:47, schrieb Per Jessen: The easiest is to use a DNS service - this is the best one I know: http://countries.nerd.dk/ This is cool... I'm glad you like it - it really is cool. /Per -- Per Jessen, Zürich (4.1°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Fork and zombies
Waynn Lue wrote: I periodically run a script that makes a call against a remote API, which takes some time to return. In an attempt to increase thoroughput, I decided to investigate using pnctl_fork to spawn off multiple processes to make the call, since the slowest part is the network part of it (and waiting for the server response). I ended up writing a script that did this: $pid = pnctl_fork(); if ($pid == -1) { die('could not fork'); } else if ($pid) { echo parent $pid\n; return; } else { // make API call } While this works, it unfortunately leaves behind a zombie process every single time. You need to call pcntl_wait() or pcntl_waitpid(). Right, but if I do that, then the parent has to wait until the child completes before it exits. Is there any way to have the parent exit before the child but prevent the zombie process for existing?
[PHP] How to catch fatal errors
Hello every body, I'm currently working on a very high traffic web sites. I often get a fatal error in production about memory Allowed memory size of ... exhausted. Unfortunately, I can not reproduce this fatal error in developpement environment. The main reason for that is that I don't know the php script which causes the error. Php only tell me on which file, the error has appeared, but I don't know the orginal php script which were called. I've tried some hacks, like the register_shutdown_function one. This hack allows me to catch almost all fatal errors, except one which says Allowed memory site of ... Any idea about how to catch this error? My main issue is to know script that has been called. Best regards
Re: [PHP] Fork and zombies
Waynn Lue wrote: While this works, it unfortunately leaves behind a zombie process every single time. You need to call pcntl_wait() or pcntl_waitpid(). Right, but if I do that, then the parent has to wait until the child completes before it exits. No it doesn't - just call pcntl_wait() with WNOHANG to check the status of a child. /Per -- Per Jessen, Zürich (6.5°C) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
Jim Lucas wrote: PJ wrote: haliphax wrote: On Fri, Mar 13, 2009 at 1:24 PM, PJ af.gour...@videotron.ca wrote: Jim Lucas wrote: PJ wrote: am resending as this was erroneously ccd to mysql. sorry! Ashley Sheridan wrote: On Thu, 2009-02-26 at 11:27 -0500, PJ wrote: Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto-insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk For some reason or other $autoId = mysql_insert_id($result); just does not work for me... Yet some of the data is inserted correctly... I did find that it does not work on tables that are empty... so you can't start with an empty table. I entered data it still did not work. I tried on another duplicate database... doesn't work. I have checked double checked the database, I have added checks to see what is returned and the returns are 0 or null - as I get different responses for slightly different functions. sessions is on mysql is 5.1.28 php5 here's what is parsed: else { $sql1 = INSERT INTO book           ( title, sub_title, descr, comment, bk_cover, copyright, ISBN, language, sellers )         VALUES           ('$titleIN', '$sub_titleIN', '$descrIN',           '$commentIN', '$bk_coverIN', '$copyrightIN', '$ISBNIN', '$languageIN', '$sellersIN');     $result1 = mysql_query($sql1, $db);   $autoid = mysql_insert_id($result1);     $sql2 = INSERT INTO author (first_name, last_name) VALUES ('$first_nameIN', '$last_nameIN');       $result2 = mysql_query($sql2, $db);   $authorID = mysql_insert_id($result2);     $sql2a = INSERT INTO book_author (authID, bookID, ordinal) VALUES ( '$authorID', '$autoid', '1');       $result2a = mysql_query($sql2a, $db);     $sql2b = INSERT INTO author (first_name, last_name) VALUES ('$first_name2IN', '$last_name2IN');       $result2b = mysql_query($sql2b, $db);   $author2ID = mysql_insert_id($result2b);     $sql2c = INSERT INTO book_author (authID, bookID, ordinal) VALUES ( '$author2ID', '$autoid', '2');       $result2c = mysql_query($sql2c, $db);     $sql3 = INSERT INTO publishers (publisher) VALUES ('$publisherIN');       $result3 = mysql_query($sql3, $db);   $publisherID = mysql_insert_id($result3);     $sql3a = INSERT INTO book_publisher (bookID, publishers_id) VALUES ( '$autoid', '$publisherID' );       $result3a = mysql_query($sql3a, $db);    Â
Re: [PHP] How to catch fatal errors
Tanoor Dieng schreef: Hello every body, I'm currently working on a very high traffic web sites. I often get a fatal error in production about memory Allowed memory size of ... exhausted. Unfortunately, I can not reproduce this fatal error in developpement environment. The main reason for that is that I don't know the php script which causes the error. Php only tell me on which file, the error has appeared, but I don't know the orginal php script which were called. I've tried some hacks, like the register_shutdown_function one. This hack allows me to catch almost all fatal errors, except one which says Allowed memory site of ... Any idea about how to catch this error? you can't - the script dies due to not enough memory, there is nothing the script/engine can do at that point (any action would require some more memory). My main issue is to know script that has been called. reproduce it in development, this probably means you will have to: 1. setup webserver/php conf/ini indentically to production 2. setup the dev env with a copy of live data most likely your issue revolves around too large a dataset being read in during some requests in the production env (e.g. a way too large product list) in the interim increase the php memory_limit on the production server to mitigate the problem (know that this only works if your server has the memory available ... too many webserver processes running the php engine with too much memory allocated will eventually cause physical memory to run out with the consequence that the OS will start to swap memory to disk, which will quickly bring your server grinding to a halt) Best regards -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Problem with passing and Area in a $_POST
At 1:30 PM -0700 3/15/09, Richard Kurth wrote: tedd wrote: At 8:56 AM -0700 3/15/09, Richard Kurth wrote: This is the form that is being sent as a post and the fieldorder[] is the part that is not sending properly. But it has worked for about a year in the script. It just stopped working. and I did not change anything in this script -snip- code If it was my problem, I see the script is riddled with inconsistencies. As such, I would pass it through validation to discover all the errors. Then I would fix those errors and then see if the problem continues. Granted, some people don't think validation is important, but I'm positive that I could get your script to work by simply cleaning up the code. Cheers, tedd You are probly right. But I got this script from Rasmus Lerdor about a year ago and I changed very little. It has worked just fine sence I started using it. Who am I to question Rasmus's coding. I am now using $_Request to capture the array for fieldorder[] and $_POST to get the rest of the data. You said: Who am I to question Rasmus's coding? I just review the code, not the author -- it just didn't look like informed code. The html was riddled with inconsistencies and had stuff that should have been in css. It certainly would not have been something I would have produced (at least not in the last five years or so). Besides, if your form is a POST and you can't see values returning, but can only see them in a REQUEST, then there's something wrong regardless of the author. A REQUEST provides value taken from GET, POST, and COOKIES (each override the other in some order). Have you looked at the possibility of COOKIES being in the mix? I'm not sure as to the logic of why a POST would be empty but a REQUEST would still hold the data, but it's something to consider. Also, you might investigate $_SERVER['REQUEST_METHOD'] to see where the data is coming from. Cheers, 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
[PHP] pdf_new() uncalled Function
Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us
Re: [PHP] pdf_new() uncalled Function
On Mon, Mar 16, 2009 at 10:06 AM, Alice Wei aj...@alumni.iu.edu wrote: Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us I like dompdf from www.digitaljunkies.ca Its a class that takes html and creates a pdf from it -- Bastien Cat, the other other white meat
Re: [PHP] How to catch fatal errors
On Mon, Mar 16, 2009 at 3:51 PM, Tanoor Dieng newstan...@gmail.com wrote: Hello every body, I'm currently working on a very high traffic web sites. I often get a fatal error in production about memory Allowed memory size of ... exhausted. Unfortunately, I can not reproduce this fatal error in developpement environment. Understandable why you cant reproduce the error. It gets generated when lots of queries has been done. Working on single environment is difficult to generate that. The main reason for that is that I don't know the php script which causes the error. You can do loadtesting or unit testing on the php scripts. Php only tell me on which file, the error has appeared, but I don't know the orginal php script which were called. I've tried some hacks, like the register_shutdown_function one. This hack allows me to catch almost all fatal errors, except one which says Allowed memory site of ... Any idea about how to catch this error? Would be a better idea to consult an experienced Web Application Architect who would sense the weaknesses of the codes and would suggest the reworks to make them optimized. Would be a hectic job for inexperienced developers. Lenin www.twitter.com/nine_L www.lenin9l.wordpress.com
[PHP] Re: pdf_new() uncalled Function
Alice Wei wrote: Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us If you have pear/pecl installed you can run: pecl install pdflib If not: yum install php-pear -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
RE: [PHP] pdf_new() uncalled Function
On Mon, Mar 16, 2009 at 10:06 AM, Alice Wei aj...@alumni.iu.edu wrote: Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us I like dompdf from www.digitaljunkies.ca Its a class that takes html and creates a pdf from it I saw online at http://us3.php.net/manual/en/pdf.installation.php that I could build PDF from some extension. However, I use Linux, and I don't think this installation using dll extension supports it. I ran the code and still get this error. Any ideas? Thanks for your help. Alice -- Bastien Cat, the other other white meat _ Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! http://get.live.com/toolbar/overview
Re: [PHP] pdf_new() uncalled Function
On Mon, Mar 16, 2009 at 11:32 AM, Alice Wei aj...@alumni.iu.edu wrote: On Mon, Mar 16, 2009 at 10:06 AM, Alice Wei aj...@alumni.iu.edu wrote: Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us I like dompdf from www.digitaljunkies.ca Its a class that takes html and creates a pdf from it I saw online at http://us3.php.net/manual/en/pdf.installation.php that I could build PDF from some extension. However, I use Linux, and I don't think this installation using dll extension supports it. I ran the code and still get this error. Any ideas? Thanks for your help. Alice -- Bastien Cat, the other other white meat _ Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! http://get.live.com/toolbar/overview for PECL based windows installation see http://us3.php.net/manual/en/install.pecl.downloads.php another option is FPDF from www.fpdf.org another class the classes are nice since they don't generally require the module to be installed. If you are on Linux, another option might be FOP... http://xmlgraphics.apache.org/fop/ -- Bastien Cat, the other other white meat
RE: [PHP] pdf_new() uncalled Function
Date: Mon, 16 Mar 2009 11:41:35 -0400 Subject: Re: [PHP] pdf_new() uncalled Function From: phps...@gmail.com To: aj...@alumni.iu.edu CC: php-general@lists.php.net On Mon, Mar 16, 2009 at 11:32 AM, Alice Wei aj...@alumni.iu.edu wrote: On Mon, Mar 16, 2009 at 10:06 AM, Alice Wei aj...@alumni.iu.edu wrote: Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us I like dompdf from www.digitaljunkies.ca Its a class that takes html and creates a pdf from it I saw online at http://us3.php.net/manual/en/pdf.installation.php that I could build PDF from some extension. However, I use Linux, and I don't think this installation using dll extension supports it. I ran the code and still get this error. Any ideas? Thanks for your help. Alice -- Bastien Cat, the other other white meat _ Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! http://get.live.com/toolbar/overviewfor PECL based windows installation see http://us3.php.net/manual/en/install.pecl.downloads.php another option is FPDF from www.fpdf.org another class the classes are nice since they don't generally require the module to be installed. If you are on Linux, another option might be FOP... http://xmlgraphics.apache.org/fop/ I checked out the first link you provided, and downloaded it. I don't think I need to edit anything else from the file according to the webpage http://www.digitaljunkies.ca/dompdf/install.php. I put the entire extracted directory at my /var/www/html directory. Is there any suggestion you could provide on how to install it? I don't see any commands that it provides in its manual. Thanks for your help. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us
Re: [PHP] pdf_new() uncalled Function
On Mon, Mar 16, 2009 at 10:06:32AM -0400, Alice Wei wrote: Hi, I use Linux, and I had installed PHP using yum install php. I am trying to use the pdf_new function to create pdfs from existing text files, but I get this error PHP Fatal error: Call to undefined function pdf_new() I have noticed that when I run the phpinfo() command, I cannot find the PDF phrase at all. My php.ini file does not even have these two lines extension=php_pdf.dll extension=php_cpdf.dll Could anyone suggest me what kind of command I should use if I need to build PDFs using PHP on a Linux system? Thanks in advance. Alice According to php.net, if you've installed PHP5 (which I assume is the case, since you used Yum to install it), you should not be using the pdf_new() function, but instead use the OO version: $pdf = new pdflib(); All this assumes that the PDFLib extension is actually installed. The documentation at php.net is a little confusing about whether this is an actual extension or not. Personally, I just install the add-on for this. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] A couple of questions
Guys, I had a page working on my opensuse 11.0 32bit, had to upgrade to 11.1 64bit. I have two strange issues. The first my code is being display when I call the page, I looked at the logs and I don't see any errors that explain why this happen. I looked at my php.ini and I don't see anything different or any outstanding. In fact I put in place my old php.ini to see if I got the same issue and I didn't. What that one I am getting include(): Failed opening 'template/header.inc' Is there a way I can do like sh -x on a php page to see what is broke? Thanks, Payne -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] pdf_new() uncalled Function
[snip] [/snip] another option is FPDF from www.fpdf.org another class the classes are nice since they don't generally require the module to be installed. If you are on Linux, another option might be FOP... http://xmlgraphics.apache.org/fop/ I checked out the first link you provided, and downloaded it. I don't think I need to edit anything else from the file according to the webpage http://www.digitaljunkies.ca/dompdf/install.php. I put the entire extracted directory at my /var/www/html directory. Is there any suggestion you could provide on how to install it? I don't see any commands that it provides in its manual. Thanks for your help. Alice _ Express yourself with gadgets on Windows Live Spaces http://discoverspaces.live.com?source=hmtag1loc=us Its a class set of files, so there is no real install. I just placed the folder containing the class files in my dir and in the calling page, required() the main file. The dompdf.inc.php file is where i handle the filesystem links -- Bastien Cat, the other other white meat
Re: [PHP] Re: GeoIP?
Nitsan Bin-Nun escreveu: Hi Michelle, Try to use sqlite instead of any other database. It will be better I guess. Regards, Nitsan On Sun, Mar 15, 2009 at 9:08 PM, zerof . wrote: Please, avoid to reply our messages with entire heads. I don't like to see my email along these. zerof -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A couple of questions
2009/3/16 Payne pa...@magidesign.com I had a page working on my opensuse 11.0 32bit, had to upgrade to 11.1 64bit. I have two strange issues. The first my code is being display when I call the page, I looked at the logs and I don't see any errors that explain why this happen. I looked at my php.ini and I don't see anything different or any outstanding. In fact I put in place my old php.ini to see if I got the same issue and I didn't. What that one I am getting include(): Failed opening 'template/header.inc' Is there a way I can do like sh -x on a php page to see what is broke? Check your include_path setting - my guess is that it doesn't include the current directory (.). -Stuart -- http://stut.net/
Re: [PHP] A couple of questions
2009/3/16 Stuart stut...@gmail.com 2009/3/16 Payne pa...@magidesign.com I had a page working on my opensuse 11.0 32bit, had to upgrade to 11.1 64bit. I have two strange issues. The first my code is being display when I call the page, I looked at the logs and I don't see any errors that explain why this happen. I looked at my php.ini and I don't see anything different or any outstanding. In fact I put in place my old php.ini to see if I got the same issue and I didn't. What that one I am getting include(): Failed opening 'template/header.inc' Is there a way I can do like sh -x on a php page to see what is broke? Check your include_path setting - my guess is that it doesn't include the current directory (.). -Stuart -- http://stut.net/ The first my code is being display when I call the page It sounds like you may have been using short tags. Check for short_open_tag and turn it On: short_open_tag = On Or go through your code and replace ? with ?php The second option is best. Nick
Re: [PHP] A couple of questions
Nick Cooper wrote: 2009/3/16 Stuart stut...@gmail.com mailto:stut...@gmail.com 2009/3/16 Payne pa...@magidesign.com mailto:pa...@magidesign.com I had a page working on my opensuse 11.0 32bit, had to upgrade to 11.1 64bit. I have two strange issues. The first my code is being display when I call the page, I looked at the logs and I don't see any errors that explain why this happen. I looked at my php.ini and I don't see anything different or any outstanding. In fact I put in place my old php.ini to see if I got the same issue and I didn't. What that one I am getting include(): Failed opening 'template/header.inc' Is there a way I can do like sh -x on a php page to see what is broke? Check your include_path setting - my guess is that it doesn't include the current directory (.). -Stuart -- http://stut.net/ The first my code is being display when I call the page It sounds like you may have been using short tags. Check for short_open_tag and turn it On: short_open_tag = On Or go through your code and replace ? with ?php The second option is best. Nick Nick you where right, I had ? and not ?php thanks. I am working on the path issue. I am not sure why, but it calling that file in the apache root folder and not home. Payne -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] A couple of questions
2009/3/16 Payne pa...@magidesign.com Nick Cooper wrote: 2009/3/16 Stuart stut...@gmail.com mailto:stut...@gmail.com 2009/3/16 Payne pa...@magidesign.com mailto:pa...@magidesign.com I had a page working on my opensuse 11.0 32bit, had to upgrade to 11.1 64bit. I have two strange issues. The first my code is being display when I call the page, I looked at the logs and I don't see any errors that explain why this happen. I looked at my php.ini and I don't see anything different or any outstanding. In fact I put in place my old php.ini to see if I got the same issue and I didn't. What that one I am getting include(): Failed opening 'template/header.inc' Is there a way I can do like sh -x on a php page to see what is broke? Check your include_path setting - my guess is that it doesn't include the current directory (.). -Stuart -- http://stut.net/ The first my code is being display when I call the page It sounds like you may have been using short tags. Check for short_open_tag and turn it On: short_open_tag = On Or go through your code and replace ? with ?php The second option is best. Nick Nick you where right, I had ? and not ?php thanks. I am working on the path issue. I am not sure why, but it calling that file in the apache root folder and not home. Check the archives - current working directory issues were recently discussed. -Stuart -- http://stut.net/
RE: [PHP] pdf_new() uncalled Function
[/snip] another option is FPDF from www.fpdf.org another class the classes are nice since they don't generally require the module to be installed. If you are on Linux, another option might be FOP... http://xmlgraphics.apache.org/fop/ I checked out the first link you provided, and downloaded it. I don't think I need to edit anything else from the file according to the webpage http://www.digitaljunkies.ca/dompdf/install.php. I put the entire extracted directory at my /var/www/html directory. Is there any suggestion you could provide on how to install it? I don't see any commands that it provides in its manual. Thanks for your help. Its a class set of files, so there is no real install. I just placed the folder containing the class files in my dir and in the calling page, required() the main file. The dompdf.inc.php file is where i handle the filesystem links Looks like the files I wanted to turn into PDF are not web pages, but most of them are text files. I am still hoping to use the function pdf_new to get this to work by assembling some modules. Is what I am trying to do here not possible? Thanks for your help. Alice -- Bastien Cat, the other other white meat _ Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! http://get.live.com/toolbar/overview
Re: [PHP] pdf_new() uncalled Function
On Mon, Mar 16, 2009 at 1:48 PM, Alice Wei aj...@alumni.iu.edu wrote: [/snip] another option is FPDF from www.fpdf.org another class the classes are nice since they don't generally require the module to be installed. If you are on Linux, another option might be FOP... http://xmlgraphics.apache.org/fop/ I checked out the first link you provided, and downloaded it. I don't think I need to edit anything else from the file according to the webpage http://www.digitaljunkies.ca/dompdf/install.php. I put the entire extracted directory at my /var/www/html directory. Is there any suggestion you could provide on how to install it? I don't see any commands that it provides in its manual. Thanks for your help. Its a class set of files, so there is no real install. I just placed the folder containing the class files in my dir and in the calling page, required() the main file. The dompdf.inc.php file is where i handle the filesystem links Looks like the files I wanted to turn into PDF are not web pages, but most of them are text files. I am still hoping to use the function pdf_new to get this to work by assembling some modules. Is what I am trying to do here not possible? Thanks for your help. Alice -- Bastien Cat, the other other white meat -- Search from any Web page with powerful protection. Get the FREE Windows Live Toolbar Today! Try it now! http://get.live.com/toolbar/overview I don't see why not, just create a page that will pull in the data and then format it nicely -- Bastien Cat, the other other white meat
Re: [PHP] Re: GeoIP?
On Mon, Mar 16, 2009 at 12:01, zerof ze...@terra.com.br wrote: Please, avoid to reply our messages with entire heads. I don't like to see my email along these. Then unsubscribe. Before subscribing and posting to any mailing list, you should read the rules and regulations of the list. Had you done so here, you'd have seen: Be sure to click Reply-All to reply to list. Clicking Reply will email the author of the message privately. It's one of the guidelines on http://php.net/mailinglists, and it's been the practice of this mailing list for years. There is no desire or plan to change this. -- /Daniel P. Brown daniel.br...@parasane.net || danbr...@php.net http://www.parasane.net/ || http://www.pilotpig.net/ 50% Off All Shared Hosting Plans at PilotPig: Use Coupon DOW1 -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
PJ wrote: Jim Lucas wrote: PJ wrote: haliphax wrote: On Fri, Mar 13, 2009 at 1:24 PM, PJ af.gour...@videotron.ca wrote: Jim Lucas wrote: PJ wrote: am resending as this was erroneously ccd to mysql. sorry! Ashley Sheridan wrote: On Thu, 2009-02-26 at 11:27 -0500, PJ wrote: Jerry Schwartz wrote: Being rather new to all this, I understood from the MySql manual that the auto_increment is to b e used immediately after an insertion not intermittently. My application is for administrators (the site owner designates) to update the database from and administration directory, accessed by user/password login... so there's really very little possibility of 2 people accessing at the same time. By using MAX + 1 I keep the id number in the $idIn and can reuse it in other INSERTS [JS] Are you looking for something like LAST_INSERT_ID()? If you INSERT a record that has an auto-increment field, you can retrieve the value that got inserted with SELECT LAST_INSERT_ID(). It is connection-specific, so you'll always have your own value. You can then save it to reuse, either as a session variable or (more easily) as a hidden field on your form. Thanks, Jerry, You hit the nail on the head.:) To refine my problem (and reduce my ignorance),here's what is happening on the form page: There is a series of INSERTs. The first inserts all the columns of book table except for the id, which I do not specify as it if auto-insert. In subsequent tables I have to reference the book.id (for transitional tables like book_author(refers authors to book) etc. If I understand it correctly, I must retrieve (SELECT LAST_INSERT_ID()) after the first INSERT and before the following insert; and save the id as a string ($id)...e.g. $sql = SELECT LAST_INSERT_ID() AS $id I need clarification on the AS $id - should this be simply id(does this have to be turned into a value into $id or does $id contain the value? And how do I retrieve it to use the returned value for the next $sql = INSERT ... - in other words, is the id or $id available for the next directive or do I have to do something like $id = id? I'm trying to figure this out with some trials but my insert does not work from a php file - but it works from command-line... that's another post. Here's how I mostly do it (albeit simplified): $query = INSERT INTO `sometable`(`title`,`content`) VALUES('$title','$content'); $result = mysql_query($query); $autoId = mysql_insert_id($result); $query = INSERT INTO `another_table`(`link_id`,`value`) VALUES($autoId,'$value'); $result = mysql_query($query); No need to call another query to retrieve the last inserted id, as it is tied to the last query executed within this session. Ash www.ashleysheridan.co.uk For some reason or other $autoId = mysql_insert_id($result); just does not work for me... Yet some of the data is inserted correctly... I did find that it does not work on tables that are empty... so you can't start with an empty table. I entered data it still did not work. I tried on another duplicate database... doesn't work. I have checked double checked the database, I have added checks to see what is returned and the returns are 0 or null - as I get different responses for slightly different functions. sessions is on mysql is 5.1.28 php5 here's what is parsed: else { $sql1 = INSERT INTO book           ( title, sub_title, descr, comment, bk_cover, copyright, ISBN, language, sellers )         VALUES           ('$titleIN', '$sub_titleIN', '$descrIN',           '$commentIN', '$bk_coverIN', '$copyrightIN', '$ISBNIN', '$languageIN', '$sellersIN');     $result1 = mysql_query($sql1, $db);   $autoid = mysql_insert_id($result1);     $sql2 = INSERT INTO author (first_name, last_name) VALUES ('$first_nameIN', '$last_nameIN');       $result2 = mysql_query($sql2, $db);   $authorID = mysql_insert_id($result2);     $sql2a = INSERT INTO book_author (authID, bookID, ordinal) VALUES ( '$authorID', '$autoid', '1');       $result2a = mysql_query($sql2a, $db);     $sql2b = INSERT INTO author (first_name, last_name) VALUES ('$first_name2IN', '$last_name2IN');       $result2b = mysql_query($sql2b, $db);   $author2ID = mysql_insert_id($result2b);     $sql2c = INSERT INTO book_author (authID, bookID, ordinal) VALUES ( '$author2ID', '$autoid', '2');       $result2c = mysql_query($sql2c, $db);     $sql3 = INSERT INTO publishers (publisher) VALUES ('$publisherIN');       $result3 = mysql_query($sql3, $db);   $publisherID = mysql_insert_id($result3);     $sql3a = INSERT INTO book_publisher (bookID, publishers_id) VALUES ( '$autoid', '$publisherID' );       $result3a = mysql_query($sql3a, $db);     foreach($_POST['categoriesIN'] as $category){       $sql4 = INSERT INTO book_categories (book_id, categories_id)    Â
[PHP] strcmp() versus ==
I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
On Mon, Mar 16, 2009 at 03:46:29PM -0500, PJ wrote: snip $book_publisher = array(); $SQL = SELECT id, bookID, publisher_id FROM book_publisher; if ( ( $results = mysql_query($SQL, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $book_publisher[$row['bookID']][] = $row['publisher_id']; Could you explain this, please - this is further from me than Arcturus: $book_publisher[$row['bookID']][] = $row['publisher_id']; What is purpose and meaning of all the [] brackets? Especially the empty ones? I following your example, I have been able to finally get all the arrays in place. Only now, I am looking into how to retrieve the parts of the array... PJ, you *really* need to read up on the *basics* of the PHP language. Please buy a good book on the subject, or search php.net for arrays and read and understand what is there. To summarize, $book_publisher is an array, as you can tell by the square brackets after it. Its first index is book IDs. So in the expression $book_publisher[$row['bookID']], $row['bookID'] is the index for one of the members of the array. It could be 5 instead, as in: $book_publisher[5]. Likewise, $row is an array. When you see an expression like $array['something'] or $array[1], the value being represented is actually the value at that index of the array. If you have an array of letters called $alphabet, it might look something like this: indexes: 'a', 'b', 'c', 'd', 'e' contents: 'alfa', 'bravo', 'charlie', 'delta', 'echo' So if you had an expression like: $alphabet['d'], it would actually represent the value 'delta'. Read the above until that's clear. In the case of $row['bookID'], it's just a value at the 'bookID' index of the $row array. It could be '1234', '55-345' or whatever. So $book_publisher[$row['bookID']] is the array member at the $row['bookID'] index of the array. Lastly, since an array member can also be another array, you can have multidimensional arrays. In your case, it's: $book_publisher[$row['bookID']][] Notice the last set of open and close backets on the end. That tells you that $book_publisher[$row['bookID']] is an array member which is actually another array. But empty open/close brackets have a special meaning. You will only find them (meaningfully) on the left hand side of an equation. They mean that you're adding whatever is on the right side of the equation to the last position in the array. So $book_publisher[$row['bookID']][] = $row['publisher_id'] Says that the $row['bookID'] member of $book_publisher is an array, and that you're adding a member on the end whose value is $row['publisher_id']. Depending on your mental abilities, you may have to draw the arrays on a sheet of paper to make it make sense. Also remember that arrays can be indexed either numerically or associatively or both. A numerically indexed arrays would have just numbers for the indexes. An associatively indexed array is what you have above, indexed not necessarily by number but possibly by strings or whatever. All this is fundamental to array processing under PHP and used constantly. So learn it and learn it well. If my explanation is insufficient, then look it up and fully understand it before you go on. Otherwise, you'll take one step, ask a bunch of questions, take another step, ask a bunch of questions, and generally make yourself a nuisance. You're essentially asking professional programmers to tutor you for free when you really should take the initiative and read/study the subject yourself. It doesn't matter if you don't really want to *be* a professional programmer at the end of this. You have to approach it as though that's your goal. Let me put this another way. Assume you're a professional chef. You get paid lots of money to cook food for people. You've had years of education and practice and get paid accordingly. Suddenly one day, management sends you some wet-behind-the-ears kid who's flipped burgers at McDonalds, and you're supposed to teach him how to cook like you do. Every time he cuts a shallot or dices an onion, he asks you a bunch of silly questions he should know if he had gone to culinary school like you did. You're busy. And the questions are things like What's the difference between a teaspoon and a tablespoon?. How come I have to dice onions? Can't I just throw them in the pot? And you know that the only reason the kid is there is so he can learn to cook some stuff to impress his girlfriend, who's gonna dump him in three months anyway. Think about it. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: strcmp() versus ==
Paul M Foster wrote: I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul I would use $str1 === $str2 if you want to make sure they are both strings and both the same value. Since PHP is loosely typed, 0 == 0 is true however 0 === 0 is false. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
Paul M Foster wrote: On Mon, Mar 16, 2009 at 03:46:29PM -0500, PJ wrote: snip $book_publisher = array(); $SQL = SELECT id, bookID, publisher_id FROM book_publisher; if ( ( $results = mysql_query($SQL, $db) ) !== false ) { while ( $row = mysql_fetch_assoc($results) ) { $book_publisher[$row['bookID']][] = $row['publisher_id']; Could you explain this, please - this is further from me than Arcturus: $book_publisher[$row['bookID']][] = $row['publisher_id']; What is purpose and meaning of all the [] brackets? Especially the empty ones? I following your example, I have been able to finally get all the arrays in place. Only now, I am looking into how to retrieve the parts of the array... PJ, you *really* need to read up on the *basics* of the PHP language. Please buy a good book on the subject, or search php.net for arrays and read and understand what is there. To summarize, $book_publisher is an array, as you can tell by the square brackets after it. Its first index is book IDs. So in the expression $book_publisher[$row['bookID']], $row['bookID'] is the index for one of the members of the array. It could be 5 instead, as in: $book_publisher[5]. Likewise, $row is an array. When you see an expression like $array['something'] or $array[1], the value being represented is actually the value at that index of the array. If you have an array of letters called $alphabet, it might look something like this: indexes: 'a', 'b', 'c', 'd', 'e' contents: 'alfa', 'bravo', 'charlie', 'delta', 'echo' So if you had an expression like: $alphabet['d'], it would actually represent the value 'delta'. Read the above until that's clear. In the case of $row['bookID'], it's just a value at the 'bookID' index of the $row array. It could be '1234', '55-345' or whatever. So $book_publisher[$row['bookID']] is the array member at the $row['bookID'] index of the array. Lastly, since an array member can also be another array, you can have multidimensional arrays. In your case, it's: $book_publisher[$row['bookID']][] Notice the last set of open and close backets on the end. That tells you that $book_publisher[$row['bookID']] is an array member which is actually another array. But empty open/close brackets have a special meaning. You will only find them (meaningfully) on the left hand side of an equation. They mean that you're adding whatever is on the right side of the equation to the last position in the array. So $book_publisher[$row['bookID']][] = $row['publisher_id'] Says that the $row['bookID'] member of $book_publisher is an array, and that you're adding a member on the end whose value is $row['publisher_id']. Depending on your mental abilities, you may have to draw the arrays on a sheet of paper to make it make sense. Also remember that arrays can be indexed either numerically or associatively or both. A numerically indexed arrays would have just numbers for the indexes. An associatively indexed array is what you have above, indexed not necessarily by number but possibly by strings or whatever. All this is fundamental to array processing under PHP and used constantly. So learn it and learn it well. If my explanation is insufficient, then look it up and fully understand it before you go on. Otherwise, you'll take one step, ask a bunch of questions, take another step, ask a bunch of questions, and generally make yourself a nuisance. You're essentially asking professional programmers to tutor you for free when you really should take the initiative and read/study the subject yourself. It doesn't matter if you don't really want to *be* a professional programmer at the end of this. You have to approach it as though that's your goal. Let me put this another way. Assume you're a professional chef. You get paid lots of money to cook food for people. You've had years of education and practice and get paid accordingly. Suddenly one day, management sends you some wet-behind-the-ears kid who's flipped burgers at McDonalds, and you're supposed to teach him how to cook like you do. Every time he cuts a shallot or dices an onion, he asks you a bunch of silly questions he should know if he had gone to culinary school like you did. You're busy. And the questions are things like What's the difference between a teaspoon and a tablespoon?. How come I have to dice onions? Can't I just throw them in the pot? And you know that the only reason the kid is there is so he can learn to cook some stuff to impress his girlfriend, who's gonna dump him in three months anyway. Think about it. Paul Thanks Paul for the explanation. It really does help and iis much appreciated. I must respond to your chastisement of me, because i believe you may not be aware of the fact that most books on programming really suck. I have had my taste of enough of them to not bother. The kinds of things that I am trying to do just cannot be learned from a book or from most of
[PHP] Re: strcmp() versus ==
Shawn McKenzie wrote: Paul M Foster wrote: I had never completely read over the rules with regard to comparisons in PHP, and was recently alarmed to find that $str1 == $str2 might not compare the way I thought they would. Is it common practice among PHP coders to use strcmp() instead of == in making string comparisons? Or am I missing/misreading something? Paul I would use $str1 === $str2 if you want to make sure they are both strings and both the same value. Since PHP is loosely typed, 0 == 0 is true however 0 === 0 is false. If you want to force a string comparison you can also use: (string)$str1 == (string)$str2 -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Studying IF statements
Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Summary Report With Details - Newbie Question
On 3/14/2009 5:13 PM, Christian Wagner ch...@unna-youth.de wrote: Hi, I would select all items with a single select. SELECT name,model, condition (etc) FROM inventory Then i'll iterate through the resultset and store them in an array like this $items = array(); while($row = next()) { // Gives the total amount of Models $items[$row['model']] = $counter++; // Stores the condition of a single item of a model // $items[$row['model']] makes sure, that the single item // will be stored at the correct position // $items[$row['model']][$row['id']] = $row['condition']; } Here's my query... (no group by - right?) mysql_select_db($database_test, $ test); $query_getall = SELECT id, model,condition FROM inventory ORDER BY model ASC; $getall = mysql_query($query_getall, $test) or die(mysql_error()); $row_getall = mysql_fetch_assoc($getall); $totalRows_getall = mysql_num_rows($getall); Thanks for your help Christian, I guess my 'newbie' is showing ... Because I'm having trouble getting this to work... 1 - on this line I get : Warning: Wrong parameter count for next() in /Libr... while($row = next()) - I tried this - with no errors while($row = mysql_fetch_assoc($getall)); // not sure if it's right? -- 2 - Then got error here: Warning: Cannot use a scalar value as an array in /Library/WebServer $items[$row['model']][$row['id']] = $row['condition']; Q: How can I fix this? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Studying IF statements
Gary wrote: Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? Well, first, it shouldn't do anything because you have parse errors that should stop the script. On your very first line you haven't surround the email in quotes (only one quote). Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. Second, you look for empty vars and if they are empty then you echo that they forgot to enter them but go on to send the emails anyway. Then you loop through a database result and send to everyone and then you send another one to the last person you just sent to. Try this: ?php $from = 'em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject) || empty($body_of_mail)) { die 'You forgot to enter a subject and or text in the body! br /Click the back buttonbr /'; } else { $dbc = mysqli_connect('hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } mysqli_close($dbc); } ? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Summary Report With Details - Newbie Question
On 3/14/2009 9:31 PM, Paul M Foster pa...@quillandmouse.com wrote: I'm not an expert, but the way I normally do something like this is with a join that would give name, model and condition on each row (so you have a lot of duplicate fields which are the same for a series of records). I make sure they're ordered properly, and then process them in a loop. Something like: $product = ''; $count = 0; while ($a = fetch_array()) { if ($product != $a['name']) { // do whatever for prior product // do whatever for new product // $count will be the number of a given product $product = $a['name']; } else { $count++; // print out whatever you need to } } Hi Paul - I appreciate your assistance, $product = ''; $count = 1; while ($a = mysql_fetch_assoc($getall)) { if ($product != $a['model']) { echo 'br/ COUNT: '.$count.' final previous'.'br/br/'; $count = 1; // resets count for each new model echo ' model: '.$a['model'].'br/br/'; // model title line echo $a['id'].' - condition: '.$a['loc'].' 1br/'; // start detail row list $product = $a['model']; } else { $count++; echo $a['id'].' - condition: '.$a['condition'].' 2 br/'; } } -- Produces something like: COUNT: 39 (final previous) model: MODEL 22-A 34 - condition: good 33 - new 32 - old 305 - new Etc... Paul - this seems to work (if I understand you correctly...), but I would like to have a title line (above) say: MODEL - 22-A - COUNT: 39 At the top ... Currently - the way I have it wants to display the *count BELOW* the line items - (when it's done counting) .. And I fooled with this line; echo 'br/ COUNT: '.$count.' final previous'.'br/br/'; Which 'sort of' shows at top - but doesn't really help the 1st item... Q: any way to improve this? -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Studying IF statements
Shawn Thanks for your reply. Some of what you are saying is a little ahead of my lessons, but let me address as best I can. The script worked fine in the previous lesson where I was to send emails from my DB, this lesson is to kill the email from being sent if empty. On your very first line you haven't surround the email in quotes (only one quote). That worked fine with the single quotes and is listed in the book that way. Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. The single quote was deleted when I was sanitizing the code to post here, but it is in the code...sorry. So the jist of what you are saying is to add die after the if statements...but they are not in the book * I tried your code and it was not working either, am getting a parse error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in on line 109 Line 109 die 'You forgot to enter a subject and or text in the body! br/Click the back buttonbr /'; Shawn McKenzie nos...@mckenzies.net wrote in message news:b8.22.22219.724fe...@pb1.pair.com... Gary wrote: Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? Well, first, it shouldn't do anything because you have parse errors that should stop the script. On your very first line you haven't surround the email in quotes (only one quote). Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. Second, you look for empty vars and if they are empty then you echo that they forgot to enter them but go on to send the emails anyway. Then you loop through a database result and send to everyone and then you send another one to the last person you just sent to. Try this: ?php $from = 'em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject) || empty($body_of_mail)) { die 'You forgot to enter a subject and or text in the body! br /Click the back buttonbr /'; } else { $dbc = mysqli_connect('hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } mysqli_close($dbc); } ? -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: [PHP-DB] SQL for counting comments - is this smart?
Chris napsal(a): Martin Zvarík wrote: Is it smart to use all of this on one page? Or should I rather do one SQL and let PHP count it? $q = $DB-q(SELECT COUNT(*) FROM comments); $int_total = $DB-frow($q); $q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved IS NULL); $int_waiting = $DB-frow($q); $q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=0); $int_deleted = $DB-frow($q); $q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=1); $int_approved = $DB-frow($q); $q = $DB-q(SELECT COUNT(*) FROM comments WHERE approved=2); $int_banned = $DB-frow($q); Each one of these probably going to scan the whole table because the approved column isn't going to be selective enough to use an index. You might be better off doing: select approved, count(*) from comments group by approved; then in php separating them out: while ($row = $DB-frow($q)) { switch ($row['approved']) { case null: $waiting = $row['count']; break; case 0: $deleted = $row['count']; break; case 1: $approved = $row['count']; break; } } $total = $waiting + $approved + $deleted; Duh, of course, thanks :) -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Studying IF statements
Gary wrote: Shawn Thanks for your reply. Some of what you are saying is a little ahead of my lessons, but let me address as best I can. The script worked fine in the previous lesson where I was to send emails from my DB, this lesson is to kill the email from being sent if empty. On your very first line you haven't surround the email in quotes (only one quote). That worked fine with the single quotes and is listed in the book that way. Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. The single quote was deleted when I was sanitizing the code to post here, but it is in the code...sorry. So the jist of what you are saying is to add die after the if statements...but they are not in the book * I tried your code and it was not working either, am getting a parse error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in on line 109 Line 109 die 'You forgot to enter a subject and or text in the body! br/Click the back buttonbr /'; Shawn McKenzie nos...@mckenzies.net wrote in message news:b8.22.22219.724fe...@pb1.pair.com... Gary wrote: Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? Well, first, it shouldn't do anything because you have parse errors that should stop the script. On your very first line you haven't surround the email in quotes (only one quote). Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. Second, you look for empty vars and if they are empty then you echo that they forgot to enter them but go on to send the emails anyway. Then you loop through a database result and send to everyone and then you send another one to the last person you just sent to. Try this: ?php $from = 'em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject) || empty($body_of_mail)) { die 'You forgot to enter a subject and or text in the body! br /Click the back buttonbr /'; } else { $dbc = mysqli_connect('hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } mysqli_close($dbc); } ? -- Thanks! -Shawn http://www.spidean.com So goes the typing code in to email :-) Try replacing the die line with: die('You forgot to enter a subject and or text in the body!br /Click the back button.br /'); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Studying IF statements
That workedthats much for all your help.. Gary Shawn McKenzie nos...@mckenzies.net wrote in message news:94.66.22219.71ffe...@pb1.pair.com... Gary wrote: Shawn Thanks for your reply. Some of what you are saying is a little ahead of my lessons, but let me address as best I can. The script worked fine in the previous lesson where I was to send emails from my DB, this lesson is to kill the email from being sent if empty. On your very first line you haven't surround the email in quotes (only one quote). That worked fine with the single quotes and is listed in the book that way. Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. The single quote was deleted when I was sanitizing the code to post here, but it is in the code...sorry. So the jist of what you are saying is to add die after the if statements...but they are not in the book * I tried your code and it was not working either, am getting a parse error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in on line 109 Line 109 die 'You forgot to enter a subject and or text in the body! br/Click the back buttonbr /'; Shawn McKenzie nos...@mckenzies.net wrote in message news:b8.22.22219.724fe...@pb1.pair.com... Gary wrote: Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? Well, first, it shouldn't do anything because you have parse errors that should stop the script. On your very first line you haven't surround the email in quotes (only one quote). Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. Second, you look for empty vars and if they are empty then you echo that they forgot to enter them but go on to send the emails anyway. Then you loop through a database result and send to everyone and then you send another one to the last person you just sent to. Try this: ?php $from = 'em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject) || empty($body_of_mail)) { die 'You forgot to enter a subject and or text in the body! br /Click the back buttonbr /'; } else { $dbc = mysqli_connect('hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } mysqli_close($dbc); } ? -- Thanks! -Shawn http://www.spidean.com So goes the typing code in to email :-) Try replacing the die line with: die('You forgot to enter a subject and or text in the body!br /Click the back button.br /'); -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: Studying IF statements
Shawn McKenzie wrote: Gary wrote: Shawn Thanks for your reply. Some of what you are saying is a little ahead of my lessons, but let me address as best I can. The script worked fine in the previous lesson where I was to send emails from my DB, this lesson is to kill the email from being sent if empty. On your very first line you haven't surround the email in quotes (only one quote). That worked fine with the single quotes and is listed in the book that way. Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. The single quote was deleted when I was sanitizing the code to post here, but it is in the code...sorry. So the jist of what you are saying is to add die after the if statements...but they are not in the book * I tried your code and it was not working either, am getting a parse error Parse error: syntax error, unexpected T_CONSTANT_ENCAPSED_STRING in on line 109 Line 109 die 'You forgot to enter a subject and or text in the body! br/Click the back buttonbr /'; Shawn McKenzie nos...@mckenzies.net wrote in message news:b8.22.22219.724fe...@pb1.pair.com... Gary wrote: Reading a book on php/mysql (Head First) and the following code is not working, athough I am pretty sure I have it as they say to. Trying to kill a sendmail script if I forget to enter a subject or text in body of email. I am getting the echo, but it is still sending the emails out. What am I missing here? Thanks. Gary ?php $from = em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject)) { if(empty($body_of_mail)){ echo 'You forgot to enter a subject and or text in the body! br /'; $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } $msg =Dear $first_name.' '.$last_name\n $text; mail($to,$subject,$msg,$from); echo Email sent to: $to br / ; mysqli_close($dbc); } } ? Well, first, it shouldn't do anything because you have parse errors that should stop the script. On your very first line you haven't surround the email in quotes (only one quote). Then later in the line $dbc = mysqli_connect(hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); you're missing a quote before hostet. Second, you look for empty vars and if they are empty then you echo that they forgot to enter them but go on to send the emails anyway. Then you loop through a database result and send to everyone and then you send another one to the last person you just sent to. Try this: ?php $from = 'em...@email.com'; $subject =$_POST['subject']; $text =$_POST['body_of_mail']; if(empty($subject) || empty($body_of_mail)) { die 'You forgot to enter a subject and or text in the body! br /Click the back buttonbr /'; } else { $dbc = mysqli_connect('hostet',UN,'PW','DB') or die('Error connecting to MySQL server'); $query = SELECT * FROM table; $result = mysqli_query($dbc, $query) or die('Error querying database.'); while ($row = mysqli_fetch_array($result)) { $to = $row['email']; $first_name = $row['first_name']; $last_name = $row['last_name']; $msg = Dear $first_name $last_name,\n$text; mail($to, $subject, $msg, 'From:' . $from); echo 'Email sent to: ' . $to . 'br /'; } mysqli_close($dbc); } ? -- Thanks! -Shawn http://www.spidean.com So goes the typing code in to email :-) Try replacing the die line with: die('You forgot to enter a subject and or text in the body!br /Click the back button.br /'); This is just an example using the code that you posted as a learning exercise. Your original IF said: if $subject is empty, then evaluate the next if $body_of_mail is empty, if so, then echo 'You forgot to enter a subject and or text in the body! br /' THEN execute the rest of the code which returns records from the db and then loops through them and send an email to the addresses from the db query. I just added a die() which kills the script execution IF the fields are empty and an ELSE, which is evaluated if the fields are NOT empty, that does the db query and email. In a real world example, instead of die() you might reload the form and display a message, so that the user can correct mistakes and resubmit. -- Thanks! -Shawn http://www.spidean.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Summary Report With Details - Newbie Question
On Mon, Mar 16, 2009 at 05:57:13PM -0700, revDAVE wrote: On 3/14/2009 9:31 PM, Paul M Foster pa...@quillandmouse.com wrote: I'm not an expert, but the way I normally do something like this is with a join that would give name, model and condition on each row (so you have a lot of duplicate fields which are the same for a series of records). I make sure they're ordered properly, and then process them in a loop. Something like: $product = ''; $count = 0; while ($a = fetch_array()) { if ($product != $a['name']) { // do whatever for prior product // do whatever for new product // $count will be the number of a given product $product = $a['name']; } else { $count++; // print out whatever you need to } } Hi Paul - I appreciate your assistance, $product = ''; $count = 1; while ($a = mysql_fetch_assoc($getall)) { if ($product != $a['model']) { echo 'br/ COUNT: '.$count.' final previous'.'br/br/'; $count = 1; // resets count for each new model echo ' model: '.$a['model'].'br/br/'; // model title line echo $a['id'].' - condition: '.$a['loc'].' 1br/'; // start detail row list $product = $a['model']; } else { $count++; echo $a['id'].' - condition: '.$a['condition'].' 2 br/'; } } -- Produces something like: COUNT: 39 (final previous) model: MODEL 22-A 34 - condition: good 33 - new 32 - old 305 - new Etc... Paul - this seems to work (if I understand you correctly...), but I would like to have a title line (above) say: MODEL - 22-A - COUNT: 39 At the top ... Currently - the way I have it wants to display the *count BELOW* the line items - (when it's done counting) .. And I fooled with this line; echo 'br/ COUNT: '.$count.' final previous'.'br/br/'; Which 'sort of' shows at top - but doesn't really help the 1st item... Q: any way to improve this? Well, I was dubious about my answer, based on the idea that someone else might have a better way. However, it appears not. So what I would do is probably, instead of echoing stuff immediately, I'd just append it to a string until you're ready to output a total line. Then output the total line, and immediately after, output the string you accumulated while counting. Make sense? The whole point in the first place, as I recall, was to avoid umpteen database queries. So what you're doing is to load it all up at once and then let PHP do the heavy work instead of the database. But the total you want is only available after you've processed all the records for that item/model. So if you want it to come first on screen, you'll have to accumulate all your detail lines as you go. Then when the total is ready, output that and then output all the stuff you've accumulated. I don't know any better way to do it. If it's still not clear, let me know. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
On Mon, Mar 16, 2009 at 06:05:33PM -0500, PJ wrote: Paul M Foster wrote: snip Thanks Paul for the explanation. It really does help and iis much appreciated. I must respond to your chastisement of me, because i believe you may not be aware of the fact that most books on programming really suck. I have had my taste of enough of them to not bother. The kinds of things that I am trying to do just cannot be learned from a book or from most of those tutorials one finds on the Internet. How do you think *I* learned this? Back in 1974, when I hooked up my high school teletype via an acoustic modem to the school district mainframe and logged in for the first time, I had one choice for programming languages: Mainframe (Dartmouth) BASIC. So I bought a book on the subject, still in print today, called Basic Basic. Thus I learned Pascal (Turbo Pascal). Thus I learned C (Kernighan and Richie). Thus I learned Linux (man pages). Thus I learned Perl, Python and PHP. *All* from books. I didn't have anyone to ask. Even when I got a job as FoxPro programmer, I had only FoxPro books to tell me what to do. If I'd pestered the other coders by asking them questions about how to do things all the time, they would have fired me on the spot. I benefitted there from having programmed in other languages before. FoxPro was then just another language. The only disadvantage to my approach is that I sometimes wonder if, having learned all this stuff in a virtual vacuum, everyone else knows a better way than me. But my experience has been that that is infrequently the case. Yes, programming books *can* suck. And most assume you know more than you do. I benefit because I programmed in C before I programmed in PHP, which is virtually C for the web. And my C benefitted from knowing Pascal before that and BASIC before that. Multi-dimensional arrays are part and parcel of Pascal and C. So encountering them in PHP was no big deal. Syntax varies from language to language (in Python, you don't do $arr[] = 'blah'; you do arr.append('blah')), but the concept is the same. Once you know the concept well, the syntax is relatively simple to learn, unless you're trying to learn Scheme or something (;-}). They are either moronically basic of sadly flawed or outdated. It's something like the do-it-yourself-wikis... any dolt can put of whatever they think. That's the downside of the net, of course. The upside is that there are great people, like yourself and a number of other who have been very helpful and who are willing to share their knowledge. Anyway, I find very little in the tutorials on the web that goes beyond total basics. You're not looking hard enough. I've found help with a great many esoteric (edge case) problems by searching on the net. You can't just decide Well, all the books suck and the net sucks, so I'll just ask someone who knows. That's why they write books. So people don't have to use up all the time of people who know, by asking them masses of questions. The people who know are busy producing products. Professors and teachers get paid to teach people things, not productive professionals in a field. You're lucky the professionals are willing to spare the (free) time to explain what already plainly exists in books. Learning PHP5 is a crappy little O'Reilly book for anyone who's programmed in another language and wants to learn PHP. But it's perfectly fine for a non-programmer learning PHP. Don't get me wrong. I have nothing against you personally. And I'm more than willing to share my knowledge with others in general. I allows me to clarify my concepts and gives others an opportunity to dispute what I'm saying. And of course, it helps others get it, when I know it's sometimes hard to figure out a way through. But I've done enough years of tech support and instruction to recognize the symptoms I'm seeing here. I'll let other people hold your hand from now on. And when they get enough of it, they'll chastise you as well. Paul -- Paul M. Foster -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Summary Report With Details - Newbie Question
On 3/16/2009 7:17 PM, Paul M Foster pa...@quillandmouse.com wrote: Well, I was dubious about my answer, based on the idea that someone else might have a better way. However, it appears not. So what I would do is probably, instead of echoing stuff immediately, I'd just append it to a string until you're ready to output a total line. Then output the total line, and immediately after, output the string you accumulated while counting. Make sense? The whole point in the first place, as I recall, was to avoid umpteen database queries. So what you're doing is to load it all up at once and then let PHP do the heavy work instead of the database. But the total you want is only available after you've processed all the records for that item/model. So if you want it to come first on screen, you'll have to accumulate all your detail lines as you go. Then when the total is ready, output that and then output all the stuff you've accumulated. I don't know any better way to do it. If it's still not clear, let me know. Thanks for your help PAUL - with your explanation I got it working - Yipee!! Like this == $product = ''; $productlast = ''; $show=''; $count = 1; while ($a = mysql_fetch_assoc($getall)) { if ($product != $a['model']) { if ($productlast != '') { echo 'br/br/br/MODEL: '.$productlast.' TOTAL COUNT '.$count.' br/br/ '.$show;} $show=''; $count = 1; // resets count for each new model $product = $a['model']; $show = $show . $a['model'].' '.$a['id'].' - loc: '.$a['condition'].' 1br/'; } else { $count++; $productlast = $a['model']; $show = $show . $a['model'].' '.$a['id'].' - loc '.$a[' condition'].' 2 br/'; } } -- Thanks - RevDave Cool @ hosting4days . com [db-lists 09] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Anyone know of a project like Redmine written in PHP?
http://www.redmine.org/ Looks pretty useful; I want one in PHP though. Anyone? -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] RE: non-auto increment question
Paul M Foster wrote: On Mon, Mar 16, 2009 at 06:05:33PM -0500, PJ wrote: Paul M Foster wrote: snip Thanks Paul for the explanation. It really does help and iis much appreciated. I must respond to your chastisement of me, because i believe you may not be aware of the fact that most books on programming really suck. I have had my taste of enough of them to not bother. The kinds of things that I am trying to do just cannot be learned from a book or from most of those tutorials one finds on the Internet. How do you think *I* learned this? Back in 1974, when I hooked up my high school teletype via an acoustic modem to the school district mainframe and logged in for the first time, I had one choice for programming languages: Mainframe (Dartmouth) BASIC. So I bought a book on the subject, still in print today, called Basic Basic. Thus I learned Pascal (Turbo Pascal). Thus I learned C (Kernighan and Richie). Thus I learned Linux (man pages). Thus I learned Perl, Python and PHP. *All* from books. I didn't have anyone to ask. Even when I got a job as FoxPro programmer, I had only FoxPro books to tell me what to do. If I'd pestered the other coders by asking them questions about how to do things all the time, they would have fired me on the spot. I benefitted there from having programmed in other languages before. FoxPro was then just another language. The only disadvantage to my approach is that I sometimes wonder if, having learned all this stuff in a virtual vacuum, everyone else knows a better way than me. But my experience has been that that is infrequently the case. Yes, programming books *can* suck. And most assume you know more than you do. I benefit because I programmed in C before I programmed in PHP, which is virtually C for the web. And my C benefitted from knowing Pascal before that and BASIC before that. Multi-dimensional arrays are part and parcel of Pascal and C. So encountering them in PHP was no big deal. Syntax varies from language to language (in Python, you don't do $arr[] = 'blah'; you do arr.append('blah')), but the concept is the same. Once you know the concept well, the syntax is relatively simple to learn, unless you're trying to learn Scheme or something (;-}). They are either moronically basic of sadly flawed or outdated. It's something like the do-it-yourself-wikis... any dolt can put of whatever they think. That's the downside of the net, of course. The upside is that there are great people, like yourself and a number of other who have been very helpful and who are willing to share their knowledge. Anyway, I find very little in the tutorials on the web that goes beyond total basics. You're not looking hard enough. I've found help with a great many esoteric (edge case) problems by searching on the net. You can't just decide Well, all the books suck and the net sucks, so I'll just ask someone who knows. That's why they write books. So people don't have to use up all the time of people who know, by asking them masses of questions. The people who know are busy producing products. Professors and teachers get paid to teach people things, not productive professionals in a field. You're lucky the professionals are willing to spare the (free) time to explain what already plainly exists in books. Learning PHP5 is a crappy little O'Reilly book for anyone who's programmed in another language and wants to learn PHP. But it's perfectly fine for a non-programmer learning PHP. Don't get me wrong. I have nothing against you personally. And I'm more than willing to share my knowledge with others in general. I allows me to clarify my concepts and gives others an opportunity to dispute what I'm saying. And of course, it helps others get it, when I know it's sometimes hard to figure out a way through. But I've done enough years of tech support and instruction to recognize the symptoms I'm seeing here. I'll let other people hold your hand from now on. And when they get enough of it, they'll chastise you as well. Paul I understand what you are sayig and I am quite impressed with your knowledge and experience. Just to justify my position and by the way before I forget I hope that there will be others who will benefit from my frustrations as some of the help I have received has been quite high level and that, obviously, I did not find on the web. As to intensifying my search on the web, well, little by little I stumble onto some stuff that is helpful but the amount of time I spend looking and thinking is beyond normal human endurance. And the rewards from searching are extremely minimal. Where can you find the kind of stuff that you and Jim Lucas have offered is not to be found easily if at all on the web. And don't forget how miserable searching has become on Google. The others, I don't even consider and don't have the time. I'll try harder to understand the array but there is a lot that simply is not clear... I keep analyzing the
Re: [PHP] Fork and zombies
While this works, it unfortunately leaves behind a zombie process every single time. You need to call pcntl_wait() or pcntl_waitpid(). Right, but if I do that, then the parent has to wait until the child completes before it exits. No it doesn't - just call pcntl_wait() with WNOHANG to check the status of a child. Hm, so now I'm not so sure what's happening. Before trying your suggestion, I ran my script again without pcntl_wait so that I'd have a baseline for how many zombie processes are being created, and it turns out that I don't think any are. Previously, I was doing ps aux | awk '{ print $8 $2 }' | grep -w Z to find zombie processes, and it turns out that they existed from before, as the count didn't change after I ran my script. That leads to another problem, though, in that the resource for the database doesn't seem to be available for the parent after the child exits. Here's pseudo code for what I'm trying to do: foreach ($things as $thing) { info = getInfo($thing); // uses a db connection makeApiCall(info); } makeApiCall(info) { $pid = pcntl_fork(); if ($pid == -1) { die(could not fork); } else if ($pid) { // parent, return the child pid echo child pid $pid\n; return; } else { // do some api calls exit; } } But after I spawn off the process, getInfo($thing) errors out sometime later on with an invalid query error, because I think the db connection is gone. I thought adding exit in the child process would be enough, but that doesn't seem to work, I still get the same error. Why would the child process affect the query in the parent process, especially if I exit in the child process? Following your suggestion, I also tried pcntl_wait in the upperlevel function, but still had the same problem. Thanks for any insight, Waynn