The teacher asks for the Impossible

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Raptor Cardel
Forum Newbie
Posts: 7
Joined: Mon Jun 05, 2006 10:58 am

The teacher asks for the Impossible

Post by Raptor Cardel »

Howdy folk. I have a very humble request...

Im taking a computer sciences course here at school. The teacher gave us a crash course of PHP in 3 classes. Needless to say, this was hardly enough and Im stil left flying blind. He gave us a very, very hard assignment. We must code a calculator. Now, I know plenty are available on the net, However, not this kind. Every other calculator I find is usually a 2 box calculator you type the numbers in and select the operator, then push submt. This calculator must be like an actual calculator, with the numbers you push adding onto a big string of them and then you push the operator and then you push the second numbers and then equals. It must look like a real calculator. I have uploaded my code to a txt document on geocities, Which is linked http://www.geocities.com/raptor_aximili/phpcalc.txt

Just view source that, and that will be my entire PHP code.

Im lost >.< Please help!

Edit: PHP Code below aswell

Code: Select all

<HTML>
<HEAD>
	<TITLE>Calculatron 5000</TITLE>
<LINK
REL  = StyleSheet
HREF ="style.css"
Type ="text/css"
title ="Screen Style"
Media ="screen" >
</head>
<BODY>


<form Method="post" Action="caltest.php">
<input type="text" name="" size="20">
<br>
<br>
<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="7"
		name="number"
		class="mybuttons"> 7
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>

<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="8"
		name="number"
		class="mybuttons"> 8
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>


<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="9"
		name="number"
		class="mybuttons"> 9
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>

<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="/"
		name="number"
		class="mybuttons"> /
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>

<br>

<br>

<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="4"
		name="number"
		class="mybuttons"> 4
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>


<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="5"
		name="number"
		class="mybuttons"> 5
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>

<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="6"
		name="number"
		class="mybuttons"> 6
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>


<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="*"
		name="number"
		class="mybuttons"> *
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>




<br>

<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="1"
		name="number"
		class="mybuttons"> 1
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>


<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="2"
		name="number"
		class="mybuttons"> 2
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>

<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="3"
		name="number"
		class="mybuttons"> 3
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>
		
<FORM Method="post"
		action="<?php echo $_SERVER ['PHP_Self']; ?>">
		<button type="Submit"
		Value="-"
		name="number"
		class="mybuttons"> -
		</button>
		<input type="Hidden"
		name="curr_Num"
		Value="<?php echo $curr_num; ?> "?>





<br>
<input type="button" value="0"class="button-width">
<input type="button" value="C"class="button-width">
<input type="button" value="+"class="button-width">
<input type="button" value="="class="button-width">
Last edited by Raptor Cardel on Mon Jun 05, 2006 11:49 am, edited 1 time in total.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Just from the initial description of your project this sounds like an AJAX app. Pressing buttons and operators and having them display is really not going to happen without page submits, which would almost necessitate using a client side technology.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Javascript with PHP is an option as well, isn't it?
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Daedalus- wrote:Javascript with PHP is an option as well, isn't it?
So what's AJAX? :P
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I figured if it wasn't different, they wouldn't give it a different name.

EDIT: Asynchronous Javascript and XML, I thought
Last edited by daedalus__ on Mon Jun 05, 2006 11:53 am, edited 1 time in total.
Raptor Cardel
Forum Newbie
Posts: 7
Joined: Mon Jun 05, 2006 10:58 am

Post by Raptor Cardel »

I suppose it would be an option, the problem being he hasnt tought us Javascript. Only HTML and 3 lessons of PHP >.<
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

It is an option, but honestly, a simple calculator can be handled with JavaScript without touching PHP. Besides, if the desired effect is to push a series of numeric buttons that populate the calulcator 'bar' as they are being entered, that will not happen with PHP unless everytime you hit a button the page sends a new request to the server. That would be the slowest calculator around :!: .

AJAX all the way for something like this, in my opinion.
Last edited by RobertGonzalez on Mon Jun 05, 2006 11:56 am, edited 1 time in total.
User avatar
andym01480
Forum Contributor
Posts: 390
Joined: Wed Apr 19, 2006 5:01 pm

Post by andym01480 »

I'd use javascript to create the numbers and then make the operators form submits to act on the number.
Probably need session variables too to build the calculation!

Sounds like a challenge - by school do you mean university level (our American cousins have butchered the English language :lol:) or under 18? under 16?!!!
Last edited by andym01480 on Mon Jun 05, 2006 11:56 am, edited 1 time in total.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

I don't want to be rude but your instructor sounds like an idiot and you should inform him of this.

Is it possible you were placed in a more advanced class than you had intended or something because I see this task as being impossible for someone with only a basic knowledge of HTML and PHP. As you said before.

I would tell him that his request is unreasonable and refuse, talk to an administrator.

Then again, I was expelled several times from different schools and never graduated high school, so you may not want to listen to me lol

Another question, what class is this exactly?
Raptor Cardel
Forum Newbie
Posts: 7
Joined: Mon Jun 05, 2006 10:58 am

Post by Raptor Cardel »

Well, how about for curiosity sake we actually code it to submit with every button? We do have a dedicated server for this project...
Raptor Cardel
Forum Newbie
Posts: 7
Joined: Mon Jun 05, 2006 10:58 am

Post by Raptor Cardel »

Heres the shocker: Im 16 years old taking a computer sciences 20 class
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

Honestly Everah is right that it should be done purely in javascript.

Having it submit on every button press would be ugly and more complicated than the script needs to be, but you could do it that way.
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Post by daedalus__ »

You need to head to borders and read all day and all night. Just change chairs every half an hour or so and they will never notice, the place is like a library.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Raptor Cardel wrote:Well, how about for curiosity sake we actually code it to submit with every button? We do have a dedicated server for this project...
To do this you would have to have your code setup in such a way as to know the difference between a number and an operator and equals "=". I would probably keep track of what was submitted numerically until an operator was selected, then store what was in number into a session var along with the operator, then repeat the process for the second number, then when equals is hit, throw the whole equation together and valuate it. This is insanely slow, but doable.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Daedalus- wrote:You need to head to borders and read all day and all night. Just change chairs every half an hour or so and they will never notice, the place is like a library.
:lol:

I'm of the opinion that you should use AJAX. Not only does it make sense given your criteria. It will also impress :) (Maybe...)
Post Reply