[PHP-DB] explode() and a database call...?
I'm trying to split up a field from a database that contains a list of No's (Eg:1, 4, 12, 32) If I do: $bands_array = explode(,, 1, 4, 12, 32); I get the following array: $bands_array[0] = 1 $bands_array[1] = 4 $bands_array[2] = 12 $bands_array[3] = 32 All good! However... Calling froma database... $bands_array = explode(',', $row[bands]); I get no values in the array, (I have checked the overall value of $row[bands] and it does contain 1, 4, 12, 32) os my question is: why is the database call, changing how explode works? Tris...? * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] explode() and a database call...?
Hi! You should use $row[bands]. But maybe it's only typing error. I use such methos and have no errors. Tuesday, May 18, 2004, 7:02:34 PM, Tristan wrote: TPrsc I'm trying to split up a field from a database that contains a list of TPrsc No's (Eg:1, 4, 12, 32) TPrsc If I do: TPrsc $bands_array = explode(,, 1, 4, 12, 32); TPrsc I get the following array: TPrsc $bands_array[0] = 1 TPrsc $bands_array[1] = 4 TPrsc $bands_array[2] = 12 TPrsc $bands_array[3] = 32 TPrsc All good! TPrsc However... TPrsc Calling froma database... TPrsc $bands_array = explode(',', $row[bands]); TPrsc I get no values in the array, (I have checked the overall value of TPrsc $row[bands] and it does contain 1, 4, 12, 32) TPrsc os my question is: why is the database call, changing how explode works? TPrsc Tris...? TPrsc * TPrsc The information contained in this e-mail message is intended only for TPrsc the personal and confidential use of the recipient(s) named above. TPrsc If the reader of this message is not the intended recipient or an agent TPrsc responsible for delivering it to the intended recipient, you are hereby TPrsc notified that you have received this document in error and that any TPrsc review, dissemination, distribution, or copying of this message is TPrsc strictly prohibited. If you have received this communication in error, TPrsc please notify us immediately by e-mail, and delete the original message. TPrsc *** -- Best regards, Mikhail U. Petrov mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] explode() and a database call...?
HH, didn't work...? Mikhail U. Petrov [EMAIL PROTECTED] 18/05/2004 16:20 Please respond to Mikhail U. Petrov [EMAIL PROTECTED] To [EMAIL PROTECTED] cc [EMAIL PROTECTED] Subject Re: [PHP-DB] explode() and a database call...? Hi! You should use $row[bands]. But maybe it's only typing error. I use such methos and have no errors. Tuesday, May 18, 2004, 7:02:34 PM, Tristan wrote: TPrsc I'm trying to split up a field from a database that contains a list of TPrsc No's (Eg:1, 4, 12, 32) TPrsc If I do: TPrsc $bands_array = explode(,, 1, 4, 12, 32); TPrsc I get the following array: TPrsc $bands_array[0] = 1 TPrsc $bands_array[1] = 4 TPrsc $bands_array[2] = 12 TPrsc $bands_array[3] = 32 TPrsc All good! TPrsc However... TPrsc Calling froma database... TPrsc $bands_array = explode(',', $row[bands]); TPrsc I get no values in the array, (I have checked the overall value of TPrsc $row[bands] and it does contain 1, 4, 12, 32) TPrsc os my question is: why is the database call, changing how explode works? TPrsc Tris...? TPrsc * TPrsc The information contained in this e-mail message is intended only for TPrsc the personal and confidential use of the recipient(s) named above. TPrsc If the reader of this message is not the intended recipient or an agent TPrsc responsible for delivering it to the intended recipient, you are hereby TPrsc notified that you have received this document in error and that any TPrsc review, dissemination, distribution, or copying of this message is TPrsc strictly prohibited. If you have received this communication in error, TPrsc please notify us immediately by e-mail, and delete the original message. TPrsc *** -- Best regards, Mikhail U. Petrov mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DB] explode() and a database call...?
Tristan Pretty [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] com... HH, didn't work...? Please echo out $row['bands'] and post the contents. Regards, Torsten Mikhail U. Petrov [EMAIL PROTECTED] 18/05/2004 16:20 Please respond to Mikhail U. Petrov [EMAIL PROTECTED] To [EMAIL PROTECTED] cc [EMAIL PROTECTED] Subject Re: [PHP-DB] explode() and a database call...? Hi! You should use $row[bands]. But maybe it's only typing error. I use such methos and have no errors. Tuesday, May 18, 2004, 7:02:34 PM, Tristan wrote: TPrsc I'm trying to split up a field from a database that contains a list of TPrsc No's (Eg:1, 4, 12, 32) TPrsc If I do: TPrsc $bands_array = explode(,, 1, 4, 12, 32); TPrsc I get the following array: TPrsc $bands_array[0] = 1 TPrsc $bands_array[1] = 4 TPrsc $bands_array[2] = 12 TPrsc $bands_array[3] = 32 TPrsc All good! TPrsc However... TPrsc Calling froma database... TPrsc $bands_array = explode(',', $row[bands]); TPrsc I get no values in the array, (I have checked the overall value of TPrsc $row[bands] and it does contain 1, 4, 12, 32) TPrsc os my question is: why is the database call, changing how explode works? TPrsc Tris...? TPrsc * TPrsc The information contained in this e-mail message is intended only for TPrsc the personal and confidential use of the recipient(s) named above. TPrsc If the reader of this message is not the intended recipient or an agent TPrsc responsible for delivering it to the intended recipient, you are hereby TPrsc notified that you have received this document in error and that any TPrsc review, dissemination, distribution, or copying of this message is TPrsc strictly prohibited. If you have received this communication in error, TPrsc please notify us immediately by e-mail, and delete the original message. TPrsc *** -- Best regards, Mikhail U. Petrov mailto:[EMAIL PROTECTED] -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php * The information contained in this e-mail message is intended only for the personal and confidential use of the recipient(s) named above. If the reader of this message is not the intended recipient or an agent responsible for delivering it to the intended recipient, you are hereby notified that you have received this document in error and that any review, dissemination, distribution, or copying of this message is strictly prohibited. If you have received this communication in error, please notify us immediately by e-mail, and delete the original message. *** -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SQLite and PHP4
After playing around some with SQLite with PHP5, I decided that I wanted to have it working in PHP4 to start using it fully while waiting for PHP5 to come out. However, I ran into a snag ... after downloading it/phpizeing/configure/make/makeinstall ... I added the extension=sqlite.so line to my server (Apache 1.3.31, Solaris) ... rebooted, and nothing happened. My phpinfo page doesn't mention any sqlite support being added, I don't see any errors in Apache's error log, and any test scripts I write to use sqlite_open claim the function doesn't exist. What have I missed here? Thanks, Eli -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] SQL Statement
For some background, I've been tasked with building a marketing tracking application by the PHB's who think that being able to write SQL means you can code. I know how to get data into a database and I can do thing with it once it's in there, but this is one of my first attempts at extracting anything remotely end-user-ish. Since the only server I can get is an old cobalt RAQ 2, the only database I can run is MySQL. Im not terribly familiar with MySQL (spent more time working with commercial databases) and Im a complete newbie at PHP, so please dont flame me yet Im not even sure what information Ill need to provide you so here goes: Platform Red Hat 9.0 Linux on a BogoMIPS CPU PHP Version - 4.3.3 Apache Version - 1.3.28 MySQL Version - 4.0.14 Heres my SQL statement which works fine from a DBA perspective (meaning that I can execute it from the command line against the database and obtain the desired results), but Im obviously missing something in the syntax in converting this to an acceptable PHP SQL statement. I know that I can connect to the database and can extract other records, but I keep getting unable to parse error message and dont know enough to know which thing Im doing is wrong. SELECT phone_reports.pk_phone_reports, SUM(phone_reports.calls) AS total_calls, phone_reports.fk_ph_num, phone_reports.`date`, phone_reports.calls FROM phone_reports WHERE (phone_reports.fk_ph_num = 1) AND (phone_reports.`date` BETWEEN '2004/05/17' AND '2004/07/05') GROUP BY phone_reports.pk_phone_reports, phone_reports.fk_ph_num, phone_reports.`date`, phone_reports.calls Heres the PHP SQL statement built from the SQL statement above ?php if ($fk_phone != NULL) { $sqlwrk = SELECT `pk_phone_reports`, `date`, `calls` , `fk_ph_num` FROM `phone_reports`; $sqlwrk .= WHERE `pk_phone_number` = . $fk_phone; $rswrk = mysql_query($sqlwrk); if ($rswrk $rowwrk = mysql_fetch_array($rswrk)) { echo $rowwrk[number]; } @mysql_free_result($rswrk); } ? This seems to work ok, but doesnt return any results (which I expected) but it does parse! So then I try do this ?php if ($fk_phone != NULL) { $sqlwrk = SELECT `pk_phone_reports`, SUM(`calls`) AS `total_calls`, `date`, `calls` , `fk_ph_num` FROM `phone_reports`; $sqlwrk .= WHERE `pk_phone_number` = . $fk_phone; $rswrk = mysql_query($sqlwrk); if ($rswrk $rowwrk = mysql_fetch_array($rswrk)) { echo $rowwrk[number]; } @mysql_free_result($rswrk); } ? Note that this shouldnt work since it isnt a valid SQL statement. I'm not sure why PHP doesn't return some kind of an error message. I know that the database does! You cannot execute SUM without its required GROUP BY statement (at least against the database directly) but it at least parses as PHP. So then I expand by statement to include the rest of the WHERE clause. ?php if ($fk_phone != NULL) { $sqlwrk = SELECT `pk_phone_reports`, SUM(`calls`) AS `total_calls`,`date`, `calls` , `fk_ph_num` FROM `phone_reports`; $sqlwrk .= WHERE (`pk_phone_number` = . $fk_phone) AND (`date` BETWEEN '$my_startdate' AND '$my_enddate'); $sqlwrk .= GROUP BY `pk_phone_reports`, `fk_ph_num`, `date`, `calls`; $rswrk = mysql_query($sqlwrk); if ($rswrk $rowwrk = mysql_fetch_array($rswrk)) { echo $rowwrk[number]; } @mysql_free_result($rswrk); } ? Which brings me to my lovely parse error Parse error: parse error in ad_report.php on line 138. What I want this to do is to return to me the SUM of all the calls to a specific phone number between two dates (the date the advertisement started running and the date it ended) and this display this in a cell in table on a web page. Any help or pointers greatly appreciated. Thanks, Ms. Jimi Thompson, CISSP Manager, Web Operations Cox School of Business Southern Methodist University If we want women to do the same work as men, we must teach them the same things. - Plato
Re: [PHP-DB] SQL Statement
Jimi, PHP does not return an error because it knows nothing about valid sql. It's just knows if it's a valid PHP statement. (which it is because you've got the 's in the right place and a ; at the end. ) :) It's up to MySQL to return an error. As to your statement. 1: It's easier and valid in PHP to write it: $sqlwrk = SELECT pk_phone_reports, SUM(calls) AS total_calls, date, calls , fk_ph_num FROM phone_reports WHERE (pk_phone_number = {fk_phone}) AND (date BETWEEN '{$my_startdate}' AND '$my_enddate') GROUP BY pk_phone_reports, fk_ph_num, date, calls; In reformatting the string I found a couple of PHP things that are probably what's tripping you up. PHP used the . as a string concatonator. You were missing several of them. Notice that I remove them all. Because we enclosed the entire statement in a sing pair, we can use {$variable} for substitution. Makes life a lot easier when building sql statements. Also, I removed all the back-tiks. Not because they were wrong but they annoy my and in 99% of the cases are not necessary. Oh and welcome to PHP/MySQL. I hope you'll find the language easy and the people friendly. Finally, a could of things that will make life easier for you if you are going to be doing much database work in PHP/MySQL. http://php.weblogs.com/ This is the best database abstraction layer I've found. Even if you only use MySQL, it's worth the investment in time to learn it. (mainly for the debug feature.) www.sqlyog.com Best FE for MySQL on Windows I've ever found. It's $49.00 (I think...I forget) but it's worth it. It's got it's bugs but overall it's a killer tool. http://www.fabforce.net/dbdesigner4/ A killer, open source tool for designing databases. If you are used to the commercial tools costing $4k+ then you'll feel right at home with this. (It's my understanding that MySQL has purchased this project, but I may have my story wrong.) Finally, you've already found the greatest tool for debugging MySQL/php, the lists. See ya round. =C= : : Cal Evans : Evans Internet Construction Company : 615-360-3385 : http://www.eicc.com : Building web sites that build your business : Thompson, Jimi wrote: For some background, I've been tasked with building a marketing tracking application by the PHB's who think that being able to write SQL means you can code. I know how to get data into a database and I can do thing with it once it's in there, but this is one of my first attempts at extracting anything remotely end-user-ish. Since the only server I can get is an old cobalt RAQ 2, the only database I can run is MySQL. Im not terribly familiar with MySQL (spent more time working with commercial databases) and Im a complete newbie at PHP, so please dont flame me yet Im not even sure what information Ill need to provide you so here goes: Platform Red Hat 9.0 Linux on a BogoMIPS CPU PHP Version - 4.3.3 Apache Version - 1.3.28 MySQL Version - 4.0.14 Heres my SQL statement which works fine from a DBA perspective (meaning that I can execute it from the command line against the database and obtain the desired results), but Im obviously missing something in the syntax in converting this to an acceptable PHP SQL statement. I know that I can connect to the database and can extract other records, but I keep getting unable to parse error message and dont know enough to know which thing Im doing is wrong. SELECT phone_reports.pk_phone_reports, SUM(phone_reports.calls) AS total_calls, phone_reports.fk_ph_num, phone_reports.`date`, phone_reports.calls FROM phone_reports WHERE (phone_reports.fk_ph_num = 1) AND (phone_reports.`date` BETWEEN '2004/05/17' AND '2004/07/05') GROUP BY phone_reports.pk_phone_reports, phone_reports.fk_ph_num, phone_reports.`date`, phone_reports.calls Heres the PHP SQL statement built from the SQL statement above ?php if ($fk_phone != NULL) { $sqlwrk = SELECT `pk_phone_reports`, `date`, `calls` , `fk_ph_num` FROM `phone_reports`; $sqlwrk .= WHERE `pk_phone_number` = . $fk_phone; $rswrk = mysql_query($sqlwrk); if ($rswrk $rowwrk = mysql_fetch_array($rswrk)) { echo $rowwrk[number]; } @mysql_free_result($rswrk); } ? This seems to work ok, but doesnt return any results (which I expected) but it does parse! So then I try do this ?php if ($fk_phone != NULL) { $sqlwrk = SELECT `pk_phone_reports`, SUM(`calls`) AS `total_calls`, `date`, `calls` , `fk_ph_num` FROM `phone_reports`; $sqlwrk .= WHERE `pk_phone_number` = . $fk_phone; $rswrk = mysql_query($sqlwrk); if ($rswrk $rowwrk = mysql_fetch_array($rswrk)) { echo $rowwrk[number]; } @mysql_free_result($rswrk); } ? Note that this shouldnt
Re: [PHP-DB] SQL Statement
Thompson, Jimi wrote: So then I try do this ?php if ($fk_phone != NULL) { $sqlwrk = SELECT `pk_phone_reports`, SUM(`calls`) AS `total_calls`, `date`, `calls` , `fk_ph_num` FROM `phone_reports`; $sqlwrk .= WHERE `pk_phone_number` = . $fk_phone; $rswrk = mysql_query($sqlwrk); if ($rswrk $rowwrk = mysql_fetch_array($rswrk)) { echo $rowwrk[number]; } @mysql_free_result($rswrk); } ? Note that this shouldnt work since it isnt a valid SQL statement. I'm not sure why PHP doesn't return some kind of an error message. PHP does return an error message, you're just not displaying it. $rswrk = mysql_query($sqlwrk) or die(mysql_error()); $sqlwrk .= WHERE (`pk_phone_number` = . $fk_phone) AND (`date` BETWEEN '$my_startdate' AND '$my_enddate'); Which brings me to my lovely parse error Parse error: You're not concatinating your string correctly. $sqlwrk .= WHERE (`pk_phone_number` = . $fk_phone . ) AND (`date` BETWEEN ' . $my_startdate . ' AND ' . $my_enddate . '); or $sqlwrk .= WHERE (`pk_phone_number` = $fk_phone) AND (`date` BETWEEN '$my_startdate' AND '$my_enddate'); -- ---John Holmes... Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/ php|architect: The Magazine for PHP Professionals www.phparch.com -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] mail() function and AOL users
I use the following php mail function in an online applicaiton program: mail($email, application submitted, $message, From: [EMAIL PROTECTED]); This function does not always work when I modify $message. I have checked for null values for $message already but this does not seem to be the problem. I am trying to develop some sort of pattern of when this function works and when it does not. The only essential difference between the values I pass in for message is the one that does not always work includes a link. Apparently anyone useing AOL email is particularly vulnerable to this problem. Is it likely that AOL and other mail servers sometimes block any email from a web site if it has a link in the main body? Or should I not be useing mail() in this manner to begin with? -Matt -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP-DB] Re: mail() function and AOL users
Hello, On 12/12/2003 04:34 AM, Matt Perry wrote: I use the following php mail function in an online applicaiton program: mail($email, application submitted, $message, From: [EMAIL PROTECTED]); This function does not always work when I modify $message. I have checked for null values for $message already but this does not seem to be the problem. I am trying to develop some sort of pattern of when this function works and when it does not. The only essential difference between the values I pass in for message is the one that does not always work includes a link. Apparently anyone useing AOL email is particularly vulnerable to this problem. Is it likely that AOL and other mail servers sometimes block any email from a web site if it has a link in the main body? Or should I not be useing mail() in this manner to begin with? Maybe you are not generating the message headers and body properly. Without seeing the code that you use to define $message, it is hard to tell. I just suggest that you try this class to properly compose and send your messages: http://www.phpclasses.org/mimemessage -- Regards, Manuel Lemos PHP Classes - Free ready to use OOP components written in PHP http://www.phpclasses.org/ PHP Reviews - Reviews of PHP books and other products http://www.phpclasses.org/reviews/ Metastorage - Data object relational mapping layer generator http://www.meta-language.net/metastorage.html -- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php