Code Newbie
News     Forums     Search     Members     Sign Up    

My Code Newbie
Username

Password

Articles/Snippets
ASP Classic
ASP.NET
C
C#
C++
HTML / CSS
Java
Javascript
Linux / BSD
Perl
PHP
Python
Ruby
SQL
VB 6
VB.NET

C.N. Friends
  Planet Rome

Link to Us!
Code Newbie
  Code Newbie
    forums
Old 06-06-2004, 12:25 PM   #1 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
need help with first php project

hi there i have been trying to figure out how or if i can complete my first php project.

here is where you can find the current script:
http://216.55.207.148/~sarah/submissionform.php.txt

what i would like to be able to do is to automatically calculate subtotal for shipping, insurance, and service charges for each of the services and then have a grand total calculated as well.

if you want to understand more how each of the calculation are done and what the terminologies mean you can read about them here:
http://www.comicgradinggroup.com/submissionform.pdf

and
http://www.comicgradinggroup.com/cggroupservices.htm

the latter page should give you a very good idea why i need the subtotals (it all has to do with turnaround times and there fore potentially many packages to return at different times.

i have been stuck for a long time now and it is frustrating.

oh yeah i know the code isn't pretty but i really have just started with php.
sarah31 is offline   Reply With Quote
Old 06-07-2004, 07:24 AM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
hi sarah,

can you explain what part you are stuck on? also any errors or what it is or isn't doing would help too.
__________________
Mike
sde is offline   Reply With Quote
Old 06-07-2004, 08:05 AM   #3 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
in the code you can see that there are a few service the user can choose from the drop down menu and if you look at the link to the service page i posted you will see that each service has a different turnaround time. so if a person is filling out the form and say has thirteen books that are eligible for the moder age service and 6 that fall under tha classic service. due to return (turnaround times) the six classic books would be shipped back seven days before the 13 modern age ones. so what i need the automatic calculations to do are out put the information in this format:

Modern Age:
# of books: --
service total $: --.--
return shipping : --.--
insurance: --.--

Standard:....

and so forth through the various servcices then have a grand total at the bottom (shipping insurance and grand total).


so basically i need the data pulled out of the chart and calculated accordingly. i am stuck on pulling the data out and performing the needed calculations on it.

as for errors. there are none with the current script. if i set up arrays or if conditional and for loops the calculations are not done correctly i either get zero or the limit value from the for loop. all of the calculations that are there in the script are exactly how they should be applied to each service break down.

hth
sarah31 is offline   Reply With Quote
Old 06-07-2004, 08:48 AM   #4 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
all i can think of is to put another set of code after line 112 to create an array based on services. you can build the array for each iteration of the loop you are currently in.

for example, something like this:
PHP Code:
<?
if($_POST['service'.$i]=="None"){
        
$Service['None'][$i]['q'] = $_POST['q'.$i];
        
$Service['None'][$i]['pub'] = $_POST['pub'.$i];
        
$Service['None'][$i]['title'] = $_POST['title'.$i];
        
$Service['None'][$i]['iss'] = $_POST['iss'.$i];
        
$Service['None'][$i]['date'] = $_POST['date'.$i];
        
$Service['None'][$i]['fvm'] = $_POST['fmv'.$i];
      }elseif(
$_POST['service'.$i]=="Modern Age"){
        
$Service['Modern Age'][$i]['q'] = $_POST['q'.$i];
        
$Service['Modern Age'][$i]['pub'] = $_POST['pub'.$i];
        
$Service['Modern Age'][$i]['title'] = $_POST['title'.$i];
        
$Service['Modern Age'][$i]['iss'] = $_POST['iss'.$i];
        
$Service['Modern Age'][$i]['date'] = $_POST['date'.$i];
        
$Service['Modern Age'][$i]['fvm'] = $_POST['fmv'.$i];
      }elseif(
$_POST['service'.$i]=="Classic"){
        
$Service['Classic'][$i]['q'] = $_POST['q'.$i];
        
$Service['Classic'][$i]['pub'] = $_POST['pub'.$i];
        
$Service['Classic'][$i]['title'] = $_POST['title'.$i];
        
$Service['Classic'][$i]['iss'] = $_POST['iss'.$i];
        
$Service['Classic'][$i]['date'] = $_POST['date'.$i];
        
$Service['Classic'][$i]['fvm'] = $_POST['fmv'.$i];
      }elseif(
$_POST['service'.$i]=="Next Day"){
        
$Service['Next Day'][$i]['q'] = $_POST['q'.$i];
        
$Service['Next Day'][$i]['pub'] = $_POST['pub'.$i];
        
$Service['Next Day'][$i]['title'] = $_POST['title'.$i];
        
$Service['Next Day'][$i]['iss'] = $_POST['iss'.$i];
        
$Service['Next Day'][$i]['date'] = $_POST['date'.$i];
        
$Service['Next Day'][$i]['fvm'] = $_POST['fmv'.$i];
      }elseif(
$_POST['service'.$i]=="Re-Certify"){
        
$Service['Re-Certify'][$i]['q'] = $_POST['q'.$i];
        
$Service['Re-Certify'][$i]['pub'] = $_POST['pub'.$i];
        
$Service['Re-Certify'][$i]['title'] = $_POST['title'.$i];
        
$Service['Re-Certify'][$i]['iss'] = $_POST['iss'.$i];
        
$Service['Re-Certify'][$i]['date'] = $_POST['date'.$i];
        
$Service['Re-Certify'][$i]['fvm'] = $_POST['fmv'.$i];
      }elseif(
$_POST['service'.$i]=="PreScreen"){
        
$Service['PreScreen'][$i]['q'] = $_POST['q'.$i];
        
$Service['PreScreen'][$i]['pub'] = $_POST['pub'.$i];
        
$Service['PreScreen'][$i]['title'] = $_POST['title'.$i];
        
$Service['PreScreen'][$i]['iss'] = $_POST['iss'.$i];
        
$Service['PreScreen'][$i]['date'] = $_POST['date'.$i];
        
$Service['PreScreen'][$i]['fvm'] = $_POST['fmv'.$i];
      }
?>
you would then have to do a foreach loop a the bottom of the script to go through that service array.
__________________
Mike
sde is offline   Reply With Quote
Old 06-07-2004, 09:29 AM   #5 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
thanks i will work on this. after my trials and erros i was beginning to think that i might have to create a much larger form (ie to handle each service separately) on order to handle the calculations more cleanly. (after all it would be easier to pull the data from the completed calculations than trying to pull data from the current script's chart)
sarah31 is offline   Reply With Quote
Old 06-08-2004, 03:56 PM   #6 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
sde,

i was wondering if you could give me a short example of the foreach loop would be used for doing the calculations? i want to be sure of syntax more than anything as handling arrays is just a bit confusing at this time.

thanks i appreciate all your help!
sarah31 is offline   Reply With Quote
Old 06-09-2004, 07:15 AM   #7 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
show me the logic of how you would calculate 2 books, the first book has a quantity of 2, the second book a quantity of 1, and both of the same service.

then i can help you with the foreach code.
__________________
Mike
sde is offline   Reply With Quote
Old 06-09-2004, 10:00 AM   #8 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
ok say a user fills out the chart section of the form in this way (MA == Modern Age):
Code:
4 DC  Wonder Woman  1  June 2001  MA   10
1 DC  Wonder Woman  105 June 1958 Standard 125
want the very same calculation on the current script to be applied to the data above but in such a format

Modern Age Subtotals:
Number of books: 4
Service Cost: 40.00 (quantity*MA service cost)
Shipping: 14.90 (from the shipping calc on the existing script)
Insurance: 3.50 (value based on the insurance calc in the existing form)

Standard Service Subtotals:
Number of books: 1
Service charges: 14.00
Shipping: 7.40 (again using the existing shipping calc)
Insurance : 3.95 (again using the insurance calculation in the existing script)

Grand Totals:
number of books: 5
service charges: 54.00
shipping: 22.30
insurance: 7.45

Total: 83.75

so basically pulling out the data from the chart according to the service but and then applying the existing calculations on these groups of data so the user and the business have a breakdown of the charges as well as a grand total. it also allows the shipping and insurance charges to be calculated individually based on the service charges because based on the service there are different turnaround time and, therefore, potentially several different packages that will have to be sent back to the user.

i hope this clarifies what i need to do.
sarah31 is offline   Reply With Quote
Old 06-09-2004, 10:44 AM   #9 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,490
sde is on a distinguished road
im gonna try to look at it today, but might not be till tonight .. just letting you know i'm not forgetting about you. =)
__________________
Mike
sde is offline   Reply With Quote
Old 06-09-2004, 10:52 AM   #10 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
no rush at all i appreciate the help. i am continuing to read up on arrays and i may try and take a good long think on it tonight myself.

obviously this is not as easy as i had thought it would be
sarah31 is offline   Reply With Quote
Old 06-14-2004, 09:56 PM   #11 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
still really stumped with this one. i have played around with what i thought might work for handling the array but have had no success. i have also looked hard for examples of something similar. any suggestions are most welcome. perhaps an array may not be the answer? however i don't want a really long form either.
sarah31 is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Suggestion: Project Thread DavH27 Lounge 2 08-17-2004 10:23 AM
PHP Comes of Age sde Code Newbie News 0 04-14-2004 11:41 AM
I need to learn PHP Nitro PHP 9 06-28-2003 11:24 AM
Php Vs. Asp sde PHP 6 06-06-2003 06:02 PM
PHP as CGI?? bdl PHP 8 05-08-2003 08:29 AM


All times are GMT -8. The time now is 04:42 PM.


Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.0.0 RC8





Copyright © 2000-2008, Milano Interactive
Web Hosting provided by Portal 360 Web Hosting