I am a complete novice with php scrip but I am wiling to learn.
I am in need of some help, please.
Can anyone sort this code out for me so that it works correctly and
adjusts the price for the quantity selected on the front end.
__________________________________________________ _____________
if(article_get_field('type')== 'Croclight Candle'){
article_set_field('item_number', 'CRC');
article_set_field('price', 6.99);
}
elseif(article_get_field('type')== 'Spray') {
article_set_field('item_number', 'CRS');
article_set_field('size', '50ml');
article_set_field('price', 6.99);
}
elseif(article_get_field('size')== '15ml') {
article_set_field('item_number', 'CRS');
article_set_field('type', 'Spray');
article_set_field('price', 2.99);
}
elseif(article_get_field('type')== 'Roll-on') {
article_set_field('item_number', 'CRO');
article_set_field('size', '50ml');
article_set_field('price', 6.99);
}
__________________________________________________ ______________
Thanks in advance
Mark 30 6290
"Mark" <ma************@ntlworld.com> wrote in
news:11**********************@g49g2000cwa.googlegr oups.com: I am a complete novice with php scrip but I am wiling to learn. I am in need of some help, please.
Can anyone sort this code out for me so that it works correctly and adjusts the price for the quantity selected on the front end. __________________________________________________ _____________
if(article_get_field('type')== 'Croclight Candle'){ article_set_field('item_number', 'CRC'); article_set_field('price', 6.99); } elseif(article_get_field('type')== 'Spray') { article_set_field('item_number', 'CRS'); article_set_field('size', '50ml'); article_set_field('price', 6.99); } elseif(article_get_field('size')== '15ml') { article_set_field('item_number', 'CRS'); article_set_field('type', 'Spray'); article_set_field('price', 2.99); } elseif(article_get_field('type')== 'Roll-on') { article_set_field('item_number', 'CRO'); article_set_field('size', '50ml'); article_set_field('price', 6.99); }
First suggestion: Avoid elseif's if at all possible. Use the switch()
statement instead. <see http://www.php.net/switch>
switch (article_get_field('type')) {
case 'Croclight Candle':
article_set_field('item_number', 'CRC');
article_set_field('price', 6.99);
break;
case 'Spray':
article_set_field('item_number', 'CRS');
article_set_field('size', '50ml');
article_set_field('price', 6.99);
break;
case 'Roll-on':
article_set_field('item_number', 'CRO');
article_set_field('size', '50ml');
article_set_field('price', 6.99);
break;
}
if(article_get_field('size') == '15ml') {
article_set_field('item_number', 'CRS');
article_set_field('type', 'Spray');
article_set_field('price', 2.99);
}
Also, when posting code, try to use indentation so that the different
code blocks can be determined.
Ken
<comp.lang.php , Ken Robinson , se**********@rbnsn.com>
<1124745948.eba2d174dc98eac000e32e39523bcf98@teran ews>
<Mon, 22 Aug 2005 21:25:48 GMT> First suggestion: Avoid elseif's if at all possible. Use the switch() statement instead. <see http://www.php.net/switch>
switch (article_get_field('type')) {snip code}
Also, when posting code, try to use indentation so that the different code blocks can be determined.
That looked a nice bit of code and i've been meaning to learn about
switch() for ages , But i'm the opposite and most of the time I regard
indents as a curse .
if ($poo<>$poo)
{
php code
}
Each to their own .
-- www.phpguestbook.co.uk
PHPGB wrote: That looked a nice bit of code and i've been meaning to learn about switch() for ages , But i'm the opposite and most of the time I regard indents as a curse .
if ($poo<>$poo) { php code }
Each to their own .
You'll find that proper indentation is almost universal amongst
programmers. There's a very good reason for that, having to do with
being able to read, debug, and maintain large code sections.
I recommend strongly that you start doing the same. Many code editors
help you out these days through auto-indenting. Use spaces, not tabs,
especially for posting code to usenet.
Brian
<comp.lang.php , Default User , de***********@yahoo.com>
<3n*************@individual.net>
<23 Aug 2005 21:57:29 GMT> if ($poo<>$poo) { php code }
Each to their own .
You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections.
And if all the other programmers put their hand in the fire you would
want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not
what suits anybody else .
-- www.phpguestbook.co.uk
Fair enouph, just dont expect assistance from the community then.
PHPGB wrote: <comp.lang.php , Default User , de***********@yahoo.com> <3n*************@individual.net> <23 Aug 2005 21:57:29 GMT>
if ($poo<>$poo) { php code }
Each to their own .
You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections.
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not what suits anybody else .
PHPGB wrote: <comp.lang.php , Default User , de***********@yahoo.com> <3n*************@individual.net> <23 Aug 2005 21:57:29 GMT>
if ($poo<>$poo) { php code }
Each to their own .
You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections.
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not what suits anybody else .
Gee, if all the other programmers were doing it, there must be a reason!
After almost 40 years of programming, I've found indenting is VERY important.
And I second Ramon's opinion - don't expect help from the group - or any other
programmer. And don't expect to ever get a job programming.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
<comp.lang.php , Jerry Stuckle , js*******@attglobal.net>
<q5********************@comcast.com>
<Tue, 23 Aug 2005 20:23:49 -0500> And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not what suits anybody else .
Gee, if all the other programmers were doing it, there must be a reason!
After almost 40 years of programming, I've found indenting is VERY important. And I second Ramon's opinion - don't expect help from the group - or any other programmer.
Calm down lads .
'don't expect help from the group'
Do you realise what you have just said ? .
Professional programmers acting like foot stomping little children who
wont help a user because they use a different method than their own .
-- www.phpguestbook.co.uk
PHPGB wrote: <comp.lang.php , Default User , de***********@yahoo.com> <3n*************@individual.net> <23 Aug 2005 21:57:29 GMT>
if ($poo<>$poo) { php code }
Each to their own .
You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections.
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
Why would they? You seem to labor under the delusion that thousands of
professionals don't know what they are doing or would be malicious in
their advice. They do and they wouldn't be.
I've always been in the frame of mind its what suits the person and not what suits anybody else .
Why do you find it has any benefit?
More importantly, posting unindented code to the newsgroup will cause
at least some people to ignore you.
Brian
No, this has nothing to do with adolescent tantrums. The reason for the
hostile behavior, is because after being involved in the industry. There
is nothing quite like walking into a new and *exciting* job opportunity,
and then finding that you are responsible for maintaining the code of a
12 year old who was stuck inside a 45 year old's body. Or simply said
was too lazy to comment and indent.
And it takes you 10x the time to interpret what was written as there is
no documentation of any kind (if you are lucky you will get some PHPdoc
crap which isnt of much use either. Oh wait, its even better if you are
a team leader and you are in charge of integration 10 large scale
systems, into one cohesive one. While because 5 out of the 10 systems in
question were written by this same 12 year old.
Still wondering where the hostility stems from? Or did you get the drift?
PHPGB wrote: <comp.lang.php , Jerry Stuckle , js*******@attglobal.net> <q5********************@comcast.com> <Tue, 23 Aug 2005 20:23:49 -0500>
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not what suits anybody else .
Gee, if all the other programmers were doing it, there must be a reason!
After almost 40 years of programming, I've found indenting is VERY important. And I second Ramon's opinion - don't expect help from the group - or any other programmer.
Calm down lads .
'don't expect help from the group'
Do you realise what you have just said ? .
Professional programmers acting like foot stomping little children who wont help a user because they use a different method than their own .
<comp.lang.php , Default User , de***********@yahoo.com>
<3n*************@individual.net>
<24 Aug 2005 00:45:46 GMT> More importantly, posting unindented code to the newsgroup will cause at least some people to ignore you.
This is worse than the spanish inquisition :-)
-- www.phpguestbook.co.uk
<comp.lang.php , Ramon , dr*****@gmail.com>
<de***********@bunyip2.cc.uq.edu.au>
<Wed, 24 Aug 2005 10:52:46 +1000> Still wondering where the hostility stems from?
From people like yourself who appear unable or unwilling to accept other
peoples right to choose ? .
Is it safe to say you grant yourself these exact same rights without
even as much as a 2nd thought .
-- www.phpguestbook.co.uk
PHPGB wrote: <comp.lang.php , Default User , de***********@yahoo.com> <3n*************@individual.net> <24 Aug 2005 00:45:46 GMT>
More importantly, posting unindented code to the newsgroup will cause at least some people to ignore you.
This is worse than the spanish inquisition :-)
Look, it's up to you. Do what you want on your own, but people are
going to complain if you post unreadable code here and try to get help.
Brian
PHPGB wrote: <comp.lang.php , Ramon , dr*****@gmail.com> <de***********@bunyip2.cc.uq.edu.au> <Wed, 24 Aug 2005 10:52:46 +1000>
Still wondering where the hostility stems from?
From people like yourself who appear unable or unwilling to accept other peoples right to choose ? .
Is it safe to say you grant yourself these exact same rights without even as much as a 2nd thought .
Right to choose what? What kind of code they produce?!?
Here's an idea, develop something worth while and submit it to PEAR or
PECL. Without proper indentation and/or commenting, and the see how far
your peace of software gets.
Looks if you are working on a small project, and you are sole developer
thats fair enough, no one cares what you do in your own little cage. But
don't preach about choice, and how its a free country. Just because you
have the choice to do a bad job or a good job, does not mean that most
of us choose to do a bad one. In fact I'm proud of the work I do. There
no substitute for quality, and believe me when it comes to bargaining
about your paycheck, *choice* is of little matter to an employer/client,
while quality is everything in this business.
Cheers,
D
PHPGB wrote: <comp.lang.php , Ramon , dr*****@gmail.com> <de***********@bunyip2.cc.uq.edu.au> <Wed, 24 Aug 2005 10:52:46 +1000>
Still wondering where the hostility stems from?
From people like yourself who appear unable or unwilling to accept other peoples right to choose ? .
Is it safe to say you grant yourself these exact same rights without even as much as a 2nd thought .
Life's too short to deal with idiots. Seriously.
So, *plonk* and all that.
Brian
<comp.lang.php , Ramon , dr*****@gmail.com>
<de**********@bunyip2.cc.uq.edu.au>
<Wed, 24 Aug 2005 11:16:15 +1000> Here's an idea, develop something worth while and submit it to PEAR or PECL. Without proper indentation and/or commenting, and the see how far your peace of software gets.
Arnt you just assuming everybody has the same ambitions as yourself .
Looks if you are working on a small project, and you are sole developer thats fair enough, no one cares what you do in your own little cage. But don't preach about choice, and how its a free country. Just because you have the choice to do a bad job or a good job, does not mean that most of us choose to do a bad one. In fact I'm proud of the work I do. There no substitute for quality, and believe me when it comes to bargaining about your paycheck, *choice* is of little matter to an employer/client, while quality is everything in this business.
'no one cares what you do in your own little cage'
Thank you & I never said otherwise .
<stother martin in southern drawl>
what we have here is a failure to communicate
</stother martin in southern drawl>
-- www.phpguestbook.co.uk
<comp.lang.php , Default User , de***********@yahoo.com>
<3n*************@individual.net>
<24 Aug 2005 01:05:53 GMT> More importantly, posting unindented code to the newsgroup will cause at least some people to ignore you.
This is worse than the spanish inquisition :-)
Look, it's up to you. Do what you want on your own, but people are going to complain if you post unreadable code here and try to get help.
Professional programmers cant read code unless its staunchly written to
exact specifications in the format they are used too - gee whizz the
things you learn on usenet :-)
-- www.phpguestbook.co.uk
Ok, look. I've tried my best to try to understand your point of view I
am unable to do so. We appear to be talking about different things. You
are talking about some kind of democratic *mambo jumbo* & *choice* & *I
am entitled to it*. While what most of us are talking about is *proper
software engineering practices*. Yes, you can do what you like. Fine.
You made your point you are entitled to *choice*. Just dont expect me to
assist you with a complex problem. It's like saying, I can drive on the
opposite side of the road, simply because its physicly feasible to do
so. Do you not understand how laughable your argument is?
And ok, the world was believed to be flat, and some guy said, It's not
and got killed for it. But do you not understand that the programmers of
the world are not going to wake up one day and say: *OH GOD!* "I've been
indenting correctly all this time. How silly of me."
Oh yeah, what is the most amusing part of your argument, is that you are
posting in a *OPEN SOURCE* programming language user group.
Where *OPEN SOURCE* refers to different people *reusing* each others
code with *ease*.
Anyway, I'm out of this argument, I'm sure most of my words are going to
be answered with some quote which you hear on a Friday Pub Crawl.
Cheers, and have a great day.
D
PHPGB wrote: <comp.lang.php , Ramon , dr*****@gmail.com> <de**********@bunyip2.cc.uq.edu.au> <Wed, 24 Aug 2005 11:16:15 +1000>
Here's an idea, develop something worth while and submit it to PEAR or PECL. Without proper indentation and/or commenting, and the see how far your peace of software gets.
Arnt you just assuming everybody has the same ambitions as yourself .
Looks if you are working on a small project, and you are sole developer thats fair enough, no one cares what you do in your own little cage. But don't preach about choice, and how its a free country. Just because you have the choice to do a bad job or a good job, does not mean that most of us choose to do a bad one. In fact I'm proud of the work I do. There no substitute for quality, and believe me when it comes to bargaining about your paycheck, *choice* is of little matter to an employer/client, while quality is everything in this business.
'no one cares what you do in your own little cage'
Thank you & I never said otherwise .
<stother martin in southern drawl> what we have here is a failure to communicate </stother martin in southern drawl>
PHPGB wrote: You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections. And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
There's a huge difference here. Putting your hand in the fire is a
stupid thing to do. Indenting, OTOH, is not.
Here's another example. *Most* people stop at stop lights. And yes I
expect you to do likewise!
I've always been in the frame of mind its what suits the person and not what suits anybody else .
Fine, if the code you write will only be maintained by you.
--
I always wanted to be a procrastinator but never got around to it
....me again... P.S.: You are not consequent with the spaces before punctuation characters.
Oops, sorry. You *are* consequent with it... (but IMHO it looks ugly).
Greetings,
Hero
Hello! if ($poo<>$poo) { php code }
Each to their own .
You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections.
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
He mentioned the reasons of proper indentation:
- makes the code more easy readable and debuggable
(as the programmer crawls through it while debugging)
- makes large code section more easy to maintain
(because the code is also visibly structured)
Furthermore (already mentioned in another post) you are writing a free
software with a free programming language and the former is perhaps
intended to be distributed also among other developers (in the future).
These developers expect to find code that meets at least very basic
standards; proper indentation is one of these standards.
It is the same with communicating in real life. You adhere certain
conventions while communicating verbally, for example pronounciation and
breaks. Talking very fastly and without any pauses would only confuse
the most people and after a while they probably would refuse to "talk"
with you anymore (after clarifying their problems with your way of
communicating, that's what we currently do in this sub-thread).
You see the paralleles?
Coding conventions should not be adhered to because many programmer do
but because they are quite useful to communicate information to other
programmers.
Greetings,
Hero
P.S.: You are not consequent with the spaces before punctuation
characters. In many languages (french is an exception) any space before
such a character is "improper". Furthermore this may lead to weird
breaks with the punctuation character as the first character in the new
line.
PHPGB schrieb: Professional programmers cant read code unless its staunchly written to exact specifications in the format they are used too - gee whizz the things you learn on usenet :-)
Look, you seem to have lost the point. It's not about how you write your
code. It's about how to improve your chances of getting a decent
response when posting your code in a newsgroup.
If you put the code in there with absolutely no indentaion, then about
80 percent of the really experienced programmers won't even bother
reading it. Why should they invest the time? "Ah no! Can't even read it.
Not even indented. Must be a terribly stupid programmer with a terribly
stupid problem => Get coffee, continue coding!"
There are tools automating the process of indenting code. If you don't
want to indent YOUR code, that's fine. But properly formatted code is a
key to succesful discussions.
AllOLLi
PHPGB wrote: <comp.lang.php , Jerry Stuckle , js*******@attglobal.net> <q5********************@comcast.com> <Tue, 23 Aug 2005 20:23:49 -0500>
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not what suits anybody else .
Gee, if all the other programmers were doing it, there must be a reason!
After almost 40 years of programming, I've found indenting is VERY important. And I second Ramon's opinion - don't expect help from the group - or any other programmer.
Calm down lads .
'don't expect help from the group'
Do you realise what you have just said ? .
Professional programmers acting like foot stomping little children who wont help a user because they use a different method than their own .
Nope. I'm not going to waste my time looking through code someone is too lazy
or stubborn to do even minimal formatting.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
PHPGB wrote: <comp.lang.php , Ramon , dr*****@gmail.com> <de***********@bunyip2.cc.uq.edu.au> <Wed, 24 Aug 2005 10:52:46 +1000>
Still wondering where the hostility stems from?
From people like yourself who appear unable or unwilling to accept other peoples right to choose ? .
Is it safe to say you grant yourself these exact same rights without even as much as a 2nd thought .
And I also have the right to choose whether to look thought the crappy mess or
not. And I choose not to.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
<comp.lang.php , Oliver Grätz , ol***********@gmx.de>
<43***********************@newsread4.arcor-online.net>
<Wed, 24 Aug 2005 05:16:02 +0200> Professional programmers cant read code unless its staunchly written to exact specifications in the format they are used too - gee whizz the things you learn on usenet :-) Look, you seem to have lost the point. It's not about how you write your code. It's about how to improve your chances of getting a decent response when posting your code in a newsgroup.
Nobody is forcing anybody to do anything against their will .
Who would have thought a harmless snippet (without indents) could
provoke such aggression almost to the state of religious fever :-)
-- www.phpguestbook.co.uk
<comp.lang.php , Jerry Stuckle , js*******@attglobal.net>
<RI********************@comcast.com>
<Tue, 23 Aug 2005 23:25:31 -0500> I'm not going to waste my time looking through code someone is too lazy or stubborn to do even minimal formatting.
Isnt it interesting how people are taking away something that hasnt
actually been given .
-- www.phpguestbook.co.uk
<comp.lang.php , Jerry Stuckle , js*******@attglobal.net>
<RI********************@comcast.com>
<Tue, 23 Aug 2005 23:26:27 -0500> And I also have the right to choose whether to look thought the crappy mess or not. And I choose not to.
No worries .
-- www.phpguestbook.co.uk
Mark wrote: I am a complete novice with php scrip but I am wiling to learn. I am in need of some help, please.
You don't have a code issue you have a data manipulation issue. You are
trying to hard-code some logic based on data values. This is best handled
by separating the code from the data. Can anyone sort this code out for me so that it works correctly and adjusts the price for the quantity selected on the front end.
Probably not. Instead i can offer the following re-write:
$info = array(
"croclight"=> array(
"item_number"=>'CRC',
"price"=>6.99),
"spray"=> array(
"item_number"=>"CRS",
"size"=>"50ml",
"price=6.99")
...etc..)
then your code looks like:
$item_info = $info($item_name);
and so forth.
All of the informatin in that associative array should come from database
tables.
hope this helps.
__________________________________________________ _____________
if(article_get_field('type')== 'Croclight Candle'){ article_set_field('item_number', 'CRC'); article_set_field('price', 6.99); } elseif(article_get_field('type')== 'Spray') { article_set_field('item_number', 'CRS'); article_set_field('size', '50ml'); article_set_field('price', 6.99); } elseif(article_get_field('size')== '15ml') { article_set_field('item_number', 'CRS'); article_set_field('type', 'Spray'); article_set_field('price', 2.99); } elseif(article_get_field('type')== 'Roll-on') { article_set_field('item_number', 'CRO'); article_set_field('size', '50ml'); article_set_field('price', 6.99); } __________________________________________________ ______________
Thanks in advance
Mark
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
PHPGB wrote: <comp.lang.php , Default User , de***********@yahoo.com> <3n*************@individual.net> <23 Aug 2005 21:57:29 GMT>
> if ($poo<>$poo) > { > php code > } > > Each to their own .
You'll find that proper indentation is almost universal amongst programmers. There's a very good reason for that, having to do with being able to read, debug, and maintain large code sections.
And if all the other programmers put their hand in the fire you would want me to do the same would you ? :-)
I've always been in the frame of mind its what suits the person and not what suits anybody else .
If you become successful you will change your mind because of the ridicule
and abuse you have to sustain from friends and coworkers.
OTOH, with that attitude your success is not much assured.
--
Kenneth Downs
Secure Data Software, Inc.
(Ken)nneth@(Sec)ure(Dat)a(.com)
PHPGB wrote: <comp.lang.php , Oliver Grätz , ol***********@gmx.de> <43***********************@newsread4.arcor-online.net> <Wed, 24 Aug 2005 05:16:02 +0200>
Professional programmers cant read code unless its staunchly written to exact specifications in the format they are used too - gee whizz the things you learn on usenet :-)
Look, you seem to have lost the point. It's not about how you write your code. It's about how to improve your chances of getting a decent response when posting your code in a newsgroup.
Nobody is forcing anybody to do anything against their will .
Who would have thought a harmless snippet (without indents) could provoke such aggression almost to the state of religious fever :-)
It wasn't your "harmless snippet". It was your statement:
"... But i'm the opposite and most of the time I regard
indents as a curse ."
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp. js*******@attglobal.net
==================
<comp.lang.php , Jerry Stuckle , js*******@attglobal.net>
<lb********************@comcast.com>
<Wed, 24 Aug 2005 07:47:56 -0500> Nobody is forcing anybody to do anything against their will .
Who would have thought a harmless snippet (without indents) could provoke such aggression almost to the state of religious fever :-)
It wasn't your "harmless snippet". It was your statement:
"... But i'm the opposite and most of the time I regard indents as a curse ."
I spoke the forbidden words in the ancient scrolls out loud and look
what happens .
-- www.phpguestbook.co.uk This discussion thread is closed Replies have been disabled for this discussion. Similar topics
2 posts
views
Thread by David |
last post: by
|
4 posts
views
Thread by Thomas Jerkins |
last post: by
|
35 posts
views
Thread by Thomas Matthews |
last post: by
|
1 post
views
Thread by mirandacascade |
last post: by
|
7 posts
views
Thread by mark |
last post: by
|
6 posts
views
Thread by Arjen |
last post: by
|
10 posts
views
Thread by John Smith |
last post: by
|
13 posts
views
Thread by eman1000 |
last post: by
|
18 posts
views
Thread by dspfun |
last post: by
| | | | | | | | | | | |