Page 4 of 4
Posted: Mon Jun 05, 2006 6:43 pm
by RobertGonzalez
Pardon me, I think I seemed to have misplaced this topic. Has anyone seen where it went?
Seriously, this thread has been derailed a bit, wouldn't you all agree. The original poster asked how one would go about writing a PHP calculator for a shool project. He mentioned that he was given very little training in PHP and that this is pretty much his first experience with it.
I would agree that we should not be writing this code for him, regardless of our position on the decay of education in our countries or how we feel about what teachers are asking students to do. The OP asked a question, we all pitched in a little bit, threw out ideas and suggestions. Shouldn't we now let the student try some of the things we suggested and see if he can't come up with something on his own... the way it was intended for his project?
This is just a thought of mine. I don't mean to be a killjoy, party-pooping, fuddy-duddy.
Posted: Tue Jun 06, 2006 12:21 am
by AGISB
If I remember correctly when an assignment is made stating you have to use a php html solution you are stuck with php and html. So javascript is not an option.
So the solution sould be:
1. Assign the used numbers to a form linked to php self.
2. Store the numbers in a session array. Numbers stay in the uneven array indexes and operators in the even ones. Display it at the page
3. Once an operator is pressed the index is incremented.
4. check if the operator was = if so make the end calculation if not increment the index again
5. for the end calculation just check the operators and process them by mathematical standarts. */ > +-
6. Display the result.
Posted: Tue Jun 06, 2006 2:59 am
by timvw
Posted: Tue Jun 06, 2006 3:13 am
by onion2k
Everah wrote:I would agree that we should not be writing this code for him, regardless of our position on the decay of education in our countries or how we feel about what teachers are asking students to do.
Well, if he just takes one of the solutions from this thread and hands it in as his own work I imagine he'll fail. It's not like his teacher can't look at this forum.. All my university tutors would Google key phrases from our assignments as a simple plagarism check, and that was 6 years ago..
Posted: Tue Jun 06, 2006 3:50 am
by aerodromoi
onion2k wrote:
Well, if he just takes one of the solutions from this thread and hands it in as his own work I imagine he'll fail. It's not like his teacher can't look at this forum.. All my university tutors would Google key phrases from our assignments as a simple plagarism check, and that was 6 years ago..
That's up to him, I suppose. Right now I we've got two php-only approaches, one using eval and forms, the other a cumbersome switch statement and no forms. The third is an ajax version.
It's safe to say that there's scope for improvement for all of them (eg. error handling, input validation), which makes it raptor's call now. If he cooks up something based on the examples and puts some effort in it, I seriously doubt that his teacher will say anything.
aerodromoi
ps: Ok, might be a bit unrealistic for the ajax version

Posted: Tue Jun 06, 2006 3:52 am
by SpiderMonkey
OK, on the surface of it a calculator in php doesn't sound such a good idea, but I'm assuming that is half the assignment - figuring out that having it reload the page every button press is a Bad Thing.
Heres how I would do it (I'm guessing this might have already been suggested, I've not read the entire thread):
* A javascript function that updates a textbox which is your calculator display. A single function can do this, as long as the buttons pass themselves as a parameter using 'this'
* The '=' set up to submit the form. The page should target itself, so you stay in the calculator when you get a result
* The php code should parse anything it was passed then place the result in the same text box. Reverse polish notation might help for this.
Posted: Tue Jun 06, 2006 10:45 am
by Raptor Cardel
My appologies folk! Im only able to access to computer for this at the school, My home internet exploded, more ro less. Aeros code works near flawlessly, However it gives several errors until numbers are entered. This being said, Leave it to me to figure out. So I can say I have done some learning of some sort. Like I said, I wont submit this code like this however, since it is not mine. I will use it as a teaching tool so I can fully understand how it works.
You guys have been alot of help! Thank you so much
Posted: Wed Jun 07, 2006 2:35 pm
by benslayton
Ive just read the first post only. Too lazy to read the rest. But look at this.......
http://dynamicdrive.com/dynamicindex11/cal.htm
*View in IE
Posted: Wed Jun 07, 2006 2:51 pm
by aerodromoi
ehmmmmm
@raptor: What kind of errors?
aerodromoi
Posted: Wed Jun 07, 2006 3:58 pm
by ok
Works only on IE!!!
