Re: [PHP] Setting up a 2 Column Display for SQL Recordset
Dave I would look into something like the array_slice function. http://us3.php.net/manual/en/function.array-slice.php With this function you could create two arrays - one for the left column, and one for the right column - and iterate through them simultaneously. i.e. untested: given $allNames is an array with all 200 names -- $firstNameSet = array_slice($allNames, 0, 100); $secondNameSet = array_slice($allNames, 100); foreach ($firstNameSet as $key => $nameA) { $nameB = $secondNameSet[$key]; ... ... } - Alternatively you can use a nested query to pull the results in two sets directly from the sql db. Hope that helps Chris. On Fri, Aug 13, 2010 at 12:51 PM, DealTek wrote: > newbie question: > > Hi Folks, > > I have a php / sql data recordset that has 200 names that I want to display > in a 2 column display ( down on left then down on right side - not left > right - left right). > > So I can create a 2 column table. Then I need to split the data result in 2 > parts - so part 1 (1-100 records) is on the left column and part 2 (101 - > 200 records) is on the right column. > > Q: I'm not quite sure how to split / display the records ... Is there some > kind of internal sql rec number that I can monitor? What is the best way to > set this up? > > > > -- > Thanks, > Dave - DealTek > deal...@gmail.com > [db-10] > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] It's Friday (a MySQL Question)
Tedd I don't know if this will resolve your issue or not, but have you looked into using mysqldump? http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html That's what I use for my backups. Chris. On Fri, Aug 13, 2010 at 6:47 PM, tedd wrote: > At 6:11 PM -0400 8/13/10, Daniel P. Brown wrote: > >> On Fri, Aug 13, 2010 at 17:48, tedd wrote: >> >>> >>>SELECT * FROM table_reference INTO OUTFILE 'file_name' >>> >>> It looked to be bit simpler/shorter than my code, so I tried it. But it >>> reports: >>> >>>Access denied for user 'me'@'localhost' (using password: YES). >>> >>> I suspect that the "access being denied" is because MySQL doesn't have >>> permission to create the output file. The MySQL manual reports: 1) that >>> a >>> file cannot be present; 2) AND MySQL must have file privileges to create >>> the >>> file -- but I don't know how to set that up. >>> >> >>No, the 'access denied' message means that either the username or >> password is incorrect, or that the given user doesn't have permission >> to access the given database on the given host. >> > > Daniel : > > I don't think so and here's my reasoning. > > You see in the same script, I tested the connection to the database with a > query *before* the OUTFILE statement and it worked! If the username and/or > password had been wrong, then it would have also failed. Here's the demo: > > http://php1.net/c/db-dump/db-2-dir.php > > Please note that the string 'BKohl41' noted is the result of a query to the > same database *before* the OUTFILE query. > > As far as I can tell, the MySQL statement does not have permission to > create a file and that's the problem as I see it. > > I shall test Daevid's "GRANT SELECT, FILE ON mydb.table_reference TO > 'me'@'localhost';" > statement tomorrow -- it looks promising. > > As for the: > > > "You know you can pass that on the command line right and avoid this pipe > business?" > > No, I don't know how to do that. > > > Cheers, > > tedd > > -- > --- > http://sperling.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] login to protected directory by php
Based off what your saying my guess is that the request is not hitting your php script. Is the php script in the protected directory? If so what is it's file name and what url are you hitting for the test? Chris. On Fri, Aug 13, 2010 at 6:21 PM, Ali Asghar Toraby Parizy < aliasghar.tor...@gmail.com> wrote: > Hi. I have a protected directory in my host. I have configured .htaccess > successfully and it works prefect. > Now I'm looking for a solution to login and logout by a php script. > In my site I have a login page. In that page I set 'PHP_AUTH_USER' and ' > PHP_AUTH_PW'. but when I try to open protected directory, user > authentication dialog appears. > How can I do this? What is my error? > > -- > Ali Asghar Torabi >
Re: [PHP] Updating Multiple rows in mysql w php at once (newbie)
you can do it like this... on the php side this would equate to... echo $_POST['field'][0]; // prints "zero" echo $_POST['field'][1]; // prints "one" echo $_POST['field'][65]; // prints "sixty-five" echo $_POST['field']['car']; // prints "truck" provided the form is submitted via a POST method. Take care to ensure you have the right index on the array. Chris. On Fri, Aug 13, 2010 at 8:19 PM, DealTek wrote: > Hi all, > > another newbie question > > I have a recordset from mysql - a list of 20 or so products... > > > 1 - I would like create an edit form to loop through the records and edit a > text field called 'favorite' for each of the records - (this, I have > done)... > > 2 - then I would like to submit the form and update all records favorite > field at once... > > Q: so how do I create the form and response page so that I can update all > 20? > > I'm sure it involves numbering the form names like: > > $c = 1 - then increment counter > > > > > ...not sure how to loop thru these on the response / update page to get > them updating correctly > > > > > -- > Thanks, > Dave - DealTek > deal...@gmail.com > [db-10] > > > >
Re: [PHP] It's Friday (a MySQL Question)
Well you certainly can not use this without the command line, however some hosts restrict you from the command line but still allow you to run commands via php's exec() function (Rackspace Sites is an example of this). pseudo code example: exec('mysqldump [options] --all-databases ... '); Of course this is only if your hoster supports it, and if the user has proper mysql privileges (which I think are SELECT, LOCK TABLES, and SHOW VIEW). mysqldump is a great program with many options so you can dump your db just the way you want it ;) If it's something you can and choose to use I would suggest reading over the link I sent you so you can customize it's output. Chris. On Sat, Aug 14, 2010 at 8:51 AM, tedd wrote: > At 6:53 PM -0400 8/13/10, chris h wrote: > >> Tedd I don't know if this will resolve your issue or not, but have you >> looked into using mysqldump? >> >> <http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html> >> http://dev.mysql.com/doc/refman/5.1/en/mysqldump.html >> >> >> That's what I use for my backups. >> >> >> Chris. >> > > Chris: > > I would like to do that, but I simply don't know how. > > I think the reason for that is that I usually work on shared hosted > accounts and the hosts don't permit command line stuff -- so I think, but I > could be wrong. Plus, I stopped doing command line stuff back in the Apple > ][ days. > > Granted this is another hole in my knowledge, but I think that even if I > knew how, I don't think it would solve my current problem. Am I wrong? > > > Cheers, > > tedd > > -- > --- > http://sperling.com/ >
Re: [PHP] tutorial failure
php is not processing the file. There's a few reasons for this, but the first thing I would check is the permissions of the file. From the directory try $ ls -oa This should tell you who owns the file and what it's permissions are. You mentioned that you copied it as root, you could change it's ownership to www-data. again from the directory try. $ chown www-data test.php then run ls -oa to ensure the change took place. Chris. On Wed, Aug 18, 2010 at 6:03 AM, e-letter wrote: > I changed the code as follows: > > > >php test > > > > > echo "Hi, I am a PHP script"; >?> > >this is a test > > > > > The result (http://localhost/test.php): > > Hi, I am a PHP script > > "; ?> > > this is a test > > If I use single quotes characters: > > Hi, I am a PHP script > > '; ?> > > this is a test > > The phpinfo instruction does not seem to be recognised. What else > should I check? > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] tutorial failure
What are the actual file permissions when you run ls -o? Do you know if PHP is installed as an apache mod or cgi? Also you might check what user apache is running as. possibly... $ vi /etc/apache2/envvars and look for something like... export APACHE_RUN_USER=www-data On Wed, Aug 18, 2010 at 6:47 AM, e-letter wrote: > On 18/08/2010, chris h wrote: > > php is not processing the file. There's a few reasons for this, but the > > first thing I would check is the permissions of the file. From the > > directory try > > > > $ ls -oa > > > The file permission was confirmed as root, since it was copied (as > root) from a normal user account directorp 'temporary' to the > directory '/var/www/html' > > > This should tell you who owns the file and what it's permissions are. > You > > mentioned that you copied it as root, you could change it's ownership to > > www-data. > > > This fails: > > [r...@localhost html]# chown www-data test.php > chown: `www-data': invalid user > > So I repeated this with a normal user account and the change in > permission occurs. However, the html file containing the php script > remains unchanged. > > The instruction: > > ... > > ... > > Does not show the version of php. >
Re: [PHP] tutorial failure
On Wed, Aug 18, 2010 at 7:10 AM, e-letter wrote: > On 18/08/2010, chris h wrote: > > What are the actual file permissions when you run ls -o? > > > root > What's the entire output of ls -o? > > > > Do you know if PHP is installed as an apache mod or cgi? Also you might > > check what user apache is running as. > > > No. How to verify? > > > possibly... > > $ vi /etc/apache2/envvars > > > No apache2 on my computer, only '/usr/lib/apache' which contains only .so > files. > there's no /etc/apache either?
Re: [PHP] method overloading in a class
Would something like this work for you? class foo { public function bar($arg1, $arg2, $arg3=null) { if (isset($arg3)){ { return $this->_bar3($arg1, $arg2, $arg3); } else { return $this->_bar2($arg1, $arg2); } } also you may want to look into the func_get_args function. Chris. On Wed, Aug 18, 2010 at 12:23 PM, Ashley Sheridan wrote: > Hi list, > > I know that some languages such as C++ can overload functions and > methods by declaring the method again with a different number of > arguments, and the compiler internally sorts things out, but I can't > seem to find a similar way to do this with PHP. > > Basically, what I've got at the moment is a class method with 2 > arguments, and I need to be able to overload the method with 3 > arguments. The following which would work in other languages doesn't > seem to bring any joy in PHP: > > class foo > { >public function bar($arg1, $arg2) > { >// do something with $arg1 & $arg2 >} > >public function bar($arg1, $arg2, $arg3) >{ >// do something different with all 3 args >} > } > > Is there any feasible way of doing this? The method names really need to > remain the same as they exist as part of a framework, but the arguments > really server quite different purposes between the two methods, so > there's no nice way of just merging the two functions without breaking > the naming conventions, etc used. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > >
Re: [PHP] Can't read $_POST array
Does $_SERVER['HTTP_METHOD'] show a GET or POST? On Wed, Aug 18, 2010 at 4:58 PM, Adam Richardson wrote: > On Wed, Aug 18, 2010 at 4:55 PM, Adam Richardson >wrote: > > > On Wed, Aug 18, 2010 at 4:49 PM, Ashley Sheridan < > a...@ashleysheridan.co.uk > > > wrote: > > > >> On Wed, 2010-08-18 at 13:45 -0700, Brian Dunning wrote: > >> > >> > I'm trying to write a VERY simple script that does nothing but store > all > >> the submitted GET and POST vars in a string and echo it out. > >> > > >> > $response = print_r($_REQUEST, true); > >> > echo $response; > >> > > >> > The problem is it only shows GET vars. I've tried $POST instead of > >> $_REQUEST and it always gives an empty array. I've got it on two > different > >> servers, and we have three guys trying various methods of submitting > forms > >> to it, trying to eliminate all potential problems, like the possibility > that > >> the request might not actually have any POST vars. I think we've safely > >> eliminated these possibilities. > >> > > >> > Can anyone see a reason why the above should not see POST vars? Is > there > >> some security setting I don't know about? > >> > >> > >> Is there any code before the print_r() call, i.e. code that might be > >> setting it to an empty array? > >> > >> If not, then are you sure your form is definitely sending post > >> variables? It sounds a stupid question, but a small typo could be > >> sending the data as GET by accident. Firefox has a useful extension > >> called Firebug which might be able to show you the data being sent to > >> the browser. If you really need to bring out the big guns, then > >> Wireshark will show all the network traffic, including that sent from > >> your form to the server. > >> > >> Thanks, > >> Ash > >> http://www.ashleysheridan.co.uk > >> > >> > >> > > Check php.ini for this setting: > > variables_order > > > > > > -- > > Nephtali: PHP web framework that functions beautifully > > http://nephtaliproject.com > > > > And I suppose post_max_size could cause issues, too. > > -- > Nephtali: PHP web framework that functions beautifully > http://nephtaliproject.com >
Re: [PHP] PHP, Soap, and WDSL
Alternatively you can pass the var through htmlspecialchars... echo htmlspecialchars( $response ); and for a really simple solution you can echo it inside a textarea... echo " $response "; Though you'll likely want to increase the size of the textarea! ;-) Chris. On Fri, Sep 3, 2010 at 3:39 AM, Jangita wrote: > On 02/09/2010 10:51 p, SBS Computers wrote: > > It's as if the data is not getting to my php page? >> >> The view source shows the following data: >> >> http://schemas.xmlsoap.org/soap/envelope/";> >> . >> . >> .bunch of data >> . >> . >> >> >> Seems like the data is getting there OK. But a browser normally will not > output normal xml and hides it (unless there is a tag or other tags > that normally display output since it is using the text/html MIME > > add this line > > header('Content-type: text/plain'); > > before the echo and see what happens. Also make sure there is no other > output (echo or any html tags) before the line above > > -- > Jangita | +256 76 91 8383 | Y! & MSN: jang...@yahoo.com > Skype: jangita | GTalk: jangita.nyag...@gmail.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] a test (list is too quite)
Evidently all is well in the world of php... :) On Sat, Sep 4, 2010 at 12:45 PM, tedd wrote: > Hi gang: > > Just checking to see if I am still receiving postings. :-) > > Cheers, > > tedd > -- > --- > http://sperling.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] a test (list is too quite)
On Sat, Sep 4, 2010 at 2:24 PM, Marc Guay wrote: > Can I make a facebook site using PHP? If yes, how? > > Please send me the infos privately. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > I'm also trying to make a Facebook site using PHP; but I want mine to incorporate all the elements from YouTube, Twitter, and Wikipedia... Also I want it to be ecommerce so I can sell t-shirts with my picture on them... Also I want it to be an auction site. Hmm, maybe Wordpress can do this
Re: [PHP] Hi
You can check the extension of the uploaded file http://www.php.net/manual/en/features.file-upload.post-method.php But to be sure that it's truly a zip file you could actually open the file with php's zip function. http://php.net/manual/en/ref.zip.php Chris. On Mon, Sep 6, 2010 at 9:46 AM, Jordan Jovanov wrote: > Hi All > > I need me a little help. > I create scripte for upload file is work very good but the problem is next: > I neet to upload only .zip file i need to disable some user to shoise to > upload another file Extensions. > > Can somebody help me. > > Thanks a lot. > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Hi
On Mon, Sep 6, 2010 at 1:45 PM, chris h wrote: > Per PHPdocs on $_FILES['userfile']['type']... > > "The mime type of the file, if the browser provided this information. An > example would be "image/gif". This mime type is however not checked on the > PHP side and therefore don't take its value for granted." > > > Personally I like to use the file right off-the-bat to ensure it's safe. > So if it's an image do some kind of image manipulation function on it, if > it's zip then use some zip functions on it (i.e. if you can read data from a > zip file using a zip function then it's probably a real zip file). It can > be slow, but handling user uploaded files is so dangerous that I think it's > typically the way to go. > > > Chris. >
Re: [PHP] Reformat array result.
Paul, How are you matching the records in the "event count" array to the ones in the timestamp array? Is it safe to say that: "$timestamp[ $i ]" corresponds to "$eventCount[ $i ]"? If so, you could just iterate through the timestamp array; on each iteration create a record in a new array that holds the timestamp and whatever the corresponding eventCount record is. Something like: $newTimeArray = array(); foreach ($timestamps as $i => $singleTimestamp) { $newTimeArray[ $i ] = array( 'timestamp' => $singleTimestamp, 'count' => $eventCounts[ $i ] ); } Now if "$timestamp[ $i ]" does NOT correspond to "$eventCount[ $i ]" then I think we'll need you to explain how that relationship works, unless I missed something :) Chris. On Wed, Sep 8, 2010 at 1:02 PM, Paul Halliday wrote: > I have been starting at this problem blankly for a couple hours now. > Hopefully someone can help. > > I have a query that returns an event count grouped by hour: > > timestamp: > Array ( [0] => 2010-09-08 03 [1] => 2010-09-08 04 [2] => 2010-09-08 05 > [3] => 2010-09-08 06 [4] => 2010-09-08 07 [5] => 2010-09-08 08 [6] => > 2010-09-08 09 [7] => 2010-09-08 10 [8] => 2010-09-08 11 [9] => > 2010-09-08 12 [10] => 2010-09-08 13 [11] => 2010-09-08 14 [12] => > 2010-09-08 15 [13] => 2010-09-08 16 ) 24 > > event count: > Array ( [0] => 1731 [1] => 885 [2] => 544 [3] => 668 [4] => 748 [5] => > 754 [6] => 933 [7] => 2422 [8] => 6713 [9] => 31925 [10] => 18827 [11] > => 16743 [12] => 16875 [13] => 11775 ) > > Lets say that coming into this, I knew that the query spanned 36 hours > and started at 01:00. How can I manipulate the resulting array to > contain the missing time stamps and a value of 0. > > The effect I am shooting for looks like this: > > http://www.pintumbler.org/example.png > > So 0 - > 23 will be static and I just walk through the array and > populate those. If we hit 23, start a new row and continue. The matrix > will always be the same though. > > I think I know what needs to happen, I just cant come up with the logic. > > Any push in the right direction would be appreciated. > -- > Paul Halliday > Ideation | Individualization | Learner | Achiever | Analytical > http://www.pintumbler.org > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
[PHP] Zend framework
Hello all, I'm starting a new project and I'm thinking about building it on Zend framework and possibly Zend server. I've only used the framework slightly and I've never really used Zend server. That being said I hear that the framework is pretty decent to work with. I want something that is strict and uses OOP & MVC well, and I hear it does; though I also have the impression that it's slow and bloated... Anyways, I was curious if any of you have some general advice / good things / horror stories on the Zend framework? Thanks, Chris.
Re: [PHP] newbie question about code
I would check this out to give you a decent understanding of php's oop. http://php.net/manual/en/language.oop5.php Chris. On Fri, Sep 10, 2010 at 2:27 PM, Adam Williams wrote: > I'm looking at someone's code to learn and I'm relatively new to > programming. In the code I see commands like: > > $code->do_command(); > > I'm not really sure what that means. How would that look in procedural > style programming? do_command($code); or something else? > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php >
Re: [PHP] Zend framework
Thanks for the info everyone, this is pretty much what I was expecting to hear about it. I think I'll probably stick to using it as a toolkit. Thanks, Chris. On Fri, Sep 10, 2010 at 3:01 PM, Daevid Vincent wrote: > Sorry wrong thread. Damnit. I meant that link for the guy that didn't know > what the -> was for... > > > -Original Message- > > From: Daevid Vincent [mailto:dae...@daevid.com] > > Sent: Friday, September 10, 2010 12:01 PM > > To: 'David Harkness' > > Cc: 'PHP-General' > > Subject: RE: [PHP] Zend framework > > > > http://www.php.net/manual/en/language.oop5.basic.php > > > > > -Original Message- > > > From: David Harkness [mailto:davi...@highgearmedia.com] > > > Sent: Friday, September 10, 2010 10:59 AM > > > To: rquadl...@googlemail.com > > > Cc: chris h; PHP-General > > > Subject: Re: [PHP] Zend framework > > > > > > We use part of Zend MVC (the dispatcher, controllers, and > > > view scripts) here > > > and a lot of the other facilities such as the autoloader, > > > config, etc. and > > > are very happy so far. As long as you design your application > > > with an eye > > > toward portability, you won't be tied to ZF. For example, put > > > all of your > > > business logic in model classes instead of the controllers > > > themselves. That > > > way if you ever need to move to a new presentation layer or > > > use the business > > > logic outside it (e.g. in SOAP or RPC messages), you'll be ready. > > > > > > David > > > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] 1984 (Big Brother)
On Mon, Sep 13, 2010 at 5:09 PM, Daevid Vincent wrote: > > > > -Original Message- > > From: tedd [mailto:t...@sperling.com] > > Sent: Sunday, September 12, 2010 9:32 AM > > To: PHP-General list > > Subject: [PHP] 1984 (Big Brother) > > > > Hi gang: > > > > I have a client who wants his employees' access to their online > > business database restricted to only times when he is logged on. > > (Don't ask why) > > > > In other words, when the boss is not logged on, then his employees > > cannot access the business database in any fashion whatsoever > > including checking to see if the boss is logged on, or not. No access > > whatsoever! > > > > Normally, I would just set up a field in the database and have that > > set to "yes" or "no" as to if the employees could access the > > database, or not. But in this case, the boss does not want even that > > type of access to the database permitted. Repeat -- No access > > whatsoever! > > > > I was thinking of the boss' script writing to a file that > > accomplished the "yes" or "no" thing, but if the boss did not log off > > properly then the file would remain in the "yes" state allowing > > employees undesired access. That would not be acceptable. > > > > So, what methods would you suggest? > > > > Cheers, > > > > tedd > > You sure know how to pick'em Tedd. > > This is the second "whacky" client you've posted about on the list... > > This guy sounds like a real control-freak (read: tool). > > One other thing I'll throw out is the use of a crontab to start/stop mysql > during "boss's hours". I don't have a complete solution for you as I just > don't care enough about helping this Dbag lord over his employees like > that, but I suspect you could have "/etc/init.d/mysql start" or "stop" at > some pre-determined times like 8am - noon. Then noon till 5pm. Or > something. > > RDBMS are not really designed to be turned on and off like that. > > Another option is to maybe use M$ Access instead (which does have a > multi-user mode). Use ODBC to connect via PHP to it. So then he would start > up the DB when he likes and shut it down when he likes. (note that a logout > of Windows will NOT prevent the ODBC connection as it is a service -- as > God intended RDBMS to be) > http://www.configure-all.com/php_access.php > > This guy is making me angry just thinking about it! > > d > > Yes I've been following this post purely in the hope that someone gets Tedd is explain the client's "logic" on this one. It's one thing for a layman to have this kind of requirement, but another entirely for them to STILL have it after an explanation. I mean part of consulting is to tell the client when they're wrong, for someone to not heed that when they are paying for the advice is mind boggling. *sigh* if only everyone were perfect like me... :p "Hey lets pay someone to consult us on a subject that we're ignorant of." "Great idea! And when he makes a suggestion we can totally ignore him! SQL - Shmeequal" Rant aside; I would defer the logistics to the client. He wants the DB to shutdown when he's not in the office? Ok no problem - not what it was designed to do, but no problem! "How would you like the system to be aware of rather or not you're in the office? It can assume you are between these hours; You can log into a screen that unlocked it, but then you have to logout; we can put a motion detector in your office; ... etc." This would put the consequences of the system off on the client. Because if this system works then there will be consequences and you'll look like a jerk :-) Btw, are there no cron / batch jobs that need to run over night? Chris
Re: [PHP] Adjusting Session Times
> My thought is to adjust the session expiration in the table based on the > client currently logged in. > > I don't know if there's a better way, but I would probably just do that. The expiration would be set to whatever the client's preference is, and default to 8 hours if he doesn't have one. You may want to set some checks to ensure that the client's preference is within a specific range (e.g. between 30 minutes and 16 hours). Chris.
Re: [PHP] 1984 (Big Brother)
So whenever the boss is in a meeting and his screen saver kicks on then the business shuts down. Also I think we've established that thumbdrive + database = disaster. Maybe a thumbdrive that has file with some random hash. Then create a cron that checks for the existence of that file each minute. When the boss leaves the cron doesn't find the file and shuts down the DB, when the boss comes in the cron will see it and starts it up. But Tedd, I'm still thinking that a "dead man's switch" is the way to go. :) Chris. On Sat, Sep 18, 2010 at 8:03 AM, TR Shaw wrote: > If you mean "not logoff properly" as, for instance, getting up and leaving > his office for the day without logging off you can run a script when the > machine "sleeps" or the screen saver runs and runs again when the machine > transitions back to run. > > If your talking about powering off, same scripting approach as above (or > just put DB on Boss' machine and if its off or crashes access ceases. > > As a crazy approach, put the DB on a thumb drive and attach the thumb to > the Boss' car or house keys. He plugs the thumb in when he wants to "grant" > access and takes it when he leaves because he need his keys. > > On Sep 17, 2010, at 11:44 PM, viraj wrote: > > >> > >> Remind him that he must logout normally to lock the DB > > > > if you follow the thread closely, this is a requirement. boss may not > > logout properly :) > > > > that's why all suggest a mechanical ways for the job. pressure > > sensors, cameras etc etc > > > > ~viraj > > > >> > >> > >> > >> On Sep 12, 2010, at 12:37 PM, Joshua Kehn wrote: > >> > >>> Tedd- > >>> > >>> Would he consider access to another database? I.e. a separate, say > memcached db which stores the "boss" status? > >>> > >>> An issue with the temporary file would also be session length, if the > session expires without the user explicitly logging off, the file wouldn't > be removed. A way to bypass this would be to add some sort of session > expiration header to the file and update that. > >>> > >>> And couldn't you make a simple check if the boss is logged in or not by > the ability to access the database? > >>> > >>> Regards, > >>> > >>> -Josh > >>> > >>> Joshua Kehn | josh.k...@gmail.com > >>> http://joshuakehn.com > >>> > >>> On Sep 12, 2010, at 12:32 PM, tedd wrote: > >>> > Hi gang: > > I have a client who wants his employees' access to their online > business database restricted to only times when he is logged on. (Don't ask > why) > > In other words, when the boss is not logged on, then his employees > cannot access the business database in any fashion whatsoever including > checking to see if the boss is logged on, or not. No access whatsoever! > > Normally, I would just set up a field in the database and have that > set to "yes" or "no" as to if the employees could access the database, or > not. But in this case, the boss does not want even that type of access to > the database permitted. Repeat -- No access whatsoever! > > I was thinking of the boss' script writing to a file that accomplished > the "yes" or "no" thing, but if the boss did not log off properly then the > file would remain in the "yes" state allowing employees undesired access. > That would not be acceptable. > > So, what methods would you suggest? > > Cheers, > > tedd > > -- > --- > http://sperling.com/ > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > >>> > >>> > >>> -- > >>> PHP General Mailing List (http://www.php.net/) > >>> To unsubscribe, visit: http://www.php.net/unsub.php > >>> > >> > >> > >> -- > >> PHP General Mailing List (http://www.php.net/) > >> To unsubscribe, visit: http://www.php.net/unsub.php > >> > >> > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] How to store data that doesn't change?
When you really NEED a global resource I'm a fan of a registry class. It's a little slower but not noticeable in most cases. With a registry you can store all global data in a single, controlled area. You can also store arrays and resources instead of just strings. One down side to most registry classes is that it's not truly "constant" data, but with magic methods you can correct that. In this class you can store values globally, and once they are set they can't be easily changed. myRegistry::get()->test = array('abc','xyz'); myRegistry::get()->test = 1234; echo myRegistry::get()->test[1]; // should echo 'xyz' I just typed this up real quick so there may be errors; but if you want to try it, it should at least give you the just of it. -untested code class myRegistry { private $_Data = array(); static private $_Object = null; static public function get () { if( !( self::$_Object instanceof self )) self::$_Object = new self(); return self::$_Object; } private function __construct () { } public function __get ($name) { if (isset( $this->_Data[$name] )) return $this->_Data[$name]; return null; } public function __set ($name, $value) { if (isset( $this->_Data[$name] )) return false; return $this->_Data[$name] = $value; } } -- On Thu, Sep 16, 2010 at 10:50 AM, tedd wrote: > At 8:46 AM -0400 9/15/10, Peter van der Does wrote: > >> Hi, >> >> How do you people store data that doesn't change, an example of this >> would be the version number of your software. You might want to use it >> through out your program but how to you store it? >> >> As far as I can see there are several options to use this data. >> 1. Global Variable >> 2. Store it in a registry class >> 3. Store it in a named constant. >> 4. Use a function that will return the data (kind of like a regsitry >> class but it's not a class) >> >> Personally I don't like option 1 but what about the other options. Is >> any of them faster then the others. What other pros and cons are there. >> > > Make it's a Constant -- it's simply a Global that doesn't change. > > I typically hold such things in a global configuration file that can be > included when needed. > > Cheers, > > tedd > > -- > --- > http://sperling.com/ > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] How to store data that doesn't change?
On Sat, Sep 18, 2010 at 12:37 PM, Ashley Sheridan wrote: > On Sat, 2010-09-18 at 12:21 -0400, chris h wrote: > > When you really NEED a global resource I'm a fan of a registry class. It's > a little slower but not noticeable in most cases. > > With a registry you can store all global data in a single, controlled area. > You can also store arrays and resources instead of just strings. One down > side to most registry classes is that it's not truly "constant" data, but > with magic methods you can correct that. > > > In this class you can store values globally, and once they are set they > can't be easily changed. > > myRegistry::get()->test = array('abc','xyz'); > myRegistry::get()->test = 1234; > > echo myRegistry::get()->test[1]; // should echo 'xyz' > > > I just typed this up real quick so there may be errors; but if you want to > try it, it should at least give you the just of it. > -untested code > class myRegistry { > > private $_Data = array(); > > static private $_Object = null; > > > static public function get () { > > if( !( self::$_Object instanceof self )) > self::$_Object = new self(); > > return self::$_Object; > > } > > > private function __construct () { } > > > public function __get ($name) { > > if (isset( $this->_Data[$name] )) > return $this->_Data[$name]; > > return null; > > } > > > public function __set ($name, $value) { > > if (isset( $this->_Data[$name] )) > return false; > > return $this->_Data[$name] = $value; > > } > > } > -- > > On Thu, Sep 16, 2010 at 10:50 AM, tedd wrote: > > > At 8:46 AM -0400 9/15/10, Peter van der Does wrote: > > > >> Hi, > >> > >> How do you people store data that doesn't change, an example of this > >> would be the version number of your software. You might want to use it > >> through out your program but how to you store it? > >> > >> As far as I can see there are several options to use this data. > >> 1. Global Variable > >> 2. Store it in a registry class > >> 3. Store it in a named constant. > >> 4. Use a function that will return the data (kind of like a regsitry > >> class but it's not a class) > >> > >> Personally I don't like option 1 but what about the other options. Is > >> any of them faster then the others. What other pros and cons are there. > >> > > > > Make it's a Constant -- it's simply a Global that doesn't change. > > > > I typically hold such things in a global configuration file that can be > > included when needed. > > > > Cheers, > > > > tedd > > > > -- > > --- > > http://sperling.com/ > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > > > You might want to add in some error returns from the setters instead of > just false, as attempting to overwrite a real constant would issue a notice. > > > Thanks, > Ash > http://www.ashleysheridan.co.uk > I agree Ash, good idea and thanks for the feedback! :)
Re: [PHP] PHP Email Question
> Ignore the other parameters unless you are very familiar with RFCs 2821, > 2822 and their associated RFCs > I would advise against ignoring the other parameters. Doing so will pretty much guarantee having your email end up in SPAM. Instead look up the examples in the docs, or better yet use something like phpmailer as Tom suggested. Chris. On Sun, Sep 19, 2010 at 6:37 PM, TR Shaw wrote: > > On Sep 19, 2010, at 6:00 PM, Joe Jackson wrote: > > > Hi > > > > Sorry for the simple question but I am trying to get my head around PHP. > I > > have a sample PHP script that I am trying to use to send a php powered > email > > message. The snippet of code is shown below > > > >mail('em...@address.com', 'Subject', $values['message'], "From: > > \"{$values['name']}\" <{$values['emailaddress']}>"); > > > > This works fine, but how can I add in other fields to the email that is > > recieved? > > > > For example in the form there are fields called, 'emailaddress', > > 'telephone', 'address' and 'name' which I need to add into the form along > > with the message field > > > > Also with the formatting how can I change the format of the email to > > > > Name: $values['name'], > > Address: etc > > Message: > > > > Joe > > The mail command lets you send mail (an RFC2821 envelop). The function is: > > bool mail ( string $to , string $subject , string $message [, string > $additional_headers [, string$additional_parameters ]] ) > > $to is where you want it to go > $subject is whatever you want the subject to be > $message is the information you want to send Ignore the other parameters unless you are very familiar with RFCs 2821, > 2822 and their associated RFCs > So if you want to send info from a form you might want to roll it up in xml > and send it via the message part. when you receive it you can easily decode > it. If you don't want to do that put it in a format that you can easily > decode on the receiving end. > > Basically "mail" is a way to deliver information in the $message body. How > you format the information there is up to you. However, depending on your > system's config you are probably constrained to placing only 7bit ascii in > the $message body. > > You might also move away from the mail function and look at phpmailer at > sf.net if you need more complex capabilities. > > Tom > > > >
Re: [PHP] Copying an Object
You could create a method of class B that takes an object of class A as a parameter and copies each property line by line (or method of class A that takes an object of class B...). If you don't want to add a method you could just do the same thing, but procedurally. The issue with this (aside from being bad oop) is that you can't copy private properties unless you have all the required getters and setters. The issue with both of these is that it's ugly, high maintenance code. There is the iterator class, extending from which would allow you iterate through all of your properties in a foreach, but if you don't want to add a new method then you likely don't want to add a parent class. I don't care for any of these options, but as far as I know there's no internal PHP mechanism to to copy all the properties from one object to another object of a different class - please correct me if I'm wrong. Is it possible that there's a more elegant solution to your problem that does not include a mass copy of all an object's properties? (e.g. using statics like Mr Bungle suggested or perhaps some nifty design pattern?) Chris H. On Wed, Sep 22, 2010 at 7:35 AM, Daniel Kolbo wrote: > Hello PHPers, > > I have: > > class A { >...code > } > > class B extends A { >...code > } > > $a = new A(); > > $b = new B(); > > I would like to get all of the properties of $a into $b by value. Class > A extends 3 other classes. I would like a way to not have to manage a > 'copy' method in B if A or one of the subclasses of A change. > > I was reading about clone, but this doesn't really seem to help me in > this situation. > > How can I copy $a into $b? > > Thanks, > dK > ` > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Re: Copying an Object
On Fri, Sep 24, 2010 at 8:35 AM, Peter Lind wrote: > On 24 September 2010 14:22, Bob McConnell wrote: > > From: David Hutto > > > >> On Fri, Sep 24, 2010 at 4:09 AM, Gary > wrote: > >>> Daniel Kolbo wrote: > >>> > Say you have two classes: human and male. Further, say male extends > human. Let's say you have a human object. Then later you want to > make > that human object a male object. This seems to be a pretty reasonable > thing to request of our objects. > >>> > >>> I don't think any human can change gender without major surgery, but I > >>> don't know if you just chose your example badly or whether you really > >>> think objects should be able to mutate into other types of object > >>> without some kind of special treatment. > >> > >> But it would work in something like makehuman, where you start with a > neuter > >> form and scale one way or the other for physical features. If I > >> remember correctly, > >> we're' all xx until you become xy(genetically speaking). > > > > This is one of the details that really bothers me about OOP. It makes it > impossible to implement some very reasonable scenarios. 80% of the time, > when a patron is added to a system, we don't know which gender they are. > More than 50% of the time, we will never know, since the client doesn't keep > track of it. But the rest of them will be assigned sometime after they were > added. i.e. the gender assignment comes from a secondary source that is not > available at the time the patron is entered. > > > > If you can't handle that, it's not the fault of OOP but your lack of > programming skills in OOP I'd say (and I mean no disrespect there, I'm > just pretty sure your scenario can be handled very easily in OOP). > > And no, I have no urge to defend OOP in PHP, I just see this entire > thread as a complete non-starter: if the language doesn't let you do > something in a particular way, how about you stop, take a breather, > then ask if perhaps there's a better way in the language to do what > you want done? That would normally be a much more productive and > intelligent response than either a) pressing on in the face of failure > or b) complaining about your specific needs and how the language fails > to meet them. > > Regards > Peter > > -- > > WWW: http://plphp.dk / http://plind.dk > LinkedIn: http://www.linkedin.com/in/plind > BeWelcome/Couchsurfing: Fake51 > Twitter: http://twitter.com/kafe15 > > > I think pages 17-19 of the GoF covers exactly this: "Object composition is an alternative to inheritance." ... "Any [composed] object can be replaced at run-time by another as long as it has the same type." I would look into "object composition" or just read the GoF.
Re: [PHP] Re: Copying an Object
"Gang of Four" http://www.amazon.com/Design-Patterns-Elements-Reusable-Object-Oriented/dp/0201633612 An excellent book on OOP. Chris H. On Fri, Sep 24, 2010 at 9:34 AM, Bob McConnell wrote: > From: chris h > > > On Fri, Sep 24, 2010 at 8:35 AM, Peter Lind > wrote: > > > > On 24 September 2010 14:22, Bob McConnell wrote: > > > From: David Hutto > > > > > >> On Fri, Sep 24, 2010 at 4:09 AM, Gary > wrote: > > >>> Daniel Kolbo wrote: > > >>> > > >>>> Say you have two classes: human and male. Further, say > male extends > > >>>> human. Let's say you have a human object. Then later you > want to make > > >>>> that human object a male object. This seems to be a pretty > reasonable > > >>>> thing to request of our objects. > > >>> > > >>> I don't think any human can change gender without major > surgery, but I > > >>> don't know if you just chose your example badly or whether > you really > > >>> think objects should be able to mutate into other types of > object > > >>> without some kind of special treatment. > > >> > > >> But it would work in something like makehuman, where you > start with a neuter > > >> form and scale one way or the other for physical features. If > I > > >> remember correctly, > > >> we're' all xx until you become xy(genetically speaking). > > > > > > This is one of the details that really bothers me about OOP. > It makes > > it impossible to implement some very reasonable scenarios. 80% of the > time, > > when a patron is added to a system, we don't know which gender they > are. > > More than 50% of the time, we will never know, since the client > doesn't keep > > track of it. But the rest of them will be assigned sometime after they > were > > added. i.e. the gender assignment comes from a secondary source that > is not > > available at the time the patron is entered. > > > > > If you can't handle that, it's not the fault of OOP but your > lack of > > programming skills in OOP I'd say (and I mean no disrespect > there, I'm > > just pretty sure your scenario can be handled very easily in > OOP). > > > > And no, I have no urge to defend OOP in PHP, I just see this > entire > > thread as a complete non-starter: if the language doesn't let > you do > > something in a particular way, how about you stop, take a > breather, > > then ask if perhaps there's a better way in the language to do > what > > you want done? That would normally be a much more productive and > > intelligent response than either a) pressing on in the face of > failure > > or b) complaining about your specific needs and how the language > fails > > to meet them. > > > > I think pages 17-19 of the GoF covers exactly this: > > > > "Object composition is an alternative to inheritance." ... "Any > > [composed] object can be replaced at run-time by another as long > > as it has the same type." > > > > I would look into "object composition" or just read the GoF. > > GoF? > > Bob McConnell > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] if/elseif being treated as if/if
Andy I see no reason why both echo's would fire; unless this block of code gets executed multiple times. can we see more of the code? Chris H. On Fri, Sep 24, 2010 at 1:50 PM, Andy McKenzie wrote: > Hey folks, > > Here's the deal. I have the following code: > > if($col_vals[$i][$val['column']] == $search_result[0][$col]) > { echo ' selected="selected"'; } > elseif($val['default'] == $col_vals[$i][$val['column']]) > { echo ' selected="selected"'; } > > It's supposed to check whether there's a value in the db > ($search_result[0][$col]) that matches the current column value, and > if not, check whether the default matches it. It does that, sort of. > In fact, both statements trigger, which I would have said wasn't > possible. > > So the question is: what causes both parts of an if/elseif > statement to trigger? As far as I can see my punctuation is correct, > and I've confirmed through debugging statements that all the values > are what I expect, so how do I make the elseif stop acting like > another if? Or, alternatively, have I just misunderstood all this > time what the if/elseif statement does? > > Thanks, > Alex > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Array question
Mike, $results[] will automatically push a value unto the end of an array. So doing this... -- $magic = array(); $magic[] = 'a'; $magic[] = 'b'; $magic[] = 'c'; - is exactly this same as doing this... -- $normal = array(); $normal[0] = 'a'; $normal[1] = 'b'; $normal[2] = 'c'; - And yes, in your example "$results[]" would be equivalent to "$results[$j]" For more reference: http://www.php.net/manual/en/language.types.array.php Chris H. On Sat, Sep 25, 2010 at 4:31 PM, MikeB wrote: > I have the following code: > > $query = "SELECT * FROM classics"; > $result = mysql_query($query); > > if (!$result) die ("Database access failed: " . mysql_error()); > $rows = mysql_num_rows($result); > > for ($j = 0 ; $j < $rows ; ++$j) > { >$results[] = mysql_fetch_array($result); > } > > mysql_close($db_server); > > My question, in the loop, why does tha author use: > > $results[] = mysql_fetch_array($result); > > instead of (as I would expect): > > $results[$j] = mysql_fetch_array($result);? > > What PHP magic is at work here? > > Thanks. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Little Parsing help...
Don, How far along are you? To get started something like this may work for you... preg_match_all('/[A-G]{1}#?/', $line, $matches); That SHOULD return each note of the line (you can retrieve them via the $matches array), given that there are no other upper-case characters that are not notes. Also this assumes that $line has exactly one line in it. :) If you get that working, perhaps you can setup something using the preg_replace method? http://php.net/manual/en/function.preg-replace.php Another option is to use the str_replace function. http://us3.php.net/manual/en/function.str-replace.php I gotta run (else I would type some more) but let me know if you want any advice on using those! Chris. On Fri, Oct 1, 2010 at 11:20 AM, Don Wieland wrote: > The logic I need is pretty straight forward, but I am having a hard time > replicating it using PHP functions. I will try to break it down to it's > simplest form: > > I have a field that has several lines of text. Chords and Song Lyrics. > > The "Chord" lines begin with an asterisk "*" and end with the line break. > This is the string I want to parse. Lines with no asterisk at the beginning > are ignored. > > Based on 3 arrays of NOTES, I want SUBSTITUTE the text (based on exact text > character patterns - just NOTES not the chord type) of the lines in my field > that start with an asterisk "*". > > original_chord_array = A, A#, B, C, C#, D, D#, E, F, F#, G, G# > transpose_up_array = A#, B, C, C#, D, D#, E, F, F#, G, G#, A > transpose_down_array = G#, A, A#, B, C, C#, D, D#, E, F, F#, G > > It is important that it only effects EXACT strings. Notes will always be > capitalized and chord types will be lower case. Maybe we can use that > characteristic to better identify what to change. Here are some examples of > chords: > > A > Asus7 > Csus add9 > Dmaj7 > F#m7 > G# > C#dim no3 > > When I transpose UP these chords, just the NOTE should change: > > A# > A#sus7 > C#sus add9 > D#maj7 > Gm7 > A > Ddim no3 > > When I transpose DOWN these chords, just the NOTE should change: > > G# > G#sus7 > Bsus add9 > C#maj7 > Fm7 > G > Cdim no3 > > I am working on a function, but still not producing the proper results. > Hopefully this break down is more clear and someone will bail me out ;-) > > Thanks again for the feedback. > > Don > > > On Oct 1, 2010, at 7:02 AM, Richard Quadling wrote: > > Changing the NormalKeyID and using that ID with NoteSequenceNumber >> should give you the new note to play. >> >> I think. >> > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Scraping Multiple sites
On Sat, Oct 2, 2010 at 9:03 PM, Russell Dias wrote: > I'm currently stuck on a little problem. I'm using cURL in conjunction > with DOMDocument and Xpath to scrape data from a couple of websites. > Please note that is only for personal and educational purposes. > > Right now I have 5 independent scripts (that traverse through 5 > websites) that run via a cron tab every 12 hours. However, as you may > have guessed this is a scalability nightmare. If my list of websites > to scrape grows I have to create another independent script and run it > via cron. > > My knowledge of OOP is fairly basic as I have just gotten started with > it. However, could anyone perhaps suggest a design pattern that would > suit my needs? My solution would be to create an abstract class for > the web crawler and then simply extend it per website I add on. > However, as I said my experience with OOP is almost non-existant > therefore I have no idea how this would scale. I want this 'crawler' > to be one application which can run via one cron rather than having n > amount of scripts for each websites and having to manually create a > cron each time. > > Or does anyone have any experience with this sort thing and could > maybe offer some advice? > > I'm not limited to using PHP either, however due to hosting > constraints Python would most likely be my only other alternative. > > Any help would be appreciated. > > Cheers, > Russell > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > Are the sites that you are crawling so different as to justify maintaining separate chunks of code for each one? I would try to avoid having any code specific to a site, otherwise scaling your application to support even a hundred sites would involve overlapping hundreds of points of functionality and be a logistical nightmare. Unless you're simply wanting to do this for educational reasons... My suggestion would be to attempt to create an application that can craw all the sites, without specifics for each one. You could fire it with a single cron job, and give it a list of the urls you want it to hit. It can crawl one url, record the findings, move to the next, repeat. Chris.
Re: [PHP] Syntax Error
On Sun, Oct 3, 2010 at 12:47 PM, Gary wrote: > I have just created a registration page using Webassist, and I am getting a > syntax error that I am not understanding. Anyone be able to point me in > the > right direction? > > You have an error in your SQL syntax; check the manual that corresponds to > your MySQL server version for the right syntax to use near ' NULL, NULL)' > at > line 1 > > This is the code (I have not modified it) > > > if (!function_exists("GetSQLValueString")) { > function GetSQLValueString($theValue, $theType, $theDefinedValue = "", > $theNotDefinedValue = "") > { > $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; > > $theValue = function_exists("mysql_real_escape_string") ? > mysql_real_escape_string($theValue) : mysql_escape_string($theValue); > > switch ($theType) { > case "text": > $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; > break; > case "long": > case "int": > $theValue = ($theValue != "") ? intval($theValue) : "NULL"; > break; > case "double": > $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; > break; > case "date": > $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; > break; > case "defined": > $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; > break; > } > return $theValue; > } > } > ?> > // *** Redirect if username exists > $MM_flag="MM_insert"; > if (isset($_POST[$MM_flag])) { > $MM_dupKeyRedirect=""; > $loginUsername = $_POST['id']; > $LoginRS__query = "SELECT id FROM family WHERE id='" . $loginUsername . > "'"; > mysql_select_db($database_local, $local); > $LoginRS=mysql_query($LoginRS__query, $local) or die(mysql_error()); > $loginFoundUser = mysql_num_rows($LoginRS); > > //if there is a row in the database, the username was found - can not add > the requested username > if($loginFoundUser){ > $MM_qsChar = "?"; > //append the username to the redirect page > if (substr_count($MM_dupKeyRedirect,"?") >=1) $MM_qsChar = "&"; > $MM_dupKeyRedirect = $MM_dupKeyRedirect . $MM_qsChar > ."requsername=".$loginUsername; > header ("Location: $MM_dupKeyRedirect"); > exit; > } > } > ?> > $editFormAction = $_SERVER['PHP_SELF']; > if (isset($_SERVER['QUERY_STRING'])) { > $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']); > } > > ?> > if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == > "WAATKRegistrationForm")) { > $insertSQL = sprintf("INSERT INTO family (firstname, lastname, email, > password, relationship, story, image, ip, submitted) VALUES (%s, %s, %s, > %s, > %s, %s, %s, %s, %s)", > GetSQLValueString($_POST['firstname'], "text"), > GetSQLValueString($_POST['lastname'], "text"), > GetSQLValueString($_POST['email'], "text"), > GetSQLValueString($_POST['password'], "text"), > GetSQLValueString($_POST['relationship'], "text"), > GetSQLValueString($_POST['story'], "text"), > GetSQLValueString($_POST['image'], ""), GetSQLValueString($_POST['ip'], > "text"), GetSQLValueString($_POST['submitted'], "date")); > > mysql_select_db($database_local, $local); > $Result1 = mysql_query($insertSQL, $local) or die(mysql_error()); > > $insertGoTo = "family_LogIn.php"; > if (isset($_SERVER['QUERY_STRING'])) { > $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; > $insertGoTo .= $_SERVER['QUERY_STRING']; > } > header(sprintf("Location: %s", $insertGoTo)); > } > ?> > > Thanks again for the help. > > Gary > > > > __ Information from ESET Smart Security, version of virus signature > database 5499 (20101003) __ > > The message was checked by ESET Smart Security. > > http://www.eset.com > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > MySQL is not liking a query. It looks to be this one: $insertSQL = sprintf("INSERT INTO family (firstname, lastname, email, password, relationship, story, image, ip, submitted) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)", I would echo or log $insertSQL just before you pass it to mysql_query() and see if the SQL syntax looks right. Chris.
[PHP] PHPExcel with large files (27,000+ rows)
I'm currently working on a project that requires the parsing of excel files. Basically the user uploads an excel file, and then a script needs to save a row in a Postgres database for each row in the excel file. The issue we are having is that when we task PHPExcel with parsing an excel file with, say 27k rows, it explodes with a memory error. I've read up on the PHPExcel forums and we've tried cell caching as well as ReadDataOnly, they do not seem to be sufficient. Does anyone here know of a way to do this? Surely there is a way to parse a large excel file with PHP. This is also NOT an on-demand service. That is, when someone uploads a file they get a task_id which allows them to check the status of their excel file. So the solution does not need to be a fast one! Thanks, Chris.
Re: [PHP] PHPExcel with large files (27,000+ rows)
Thanks Jessen/Marc, though the user provided format can be in xls, xlsx, or csv. So i need a solution to support all formats. Thanks for the ideas shiplu I'll get with the team and see if there's anything there we aren't trying. Chris. On Mon, Oct 4, 2010 at 3:01 PM, shiplu wrote: > On Tue, Oct 5, 2010 at 12:39 AM, chris h wrote: > > I'm currently working on a project that requires the parsing of excel > files. > > Basically the user uploads an excel file, and then a script needs to > save a > > row in a Postgres database for each row in the excel file. The issue we > are > > having is that when we task PHPExcel with parsing an excel file with, say > > 27k rows, it explodes with a memory error. I've read up on the PHPExcel > > forums and we've tried cell caching as well as ReadDataOnly, they do not > > seem to be sufficient. > > > > Does anyone here know of a way to do this? Surely there is a way to parse > a > > large excel file with PHP. This is also NOT an on-demand service. That > is, > > when someone uploads a file they get a task_id which allows them to check > > the status of their excel file. So the solution does not need to be a > fast > > one! > > > > > > Thanks, > > Chris. > > > > 1. Remove any variable that contains big object if its not necessary. > 2. Use unset when applicable > 3. Read chunk by chunk. > 4. Profile it to find the exact place where you are wasting memory. > Optimizing that little portion of code can improve memory performance. > > -- > Shiplu Mokadd.im > My talks, http://talk.cmyweb.net > Follow me, http://twitter.com/shiplu > SUST Programmers, http://groups.google.com/group/p2psust > Innovation distinguishes bet ... ... (ask Steve Jobs the rest) >
Re: [PHP] Re: Continuance of the struggle (trying to understand)
"If I paste the script into a web page" What do you mean by "paste the script into a web page"? Can you tell us exactly what you are doing when you do that? Chris. On Tue, Oct 5, 2010 at 7:54 AM, Col Day wrote: > Hi Shreyas, > > Ok, as far as I can tell the script should show "This is an HTML line" > reflecting that I am seeing the HTML part of the script followed by "This is > a PHP line" to show that PHP is installed and working fine. > > If I view the script directly in IE by going to > http://localhost/phptest.php I get the output: > > > This is an HTML line > > This is a PHP line > > followed by a large and detailed list of the PHP install which includes > things like compiler language etc. > > If I paste the script into a web page then all that is displayed is > > This is an HTML line. > > Nothing else whatsoever. > > I am fairly confused. I've tried a couple of different web page creators > (Webplus 10 and Web page maker) and get the same result. > > Sorry if I sound extremely naive but it's bugging me now and I want to > understand. > > Cheers > > "Shreyas Agasthya" wrote in message > news:aanlkti=4ke1stf8tan7+ecjo-ux5cj=t9-0qctcfk...@mail.gmail.com... > > Col, >> >> Can you let us know what exactly you see when you say >> http://localhost:/phptest.php >> ? >> >> >> Regards, >> Shreyas >> >> On Tue, Oct 5, 2010 at 4:20 PM, Col Day wrote: >> >> >>> ""Col Day"" wrote in message >>> news:23.81.45586.2820b...@pb1.pair.com... >>> >>> Hi all, >>> After my escapades with the real basics and realizing my laptop wasn't logged on as Administrator, I now am trying to work out why this script works sometimes but not others. PHP Test This is an HTML line >>> echo "This is a PHP line"; phpinfo(); ?> If I save this as phptest.php and open IE pointing it to localhost/phptest.php it works fine. Get both lines of text followed by the pages of gumpf about php. However if I paste this into a That was weird! >>> >>> I was saying, If I paste this into a webpage I only get the "HTML" line >>> as >>> before. >>> >>> Anyone have any ideas? >>> >>> PHP is obviously working as is apache. Just don't understand why they >>> don't >>> show up in web pages. >>> >>> Cheers again all! >>> >>> -- >>> PHP General Mailing List (http://www.php.net/) >>> To unsubscribe, visit: http://www.php.net/unsub.php >>> >>> >>> >> >> -- >> Regards, >> Shreyas Agasthya >> >> > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] which one is faster
Benchmark and find out! :) What are you using this for? Unless you are doing something crazy it probably doesn't matter, and you should pick whichever you feel looks nicer / is easier to code in / etc. Chris H. On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed wrote: > $a = 'hey'; > $b = 'done'; > > $c = $a.$b; > $c = "$a$b"; > > which one is faster for echo $c. >
Re: [PHP] which one is faster
Saeed here's a quick (and dirty) test I ran: $tests = 100; $start = microtime(true); for ($i=0; $i<$tests; $i++) { $a = md5( rand() ); $b = md5( rand() ); $c = $a.$b; } var_dump( "By concat op:\t". (microtime(true) - $start) ); $start = microtime(true); for ($i=0; $i<$tests; $i++) { $a = md5( rand() ); $b = md5( rand() ); $c = "$a$b"; } var_dump( "By string:\t\t". (microtime(true) - $start) ); Sample results: string(30) "By concat op: 2.1713118553162" string(27) "By string: 2.2525599002838" string(30) "By concat op: 2.2123351097107" string(27) "By string: 2.2798750400543" string(29) "By concat op: 2.1521489620209" string(27) "By string: 2.2470209598541" string(29) "By concat op: 2.1347990036011" string(27) "By string: 2.1982681751251" I would say that under virtually all cases that difference is less then negligible. Chris H. On Tue, Oct 5, 2010 at 3:35 PM, Ashley Sheridan wrote: > On Tue, 2010-10-05 at 15:28 -0400, chris h wrote: > > Benchmark and find out! :) > > What are you using this for? Unless you are doing something crazy it > probably doesn't matter, and you should pick whichever you feel looks nicer > / is easier to code in / etc. > > Chris H. > > On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed wrote: > > > $a = 'hey'; > > $b = 'done'; > > > > $c = $a.$b; > > $c = "$a$b"; > > > > which one is faster for echo $c. > > > > > As far as I'm aware, the first of the two will be faster, but only just. As > Saeed mentioned, the difference will be negligible, and unless you plan to > run a line like that in a loop or something hundreds of thousands of times, > you probably won't notice any difference. > Thanks, > Ash > http://www.ashleysheridan.co.uk > > >
Re: [PHP] which one is faster
On Tue, Oct 5, 2010 at 3:53 PM, Ashley Sheridan wrote: > On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote: > > > On Tue, 2010-10-05 at 20:35 +0100, Ashley Sheridan wrote: > > > On Tue, 2010-10-05 at 15:28 -0400, chris h wrote: > > > > > > > Benchmark and find out! :) > > > > > > > > What are you using this for? Unless you are doing something crazy it > > > > probably doesn't matter, and you should pick whichever you feel looks > nicer > > > > / is easier to code in / etc. > > > > > > > > Chris H. > > > > > > > > On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed > wrote: > > > > > > > > > $a = 'hey'; > > > > > $b = 'done'; > > > > > > > > > > $c = $a.$b; > > > > > $c = "$a$b"; > > > > > > > > > > which one is faster for echo $c. > > > > > > > > > > > > > > As far as I'm aware, the first of the two will be faster, but only > just. > > > As Saeed mentioned, the difference will be negligible, and unless you > > > plan to run a line like that in a loop or something hundreds of > > > thousands of times, you probably won't notice any difference. > > > Thanks, > > > Ash > > > http://www.ashleysheridan.co.uk > > > > > > > > > > > > to be proper, shouldn't it technically be > > $c = "{$a}{$b}"; > > > > ?? > > > > Steve. > > > > > > > It doesn't have to use the braces. The braces only tell PHP exactly > where to stop parsing the current variable name. The following examples > wouldn't work without them: > > $var = 'hello '; > $arr = array('msg 1'=>'hello','msg 2'=>'world'); > > echo "{$var}world"; > echo "{$arr['msg 1']}{$arr['msg 2']}"; > > Without the braces, in the first example PHP would look for a variable > called $varworld, and in the second it would be looking for a simple > scaler called $arr, not the array value you wanted. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > > Just to add in here, they are also required when calling an object's properties, if - ready for this? - that object is itself a property of another object. so while this would work, "$circle->circumference" this would NOT work "$circle->circumference->inches" The later would be injecting the $circle->circumference property, followed by string literal "->inches". So to get it to work you would need to use curlys. "{$circle->circumference->inches}" Chris H.
Re: [PHP] Variable (Class instantiation) collision
Just to clarify, both packages are instantiating and calling their respective database classes from the $db var, which is in the global scope. Is this correct? This is why I hate the global scope, I hate it, I hate it! On Tue, Oct 5, 2010 at 3:47 PM, Brian Smither wrote: > I am running into a variable collision. The project I'm developing is NOT > guaranteed to be operating on PHP5. Any solution I find should (hopefully) > be able to run on PHP4 (yes, I know PHP4 is deprecated). > > I am building a bridge between two third-party applications. Both > instantiate their respective database class assigning it to $db and I cannot > change that. > > So, I am interested in solutions to this. > > I found a reference to a Packager class and will be looking at it shortly. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] which one is faster
On Tue, Oct 5, 2010 at 3:58 PM, Steve Staples wrote: > On Tue, 2010-10-05 at 20:53 +0100, Ashley Sheridan wrote: > > On Tue, 2010-10-05 at 15:46 -0400, Steve Staples wrote: > > > > > On Tue, 2010-10-05 at 20:35 +0100, Ashley Sheridan wrote: > > > > On Tue, 2010-10-05 at 15:28 -0400, chris h wrote: > > > > > > > > > Benchmark and find out! :) > > > > > > > > > > What are you using this for? Unless you are doing something crazy > it > > > > > probably doesn't matter, and you should pick whichever you feel > looks nicer > > > > > / is easier to code in / etc. > > > > > > > > > > Chris H. > > > > > > > > > > On Tue, Oct 5, 2010 at 3:23 PM, saeed ahmed > wrote: > > > > > > > > > > > $a = 'hey'; > > > > > > $b = 'done'; > > > > > > > > > > > > $c = $a.$b; > > > > > > $c = "$a$b"; > > > > > > > > > > > > which one is faster for echo $c. > > > > > > > > > > > > > > > > > > As far as I'm aware, the first of the two will be faster, but only > just. > > > > As Saeed mentioned, the difference will be negligible, and unless you > > > > plan to run a line like that in a loop or something hundreds of > > > > thousands of times, you probably won't notice any difference. > > > > Thanks, > > > > Ash > > > > http://www.ashleysheridan.co.uk > > > > > > > > > > > > > > > > > to be proper, shouldn't it technically be > > > $c = "{$a}{$b}"; > > > > > > ?? > > > > > > Steve. > > > > > > > > > > > > It doesn't have to use the braces. The braces only tell PHP exactly > > where to stop parsing the current variable name. The following examples > > wouldn't work without them: > > > > $var = 'hello '; > > $arr = array('msg 1'=>'hello','msg 2'=>'world'); > > > > echo "{$var}world"; > > echo "{$arr['msg 1']}{$arr['msg 2']}"; > > > > Without the braces, in the first example PHP would look for a variable > > called $varworld, and in the second it would be looking for a simple > > scaler called $arr, not the array value you wanted. > > > > Thanks, > > Ash > > http://www.ashleysheridan.co.uk > > > > > Ash: > > I understand what the {} does, but just like in HTML, it is more proper > to use lower case for the attributes/elements, and use " (double quotes) > when wrapping the attributes... but is it not "REQUIRED" to write it in > that manner... just like it is not required to wrap the variables in {} > when inside the ""... > > that's just me, I tend to try and do that every time... > > Steve. > > Unlike HTML, PHP interpretation doesn't have various browsers to contend with. And even if it was not proper I have a doubt that not using {} would become deprecated anytime soon. Also laziness is a trait of a good programmer! :) http://c2.com/cgi/wiki?LazinessImpatienceHubris Chris H.
Re: [PHP] Variable (Class instantiation) collision
Short of refactoring ApplicationB, can you set it up as a SOAP/REST service that AppA calls? On Tue, Oct 5, 2010 at 5:02 PM, Brian Smither wrote: > > >Just to clarify, both packages are instantiating and calling their > >respective classes from the $db var, which is in the global scope. > >Is this correct? > > I would say yes to the way you are asking. Take the following two > applications. The four respective statements are in each their respective > script. > > Application A: > class foo {} > $db = new foo(); > $outA = barA(); > function barA() { global $db; include("Application B"); } > ?> > > Application B: > class bar {} > $db = new bar(); > $outB = barB(); > function barB() { global $db; } > ?> > > The bridge project is operating in A and include()'ing the script that is B > (as I have not found an API for B). $db in B is colliding with $db in A. > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Class mysqli not found
mysqli is set of functions not a class. The name to connect is mysqli_connect mysqli can be used as either a set of functions ( mysqli_connect(..) ) OR it can be used an an object ( new mysqli(...) ). When used as an object you just use the various functions as methods. http://www.php.net/manual/en/mysqli.connect.php Chris. On Wed, Oct 6, 2010 at 4:33 PM, Alejandro Michelin Salomon < amichel...@hotmail.com> wrote: > Sueandant : > > mysqli is set of functions not a class. The name to connect is > mysqli_connect > /** > * > * > * @version $Id$ > * @copyright 2010 > */ > $mysqli = mysqli_connect ("localhost", "root", "woodcote", "testDB"); > > if (mysqli_connect_errno()) { > printf("Connect failed: %s\n", mysqli_connect_error()); > exit(); > } else { > printf("Host information: %s\n", mysqli_get_host_info($mysqli)); > } > > > Try adodb lib for php ( http://adodb.sourceforge.net/ ), is great layer on > top of php db functions. > > Alejandro M.S. > > -Mensagem original- > De: sueandant [mailto:hollandsath...@tiscali.co.uk] > Enviada em: quarta-feira, 6 de outubro de 2010 17:27 > Para: sstap...@mnsi.net > Cc: PHP > Assunto: Re: [PHP] Class mysqli not found > > Thanks Steve. Here's the php file: > > > /** > * > * > * @version $Id$ > * @copyright 2010 > */ > $mysqli = new mysqli("localhost", "root", "woodcote", "testDB"); > > if (mysqli_connect_errno()) { > printf("Connect failed: %s\n", mysqli_connect_error()); > exit(); > } else { > printf("Host information: %s\n", mysqli_get_host_info($mysqli)); > } > > ?> > > When I run this small program I get a Fatal Error: Class mysqli not found > error message. > > > - Original Message - > From: "Steve Staples" > To: "sueandant" > Cc: "PHP" > Sent: Wednesday, October 06, 2010 9:09 PM > Subject: Re: [PHP] Class mysqli not found > > > > On Wed, 2010-10-06 at 21:00 +0100, sueandant wrote: > >> I'm still fighting a losing battle in my attempts to get PHP speak to > >> mysqli. I can access MySql via the prompt. Apache and PHP are > installed > >> and working. In Apache's config file PHPIniDir is set to "C:\php", > >> which is where I unzipped the binary download files, and set LoadModule > >> php5_module C:\php\php5apache2_2.dll. In php.ini I have uncommented > the > >> mysql.dll and mysqli.dll extensions and set extension_dir = > >> "C:\php\ext\". I have edited the environment variables to include > >> C:\php and C:php\ext. > >> > >> I am running Vista Home Premium 32 bit with SP2, Apache 2.2, PHP 5.3.3 > >> and MySql Server 5.1. > >> > >> What have I missed? > > > > How are you connecting to the mysql? What does your connection string > > look like from your php file? Can you cut and paste it here for us to > > trouble shoot (if it is the apache->php->mysql connection problem) > > > > > > Steve > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: RES: [PHP] Class mysqli not found
Are you doing phpinfo() off the CLI or via apache mod? Is it the same way you are running the actual script that's calling on mysqli? On Wed, Oct 6, 2010 at 4:58 PM, sueandant wrote: > phpinfo() includes mysqli in its detailed output: > > mysqli > MysqlI Support enabled > Client API library version mysqlnd 5.0.7-dev - 091210 - $Revision: > 300533 $ > Active Persistent Links 0 > Inactive Persistent Links 0 > Active Links 0 > > Directive Local Value Master Value > mysqli.allow_local_infile On On > mysqli.allow_persistent On On > mysqli.default_host no value no value > mysqli.default_port 3306 3306 > mysqli.default_pw no value no value > mysqli.default_socket no value no value > mysqli.default_user no value no value > mysqli.max_links Unlimited Unlimited > mysqli.max_persistent Unlimited Unlimited > mysqli.reconnect Off Off > > - Original Message - From: "Simon J Welsh" > To: "Alejandro Michelin Salomon" > Cc: "'sueandant'" ; < > php-general@lists.php.net> > Sent: Wednesday, October 06, 2010 9:43 PM > Subject: Re: RES: [PHP] Class mysqli not found > > > > http://php.net/manual/en/class.mysqli.php definitely says MySQLi is a > class. > > It looks like PHP was complied without MySQLi support. Does running a > phpinfo() show the MySQLi module? > On 7/10/2010, at 9:33 AM, Alejandro Michelin Salomon wrote: > > Sueandant : >> >> mysqli is set of functions not a class. The name to connect is >> mysqli_connect >> /** >> * >> * >> * @version $Id$ >> * @copyright 2010 >> */ >> $mysqli = mysqli_connect ("localhost", "root", "woodcote", "testDB"); >> >> if (mysqli_connect_errno()) { >> printf("Connect failed: %s\n", mysqli_connect_error()); >> exit(); >> } else { >> printf("Host information: %s\n", mysqli_get_host_info($mysqli)); >> } >> >> >> Try adodb lib for php ( http://adodb.sourceforge.net/ ), is great layer >> on top of php db functions. >> >> Alejandro M.S. >> >> -Mensagem original- >> De: sueandant [mailto:hollandsath...@tiscali.co.uk] >> Enviada em: quarta-feira, 6 de outubro de 2010 17:27 >> Para: sstap...@mnsi.net >> Cc: PHP >> Assunto: Re: [PHP] Class mysqli not found >> >> Thanks Steve. Here's the php file: >> >> > >> /** >> * >> * >> * @version $Id$ >> * @copyright 2010 >> */ >> $mysqli = new mysqli("localhost", "root", "woodcote", "testDB"); >> >> if (mysqli_connect_errno()) { >> printf("Connect failed: %s\n", mysqli_connect_error()); >> exit(); >> } else { >> printf("Host information: %s\n", mysqli_get_host_info($mysqli)); >> } >> >> ?> >> >> When I run this small program I get a Fatal Error: Class mysqli not found >> error message. >> >> >> - Original Message - From: "Steve Staples" >> To: "sueandant" >> Cc: "PHP" >> Sent: Wednesday, October 06, 2010 9:09 PM >> Subject: Re: [PHP] Class mysqli not found >> >> >> On Wed, 2010-10-06 at 21:00 +0100, sueandant wrote: >>> I'm still fighting a losing battle in my attempts to get PHP speak to mysqli. I can access MySql via the prompt. Apache and PHP are installed and working. In Apache's config file PHPIniDir is set to "C:\php", which is where I unzipped the binary download files, and set LoadModule php5_module C:\php\php5apache2_2.dll. In php.ini I have uncommented the mysql.dll and mysqli.dll extensions and set extension_dir = "C:\php\ext\". I have edited the environment variables to include C:\php and C:php\ext. I am running Vista Home Premium 32 bit with SP2, Apache 2.2, PHP 5.3.3 and MySql Server 5.1. What have I missed? >>> >>> How are you connecting to the mysql? What does your connection string >>> look like from your php file? Can you cut and paste it here for us to >>> trouble shoot (if it is the apache->php->mysql connection problem) >>> >>> >>> Steve >>> >>> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> > --- > Simon Welsh > Admin of http://simon.geek.nz/ > > Who said Microsoft never created a bug-free program? The blue screen never, > ever crashes! > > http://www.thinkgeek.com/brain/gimme.cgi?wid=81d520e5e > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Array / form processing
$_SESSION['life_coaching_order'][$product][$gift]['quantity'] = $_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1; === ... === foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference => $value ) { === In this example $value would be an array. To test if it is a gift or not you would do this from within the foreach loop: //gift if ( isset($value[1]) && isset($value[1]['quantity']) ) { $gift_quantity = $value[1]['quantity']; } //personal use if ( isset($value[2]) && isset($value[2]['quantity']) ) { $personal_quantity = $value[2]['quantity']; } Technically the above IF's are optional, but they are proper syntax. I don't know how you are with OOP, but you may have more luck using objects instead of a complex array. Chris H. On Thu, Oct 7, 2010 at 3:35 PM, Ron Piggott wrote: > > I am writing a custom shopping cart that eventually the "cart" will be > uploaded to PayPal for payment. I need to be able to include the option > that the purchase is a gift certificate. > > > > At present my "add to cart" function goes like this: > > === > # Gift Certificate: 1 is a gift; 2 is personal use > > if ( $gift_certificate == "yes" ) { >$gift = 1; > } else { >$gift = 2; > } > > $_SESSION['life_coaching_order'][$product][$gift]['quantity'] = > $_SESSION['life_coaching_order'][$product][$gift]['quantity'] + 1; > === > > Now I need to display the shopping cart contents. I want to do this > through an array as the contents of the shopping cart are in a session > variable. I start displaying the shopping cart contents by a "FOREACH" > loop: > > === > foreach ($_SESSION['life_coaching_order'] AS $coaching_fee_theme_reference > => $value ) { > === > > What I need help with is that I don't know how to test the value of $gift > in the above array if it is a 1 or 2 (which symbolizes this is a gift > certificate). > > I have something like this in mind: > if ( $_SESSION['life_coaching_order'] == 2 ) { > > But I don't know how to access all the components of the array while I am > going through the FOREACH loop. > > By using a "1" or "2" I have made gift certificates their own product. If > you a better method I could use please provide me with this feedback. > > Ron > > The Verse of the Day > Encouragement from God's Word > www.TheVerseOfTheDay.info > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Array / form processing
I don't know what the context is like, but you may be better off just using an entire form here with hidden fields. i.e. Without knowing what else is going on in your page, and how the request is being handled on the server, it's kind of hard to give exact advice. :) Chris H.
Re: [PHP] class object vs array for db table model
On Tue, Oct 12, 2010 at 2:38 AM, Tommy Pham wrote: > Hi everyone, > > It's been a couple years since I've did a project in PHP. The current > project I'm working on is for PHP 5.3 and I noticed a performance issue. > Is > it just me or is there a BIG difference in performance between class object > vs array for PHP 5.3? Below is the sample: > > class MyTable > { >private $_id; // int >private $_name; // varchar >private $_description; // text > >public function __construct() {} > >public function getId() >{ >return $this->_id; >} >public function getName() >{ >return $this->_name; >} >public function getDescription() >{ >return $this->_description; >} > >public function setId($id) >{ >$this->_id = $id; >} >public function setName($name) >{ >$this->_name = $name; >} >public function setDescription($description) >{ >$this->_description = $description; >} > } > > $my_table = array ('id' => 'id value', 'name' => 'name value', > 'description' > => 'long description text'); > > The above are representations for my table as class and as array, > respectively. The only difference is how I represent the results from db: > > 1) as class object > $list = array(); > while ($row = $db->fetch($result)) > { >$my_table = new MyTable(); >$my_table->setId($row['id']); >$my_table->setName($row['name']); >$my_table->setDescription($row['description']); > >$list[$my_table->getId()] = $my_table; > } > > 2) as table > $list = array(); > while ($row = $db->fetch($result)) > { >$my_table['id'] = $row['id']; >$my_table['name'] = $row['name']; >$my_table['description'] = $row['description']; > >$list[$my_table['id'] = $my_table; > } > > The performance difference I get is about 1.4 seconds with the array in the > lead!!! Does anyone have the same problem? > > Thanks, > Tommy > > PS: The above executed in 4.2 sec and 1.8 sec (on average) respectively w/o > actually showing the results to html, while my ASP.NET project executes it > and displays in html in about 2 seconds for all 3684 rows, using class > similar to the MyTable. All codes, PHP & ASP.NET C#, access the same > MySQL > DB on the same development box. > > When you are adding a row as an object you are calling 4 user functions: MyTable::__construct(), MyTable::setId(), MyTable::setName(), and MyTable::setDescription(). This adds some overhead for sure, so you might want to think about passing the row array into the construct and doing away with the setters (at least for the initial instantiations). Something like this... - public function __construct($dataArray=null) { foreach ((array)$dataArray as $rowKey => $rowValue) { $this->$rowKey = $rowValue; } } ==OR== public function __construct($dataArray=null) { // maybe add casting here as well? $this->_id = isset($dataArray['id'])? $dataArray['id']: null; $this->_name = isset($dataArray['name'])? $dataArray['name']: null; $this->_description = isset($dataArray['description'])? $dataArray['description']: null; } ==And instantiate like this== $list = array(); while ($row = $db->fetch($result)) { // I also changed setting the $list's key with "$row['id']" instead of using the MyTable getter. $list[$row['id']] = new MyTable($row); } --- I don't know how much faster that will run for you (if at all) but using your method you were calling 5 user functions per result set from the db (that's the construct, the getter to set the $list key, and 1 for each of the 3 properties of the result) for a total of 18,420 user function calls. With my method I'm calling 1 user function (the construct) for each set, for a total of 3,684 calls. Of course a down-side is that if there's any logic in your setters then that needs to be replicated in your construct. Another method is to use a single object for all 3684 records. Perhaps you can use the built in Iterator interface which lets your class's objects be used as if they were an array for the purposes of foreach loops. http://php.net/manual/en/language.oop5.iterations.php You would set a pointer to the record you wish to use, and your getters and setters would key off that element of the master array. This should be a fast solution, while still giving you the power of encapsulation, getters and setters. Hope that helps! Chris.
Re: [PHP] class object vs array for db table model
hehe that's pretty funny; also funny oversight of mine in regards to isset()... so I guess we're both comedians today? ;-) Glad you got that worked out Tommy! Chris. On Tue, Oct 12, 2010 at 8:46 AM, Tommy Pham wrote: > On Tue, Oct 12, 2010 at 4:45 AM, chris h wrote: > > > > > > > > > > > When you are adding a row as an object you are calling 4 user > > functions: MyTable::__construct(), MyTable::setId(), MyTable::setName(), > and > > MyTable::setDescription(). This adds some overhead for sure, so you > might > > want to think about passing the row array into the construct and doing > away > > with the setters (at least for the initial instantiations). > > Something like this... > > - > > public function __construct($dataArray=null) > > { > > foreach ((array)$dataArray as $rowKey => $rowValue) > > { > > $this->$rowKey = $rowValue; > > } > > } > > ==OR== > > public function __construct($dataArray=null) > > { > > // maybe add casting here as well? > > $this->_id = isset($dataArray['id'])? > > $dataArray['id']: null; > > $this->_name = isset($dataArray['name'])? > > $dataArray['name']: null; > > $this->_description = isset($dataArray['description'])? > > $dataArray['description']: null; > > } > > ==And instantiate like this== > > $list = array(); > > while ($row = $db->fetch($result)) > > { > > // I also changed setting the $list's key with "$row['id']" instead of > > using the MyTable getter. > > $list[$row['id']] = new MyTable($row); > > } > > --- > > I don't know how much faster that will run for you (if at all) but using > > your method you were calling 5 user functions per result set from the db > > (that's the construct, the getter to set the $list key, and 1 for each of > > the 3 properties of the result) for a total of 18,420 user function > calls. > > With my method I'm calling 1 user function (the construct) for each set, > > for a total of 3,684 calls. Of course a down-side is that if there's any > > logic in your setters then that needs to be replicated in your construct. > > Another method is to use a single object for all 3684 records. Perhaps > you > > can use the built in Iterator interface which lets your class's objects > be > > used as if they were an array for the purposes of foreach loops. > > http://php.net/manual/en/language.oop5.iterations.php > > You would set a pointer to the record you wish to use, and your getters > and > > setters would key off that element of the master array. This should be a > > fast solution, while still giving you the power of encapsulation, getters > > and setters. > > > > Hope that helps! > > Chris. > > > > Hi Chris, > > Thanks for the reply. The sample I made is just for simplicity and > comparison. As for function calling 'get's, I think the speed would > come out to be same in your sample since you're doing isset() > checking. My actual class is more sophisticated having the psuedo > overloading as you mentioned. The class is generated from a PHP class > builder - to save on typing - I made a long time ago with some minor > update. > > Anyway, I was frustrated as to why my code took so long to execute and > had to dig deep. As it turns out, I had xdebug loaded with all > options on ... lol. Removed the extension and all is good in the > world. The script runs in less than 150ms :D!!! > > Thanks, > Tommy > > PS: This is what I get for not coding in PHP so long ... >
Re: [PHP] Buffering output to allow headers late in code?
> > > I'm working through my class on PHP and I tried to put information from my > sign-on process in the navbar. This didn't work well, since I had to reload > the page to see it as the navbar was constructed earlier in the code than > the signon process. (Hard to explain, as we are building a "dynamic" web > page with lots of include files to fill in the main contnt portion of the > page.) > > I don't know if this will be much help, but I try to do all the controller / model work before I mess with the view side. So the controller starts off with the ball, then he and the model pass it between each other a few times until the controller finally hands it over to the view, who does her magic and makes the score! ... Perhaps that analogy went to far. At any rate! Ideally the sign-on task would be done before any tasks that would use sign-on data. Additionally, the layout of your page should not necessarily dictate the order of any tasks (i.e. the sign-on box being below the welcome box should not mean that the sign-on task gets done before the welcome task). Hope that helps! Chris.
Re: [PHP] floored by floor()
floor(32703) is different then floor(327.03 * 100). The former is an int, while the later is a float. Read those links that were sent :) Chris. On Thu, Oct 14, 2010 at 2:14 AM, Glen Fuller wrote: > On 10/13/2010 10:48 PM, Mattias Thorslund wrote: > >> Hi List, >> >> I'm having a problem with the behavior of the floor() function: >> >> echo floor(327.03 * 100)."\n"; //prints "32702" and not "32703"!! >> >> Sanity check: >> var_dump(327.03 * 100); //prints "float(32703)" as expected >> >> Any ideas why this happens, and how to work around it? >> >> Thanks, >> >> Mattias >> >> >> > Wouldn't that be equivalent to floor(32703), and since 32703 is the nearest > integer to 32703 it returns it? > > Glen Fuller > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] Text messaging from the web
> > You can send a text message via email: > >Verizon: 10digitphonenum...@vtext.com >AT&T: 10digitphonenum...@txt.att.net >Sprint: 10digitphonenum...@messaging.sprintpcs.com >T-Mobile: 10digitphonenum...@tmomail.net >Nextel: 10digitphonenum...@messaging.nextel.com >Cingular: 10digitphonenum...@cingularme.com >Virgin Mobile: 10digitphonenum...@vmobl.com >Alltel: 10digitphonenum...@message.alltel.com >CellularOne: 10digitphonenum...@mobile.celloneusa.com >Omnipoint: 10digitphonenum...@omnipointpcs.com >Qwest: 10digitphonenum...@qwestmp.com > > Larry, it seems like this method would only be useful if you knew the carrier of a specific number. Do you know of a way to determine that? Chris.
Re: [PHP] Re: Buffering output to allow headers late in code?
> > > Then someone said that using buffering was a bad idea and I should disable > it. > > I think it leads to poor habits like calling controller methods out of the view (essentially what you are wanting to use it for). Using it like that is asking for spaghetti code that's hard to maintain, scale, and train new developers on. I'd imagine it also adds overhead, though I don't know how much - my guess is negligible. OB can be a great tool, but it shouldn't be a hack to get around sloppy architecture. Just my 2 cents :) Chris.
Re: [PHP] Execute a php page and don't wait for it to finish
What about simply having the script trip a flag that another background script checks every 60 seconds or so? Once a minutes a background script checks to see if it needs to preform any tasks. When a user hits a certain page it does an ajax request to trip this flag and immediately returns. The next time the background script checks if it needs to do anything, it sees the tripped flag and preforms the relevant database copy - or whatever :-) Chris. On Tue, Oct 19, 2010 at 9:20 AM, Ferdi wrote: > Hi List, > > I have a php page that updates data from one database to another when it is > run. > My query is, how can I trigger the execution of this update page from > another php / javascript without the calling page having to wait for the > update page to finish? > Basically, I think the update page needs to use: > ignore_user_abort(1); > set_time_limit(0); // I don't think the script will take more than 1 min. > > At the other end I found this: > 1) > > http://www.mindraven.com/blog/php/run-a-php-script-in-the-background-using-ajax/ > 2) On that page a user suggested using *pclose(popen(‘/usr/bin/php > /path/to/something.php > /dev/null &’, ‘r’)* > **However, I need this to be usable on windows servers also. > 3) Finally, would pcntl_exec, pcntl_fork, exec or something be useful for > me? > > Which of the above 3 options is the better one? > Other suggestions are welcome :) > > Thanks and Regards, > Ferdi >
Re: [PHP] require_once
> > I'm having a problem including files using Zend Framework. I have in a > controller file this > > Jim why not use the Zend autoloader? Chris.
Re: [PHP] require_once
I see! Yes using an autoloader typically requires following a naming convention for your classes (though you can get around it by defining your own naming rules). I didn't care for it much at first, but it's nice that class names are explicit (less confusion when you have several) and not worrying about requiring all your files is a plus. Chris. On Tue, Oct 19, 2010 at 10:00 AM, jim wrote: > I am following an example. Also, doesn't that require the class name to be > something like models_members? > > Jim > > > On 10/19/2010 09:40 AM, chris h wrote: > > I'm having a problem including files using Zend Framework. I have in a >> controller file this >> >> > Jim why not use the Zend autoloader? > > > Chris. > > >
Re: [PHP] simple class & constructor
Can you paste the index page's code here? If the page is going blank there's probably an error (syntax, bad file path, etc). If you have access you can turn error reporting on so you can actually see the error - or better yet check the php error log file. Settings for both of these are in the php.ini file, though sometimes they can be overridden by apache directives (depending on the setup). http://php.net/manual/en/ini.core.php Chris. On Tue, Oct 19, 2010 at 4:12 PM, David McGlone wrote: > Hi everyone, > > I've been really good at googling to find my answers, but this time my > method isn't working for me. > > I have created a very simple class and a constructor hoping to get a > much better understanding of how to work with them. The code works, but > because it's very simple, I'm not sure that the way I'm trying to > access it is possible. > > All I'm trying to do is "access the class from outside the function". > (is that how to describe it?) > > For instance I have this simple code: > > class simpleConstructer { > > function __construct() { >echo "running the constructor"; > } > } > > $test=new simpleConstructer(); > > > Basically I want to learn how I can (if it's possible with this simple > code) is display the output on a different page. > > I tried putting the line: $test=new simpleConstructer(); on the index > page and including the page the class is on, but it causes the index > page to go blank. > > The thought of a session crossed my mind, but I'm pretty confident at my > level to know I don't need a session. > > Could someone point me in the right direction or give me some pointers, > advice? > > -- > Blessings > David M. > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >
Re: [PHP] simple class & constructor
Also wanted to point out that you can check the error reporting level and log file location (really all of the php's settings) by calling phpinfo(); in your code. Chris. On Tue, Oct 19, 2010 at 4:54 PM, chris h wrote: > > Can you paste the index page's code here? If the page is going blank > there's probably an error (syntax, bad file path, etc). If you have access > you can turn error reporting on so you can actually see the error - or > better yet check the php error log file. Settings for both of these are in > the php.ini file, though sometimes they can be overridden by apache > directives (depending on the setup). > > http://php.net/manual/en/ini.core.php > > > Chris. > > > On Tue, Oct 19, 2010 at 4:12 PM, David McGlone wrote: > >> Hi everyone, >> >> I've been really good at googling to find my answers, but this time my >> method isn't working for me. >> >> I have created a very simple class and a constructor hoping to get a >> much better understanding of how to work with them. The code works, but >> because it's very simple, I'm not sure that the way I'm trying to >> access it is possible. >> >> All I'm trying to do is "access the class from outside the function". >> (is that how to describe it?) >> >> For instance I have this simple code: >> >> class simpleConstructer { >> >> function __construct() { >>echo "running the constructor"; >> } >> } >> >> $test=new simpleConstructer(); >> >> >> Basically I want to learn how I can (if it's possible with this simple >> code) is display the output on a different page. >> >> I tried putting the line: $test=new simpleConstructer(); on the index >> page and including the page the class is on, but it causes the index >> page to go blank. >> >> The thought of a session crossed my mind, but I'm pretty confident at my >> level to know I don't need a session. >> >> Could someone point me in the right direction or give me some pointers, >> advice? >> >> -- >> Blessings >> David M. >> >> >> -- >> PHP General Mailing List (http://www.php.net/) >> To unsubscribe, visit: http://www.php.net/unsub.php >> >> >
Re: [PHP] "My truth comes out" [1]
settype looks like a no-go for this; per the php docs... http://php.net/manual/en/function.settype.php -- $bar = true; // boolean settype($bar, "string"); // $bar is now "1" (string) -- I think using a conditional here is the best (only?) way. $bool = (strtolower($string)=='true')? true: false; and if the default should be true... $bool = (strtolower($string)=='false')? false: true; If you you're going to use it a lot then wrap it in a function. Also, (as was stated) preg_ is overkill here. php has a lot of nifty string functions that should be taken advantage of before jumping onto regex. Chris. On Thu, Oct 21, 2010 at 6:01 AM, a...@ashleysheridan.co.uk < a...@ashleysheridan.co.uk> wrote: > That's as bad as an if! > > What about using settype() on the string? I've not tested it, but it looks > like it should do the trick. > > Thanks, > Ash > http://www.ashleysheridan.co.uk > > - Reply message - > From: "Russell Dias" > Date: Thu, Oct 21, 2010 10:51 > Subject: [PHP] "My truth comes out" [1] > To: > > preg_match("/false/i", $string) ? false : true; > > > > On Thu, Oct 21, 2010 at 7:39 PM, Gary wrote: > > Is there any nice way to convert a string containing either "TRUE" or > > "FALSE" to a bool with the appropriate value? I know I can just "if > > (strcmp..." but, as the song goes on to say "...ugly, so ugly, it's > ugly"[1] > > > > Footnotes: > > [1] "Mask", Henry Rollins > > > > -- > > Gary > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > >