Re: [PHP] calculate a varchar
2007. 12. 3, hétfő keltezéssel 15.00-kor Andrew Ballard ezt írta: > On Dec 3, 2007 10:56 AM, John Taylor-Johnston > <[EMAIL PROTECTED]> wrote: > > Is there a calculation function? > > > > I'm using an e-commerce shopping cart. I want to tweak the code. The > > author is using a varchar(100) field to store prices. > > > > Taking advantage of there being a varchar, instead of entering a price, > > I would like to enter a calculation. > > > > (24*2.2)+(24*2.2*.1) 24 is my unit price in British pounds. 2.2 is the > > exchange rate into Canadian dollars. etc. > > > > The exchange rate changes frequently. Instead of recalculating and > > entering a new price every few days, it would be useful to enter a > > calculation in any price field. > > > > I had a look at: http://ca3.php.net/manual-lookup.php?pattern=calc > > http://ca3.php.net/manual-lookup.php?pattern=calculate > > http://ca3.php.net/manual-lookup.php?pattern=calculation > > but I see no function, although I'm sure there is one. > > > > So how could I do this? > > > > $price = (24*2.2)+(24*2.2*.1); > > > > if $price is not an integer, verify if it is a calculation. If so, give > > me an integer and round it off to two decimal points: > > > > $price = 58.08; > > > > Do-able? > > > > John > > > > John, > > Technically, yes you can do it. eval() will work, as Richard > mentioned. However, your question involves two things that I prefer to > avoid at all costs. The first is storing numeric data in a varchar > field. I'm not sure why the author chose this approach. A varchar(100) > is reserving storage space for 100 characters. I doubt you're selling > any items that require that number of digits, so it's wasted space. > (It also makes queries like this "SELECT * FROM `items` WHERE `price` > > 100" problematic because the comparison is being done > alphanumerically rather than just numerically.) Price is a number, > regardless of the units -- even cats or canaries -- and is nearly > always handled better as such. AFAIK the varchar(100) fields do not reserve the space in advance. these fields occupy space according to the length of the data stored in them. hence their name 'var' > The second item I like to avoid is anything like that evalutates a > string of text as code like eval(), because you have to handle a wide > range of potential errors in the string being evaluated as well as the > potential security risk. > > If you're just wanting to convert prices from one currency to another, > isn't the formula the same regardless of the currency? Could you not > store all your prices numerically in a single currency and then > convert the price to any other currency by passing the stored price > and the exchange rate into a function? > > function exchangeCurrency($amount, $exchange_rate) { > return $amount * $exchange_rate; > } > > however I agree 100% with you in your conclusions ;) greets Zoltán Németh > > Andrew > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] forget about this.
julian wrote: however this will work... p1.inc 1 var;; 9} 10 } 11 12 class obj { 13var $obj2=20; 14 15function f1(){ 16 global $db; 17 18 echo "\n".$db->fun2()*$this->obj2."\n"; 19} 20 } 21 ?> 1 #!/usr/bin/php -q 2 3 f1(); 13 14 ?> -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Banned from #php
On Dec 4, 2007 10:21 AM, tedd <[EMAIL PROTECTED]> wrote: > I always like to see (have an example) of how it's done, but then I > rewrite everything to fit with my view of the world. No wonder your code looks crooked. ;-P -- Daniel P. Brown [office] (570-) 587-7080 Ext. 272 [mobile] (570-) 766-8107 If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Banned from #php
At 1:09 PM -0800 12/3/07, Stephen Johnson wrote: Part of this job is learning how to learn, and so many times people just want you to write the code for them. That works for me, but I seldom use their code. I always like to see (have an example) of how it's done, but then I rewrite everything to fit with my view of the world. Cheers, tedd -- --- http://sperling.com http://ancientstones.com http://earthstones.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Banned from #php
That works for me, but I seldom use their code. I always like to see (have an example) of how it's done, but then I rewrite everything to fit with my view of the world. I seldom like other people's coding style. Most programmers seem to like their code tight and I like mine fluffy. -- Michael McGlothlin Southwest Plumbing Supply -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] References to a variable and scope
Hello, I know that PHP doesn't support pointers to a variable, instead of that there is references to a variable which are similar to pointers, right? BTW, what I want to do is to save a references to a variable and read the content when I need, similar to PDO "bindParam". I will try to explain better in the following pseudo php code. function foo($a) { $GLOBALS['references']['a'] = /*references to $a */ } function bar() { echo $GLOBALS['references']['a']; } $var="hello" foo($var); $var = "hi"; bar(); /* it should print "hi" instead of "hello" */ -- Best Regards Cesar D. Rodas www.cesarodas.com www.thyphp.com www.phpajax.org Phone: +595-961-974165
Re: [PHP] Calendar
On Monday 03 December 2007 13:37:45 Emil Edeholt wrote: > Hi, > was this a mathematical question? Yes, someone on this list, can probably help you to do some finesse, but I like it mathematical and clean code > I'm about to add some simple calendar functions to my application, and > I'm thinking of how I should implement recurring events. Are there one > standard way most people use that works well? a timestamp > I guess you have some kind > of emitter event that creates the recurring events and a group id that > holds the events together. a timestamp + a year ahead as an example, a week, a day, a week + two days, it's all very simple to add up with php. > How long forward does one usually create the > events. Two-three years...? chaa... What event except birthdays weddings and maby elections are we talking about here? I cannot tell what I'm supposed to do next week and it seems kind'a hard to grasp at what youre thinkin of > > Sorry if I'm a bit blury. But any ideas on recurring events are welcome. > I guess I could just hack something together, but it would be fun to do > it right. wee bit blurry. > > Regards Emil -- --- Børge Holen http://www.arivene.net -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] References to a variable and scope
On Tue, 2007-12-04 at 16:58 -0400, Cesar D. Rodas wrote: > Hello, > > I know that PHP doesn't support pointers to a variable, instead of that > there is references to a variable which are similar to pointers, right? > > BTW, what I want to do is to save a references to a variable and read the > content when I need, similar to PDO "bindParam". I will try to explain > better in the following pseudo php code. > > function foo($a) { >$GLOBALS['references']['a'] = /*references to $a */ > } > > function bar() { > echo $GLOBALS['references']['a']; > } > > $var="hello" > foo($var); > $var = "hi"; > bar(); /* it should print "hi" instead of "hello" */ Your code is broken: Cheers, Rob. -- ... SwarmBuy.com - http://www.swarmbuy.com Leveraging the buying power of the masses! ... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] References to a variable and scope
On 04/12/2007, Cesar D. Rodas <[EMAIL PROTECTED]> wrote: > > Robert, > > On 04/12/2007, Robert Cummings <[EMAIL PROTECTED]> wrote: > > > > On Tue, 2007-12-04 at 16:58 -0400, Cesar D. Rodas wrote: > > > Hello, > > > > > > I know that PHP doesn't support pointers to a variable, instead of > > that > > > there is references to a variable which are similar to pointers, > > right? > > > > > > BTW, what I want to do is to save a references to a variable and read > > the > > > content when I need, similar to PDO "bindParam". I will try to explain > > > better in the following pseudo php code. > > > > > > function foo($a) { > > >$GLOBALS['references']['a'] = /*references to $a */ > > > } > > > > > > function bar() { > > > echo $GLOBALS['references']['a']; > > > } > > > > > > $var="hello" > > > foo($var); > > > $var = "hi"; > > > bar(); /* it should print "hi" instead of "hello" */ > > > > Your code is broken: > > > I knew that, that was a pseudo code. I've try something similar but > doesn't work. > > > > > function foo( &$a ) > > { > > $GLOBALS['references']['a'] = &$a; /*references to $a */ > > } > > > > function bar() > > { > > echo $GLOBALS['references']['a']; > > } > > > > $var="hello" > > foo($var); > > $var = "hi"; > > bar(); /* it should print "hi" instead of "hello" */ > > > > ?> > > > > Cheers, > > Rob. > > -- > > ... > > SwarmBuy.com - http://www.swarmbuy.com > > > > Leveraging the buying power of the masses! > > ... > > > > > What you code is working, I am so happy for that... the references of a > reference works, > thank you! :-) > > -- > Best Regards > > Cesar D. Rodas > http://www.cesarodas.com > http://www.thyphp.com > http://www.phpajax.org > Phone: +595-961-974165 -- Best Regards Cesar D. Rodas http://www.cesarodas.com http://www.thyphp.com http://www.phpajax.org Phone: +595-961-974165
Re: [PHP] howto get .tar.gz content's filenames
Call exec is not good, because you are executing other program, instead of that you should use some PHP program, take a look here http://www.phpclasses.org/search.html?words=tar&x=0&y=0&go_search=1 On 04/12/2007, Daniel Brown < [EMAIL PROTECTED]> wrote: > > On Dec 3, 2007 10:05 PM, Shelley Shyan < [EMAIL PROTECTED]> > wrote: > > Hi all, > > > > It may not be a php question, but I want to get the filename lists that > a .tar.gz file contains and give it to an array. > > How can I manage that? > > > > Thank you very much for your consideration. > > > > Regards, > > Shelley > > > > > > -- > > PHP General Mailing List (http://www.php.net/) > > To unsubscribe, visit: http://www.php.net/unsub.php > > > > If you're on Linux/BSD/Unix/MacOS or Cygwin on Windows, this should > work: > > $tar_gz_file = " filename.tar.gz"; // Replace this with the actual > filename. > exec('tar -ztf '.$tar_gz_file,$ret); > print_r($ret); > ?> > > > -- > Daniel P. Brown > [office] (570-) 587-7080 Ext. 272 > [mobile] (570-) 766-8107 > > If at first you don't succeed, stick to what you know best so that you > can make enough money to pay someone else to do it for you. > > -- > PHP General Mailing List (http://www.php.net/ ) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Best Regards Cesar D. Rodas www.cesarodas.com www.thyphp.com www.phpajax.org Phone: +595-961-974165 -- Best Regards Cesar D. Rodas http://www.cesarodas.com http://www.thyphp.com http://www.phpajax.org Phone: +595-961-974165
Re: [PHP] Calendar
On Dec 3, 2007 7:37 AM, Emil Edeholt <[EMAIL PROTECTED]> wrote: > Hi, > > I'm about to add some simple calendar functions to my application, and > I'm thinking of how I should implement recurring events. Are there one > standard way most people use that works well? I guess you have some kind > of emitter event that creates the recurring events and a group id that > holds the events together. How long forward does one usually create the > events. Two-three years...? > > Sorry if I'm a bit blury. But any ideas on recurring events are welcome. > I guess I could just hack something together, but it would be fun to do > it right. > > Regards Emil > Emil, There is not much "simple" about a calendar, especially when you start dealing with recurring events. How far into the future your calendar allow events to recur will depend at least in part on how you intend to store them. For instance, you can store them in a database where you create a separate event row for each occurrence (though still be linked by a common ID as you said), but you'll probably set your limits based on storage to prevent adding a daily event for the next 10 years. You could also store a single event record that includes the rules for recurrence and then calculate the dates of each instance as needed, but that could get pretty CPU intensive. (I'm assuming you want to stick with "simple" periodic recursion, not more complex things like the date for Easter or events that don't have any set pattern.) Your decision will also be affected by whether you want to be able to modify a specific instance of a recurring event -- say to move your monthly meeting from 1:00 to 2:30 for next month only or to cancel your weekly card game 3 weeks from now without altering other instances of the same events -- will impact how you approach your design. And none of this takes into account the fun you get if you have to deal with multiple time zones and/or daylight saving time. For instance, if you store events in local time, you have to store the time zone with the record so you can convert from one time zone to another. If you store events in UTC, you usually have to account for shifts in daylight saving time so that your weekly 2:00 staff meetings don't suddenly change to 1:00. Then there are the occasional changes to the beginning/ending dates for DST like happened this year for the US. I know this probably muddies your original question even further, but I'll say again -- there is not much "simple" when it comes to calendars. Andrew -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] // ?>
Here's some unexpected behavior: what? ?> This will output "what?" - I expected no output, as is the case if the inline comment was a /* */ comment. Is this a bug? Kevin -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] // ?>
On 04/12/2007, Kevin Schmeichel <[EMAIL PROTECTED]> wrote: > > Here's some unexpected behavior: > > // ?> what? > ?> > > This will output "what?" - I expected no output, as is the case if the > inline comment was a /* */ comment. Is this a bug? That is because the PHP parser stops the comment on the end of a php tag ("?>") or new line, that is not a bug. Kevin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- Best Regards Cesar D. Rodas http://www.cesarodas.com http://www.thyphp.com http://www.phpajax.org Phone: +595-961-974165
Re: [PHP] // ?>
On Dec 4, 2007 8:41 PM, Kevin Schmeichel <[EMAIL PROTECTED]> wrote: > Here's some unexpected behavior: > > // ?> what? > ?> > > This will output "what?" - I expected no output, as is the case if the > inline comment was a /* */ comment. Is this a bug? > > Kevin > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > No, that is expected behavior. Try this: This will display versus this: This will be hidden */ ?> Comments with //double-slashes and #hashmarks terminate when the code container terminates, because the ending ?> indicates that it's time for the parser to stop interpreting code. However, /*slash-starred comments do not terminate, as the parser expects a closing comment tag*/. For all intents and purposes, you could consider the /* as a sleeping pill, and the */ as the alarm clock. ANYTHING that happens between those will have no attention paid to it by PHP. -- Daniel P. Brown [Phone Numbers Go Here!] [They're Hidden From View!] If at first you don't succeed, stick to what you know best so that you can make enough money to pay someone else to do it for you. -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] // ?>
2007/12/4, Kevin Schmeichel <[EMAIL PROTECTED]>: > > Here's some unexpected behavior: > > // ?> what? > ?> > > This will output "what?" - I expected no output, as is the case if the > inline comment was a /* */ comment. Is this a bug? > Expected behavior. Read the manual: http://php.net/manual/en/language.basic-syntax.comments.php
Re: [PHP] howto get .tar.gz content's filenames
Cesar D. Rodas wrote: > Call exec is not good, because you are executing other program, > instead of that you should use some PHP program, take a look here > > http://www.phpclasses.org/search.html?words=tar&x=0&y=0&go_search=1 > "The access to the internal site search engine is restricted to premium users." /Per Jessen, Zürich -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php