hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : calculator
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

calculator

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 10-19-2006, 06:52 PM
Ricky_182 Ricky_182 is offline
Newbie
 
Join Date: Sep 2006
Posts: 7
*

calculator


Hey, Im building a website for my work. And they own a Travel Company. I want to do a PHP or HTML thing where they can click how many people are traveling and where to and it comes up with a answer As In How much it will cost. If anyone can code one or knows where i can get one would really help

23 People
To London
From Leeds
= £230

See what i mean? I want it so when they click or type the opions they want it will have a calculat button at the bottem and tell them the price


Cheers Ricky

Reply With Quote


Sponsored Links
  #2  
Old 10-19-2006, 07:01 PM
tnndotnet tnndotnet is offline
Web Hosting Guru
 
Join Date: Feb 2006
Location: Pittsburgh PA
Posts: 289
i would start looking into javascript, I want to do the same thing, but i cant really find any good information on it. however, I have seen what your talking about done in java, but i dont have to code =/

Reply With Quote
  #3  
Old 10-19-2006, 07:07 PM
Ricky_182 Ricky_182 is offline
Newbie
 
Join Date: Sep 2006
Posts: 7
Yeah, Java And php arnt really my thing i only know HTML and how to edit PHP.. lol So im a bit noobbish on that

Reply With Quote
Sponsored Links
  #4  
Old 10-19-2006, 08:00 PM
spryandrew spryandrew is offline
Junior Guru Wannabe
 
Join Date: Oct 2006
Posts: 44
Whether you want to use a client-side language like javascript, or a server side technology like php or ruby will depend on your needs. If your prices are fixed then javascript can offer a faster user experience, but isn't as flexible as the server technologies. PHP and the other server side technologies will allow you to store prices in a database and update them in a single place, which makes ongoing administration easier. The price you pay is you need more resources to run server side technologies. AJAX would give you a good compromise between the two options, but will cost more to set up.

There are a number of places you can go to find scripts on the web. Just do a Google search for 'php scripts' or the like and you'll find plenty of sites that have scripts. I haven't used any of these sites, so I can't offer any recomendations. But I will warn you not to use any pre made script if you can't understand the php well enough to be sure there aren't any security holes.

I can't really say what it would cost you to have it done either. The old maxim about 'you get what you pay for' applies. You don't want to over pay, but you don't want shoddy, buggy scripts either.

__________________
Andrew
Spry VPS Hosting cPanel VPS, Plesk VPS, Webmin VPS, Shared, Domain Registration, Dedicated and Colo
VPSLink Cheap VPS accounts CentOS, Fedora 4/5/6, RHEL, Gentoo, Debian, Ubuntu -- Dapper/Edgy, Slackware, OpenSUSE, LAMP + Ruby pre-installed available

Reply With Quote
  #5  
Old 10-19-2006, 08:02 PM
Ricky_182 Ricky_182 is offline
Newbie
 
Join Date: Sep 2006
Posts: 7
cheers andrew Ill keep that in mind

Reply With Quote
  #6  
Old 10-20-2006, 12:12 AM
Syphic Syphic is offline
Junior Guru
 
Join Date: Jan 2003
Location: USA, FL
Posts: 241
Rick if you know the prices of the ticket then here is a simple script.
This script is just and example and is not for production use.
This is the longer, hardcoded away of doing it but it could be done by database which would be easier to maintain and change prices like spryandrew explained.

Thank you and have a good day

Code:
<?php

$get_to = $_POST['to'];
$get_from = $_POST['from'];
$get_ppl = $_POST['ppl'];

if(isset($get_to) && isset($get_from) && isset($get_ppl)){
if($get_to == 'london' && $get_from='leads'){
$price = $get_ppl * 200;
echo 'Cost is: '.$price.'<br />';
}
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
To:<select name="to">
<option value="london">London</option>
</select>
From: <select name="from">
<option value="leads">Leads</option>
</select>
People: <input type="text" name="ppl" />
<input type="submit" value="Submit" />
</form>

Reply With Quote
  #7  
Old 10-20-2006, 07:52 AM
hosting4life hosting4life is offline
Temporarily Suspended
 
Join Date: Jan 2005
Posts: 106
Quote:
Originally Posted by Syphic
Rick if you know the prices of the ticket then here is a simple script.
This script is just and example and is not for production use.
This is the longer, hardcoded away of doing it but it could be done by database which would be easier to maintain and change prices like spryandrew explained.

Thank you and have a good day

Code:
<?php

$get_to = $_POST['to'];
$get_from = $_POST['from'];
$get_ppl = $_POST['ppl'];

if(isset($get_to) && isset($get_from) && isset($get_ppl)){
if($get_to == 'london' && $get_from='leads'){
$price = $get_ppl * 200;
echo 'Cost is: '.$price.'<br />';
}
}

?>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="POST">
To:<select name="to">
<option value="london">London</option>
</select>
From: <select name="from">
<option value="leads">Leads</option>
</select>
People: <input type="text" name="ppl" />
<input type="submit" value="Submit" />
</form>
That works but takes allot of editing if you are going to use more destinations.

Reply With Quote
  #8  
Old 10-20-2006, 10:52 AM
Ricky_182 Ricky_182 is offline
Newbie
 
Join Date: Sep 2006
Posts: 7
To be honest i cant be botherd messing about withdata base's id rather have it in a script and edited the scripts

Reply With Quote
  #9  
Old 10-20-2006, 01:53 PM
Xenatino Xenatino is offline
Web Hosting Evangelist
 
Join Date: Oct 2004
Location: UK
Posts: 487
If your going to avoid using a database, your going to be best off using Arrays to store the locations, rather than using hundreds/thousands of boolean statements.

Look into using dual arrays to store the 2 locations and the price for the 2.

The other option is flat file databasing, avoiding using MySQL.

Reply With Quote
  #10  
Old 10-20-2006, 02:20 PM
cywkevin cywkevin is offline
Predatory Poster
 
Join Date: Jul 2003
Location: Goleta, CA
Posts: 5,550
I strongly urge you to go the database route. What happens when the travel agency wants you to sort trips by popularity. Maybe they want added information like which trips have a lot of viewers but no buyers. This seems like it would be much easier to expand using a database system. maybe the price is too high etc. Find ways to make more money whenever you can.

__________________
Patron: I'd like my free lunch please.
Cafe Manager: Free lunch? Did you read the fine print stating it was an April Fool's joke.
Patron: I read the same way I listen, I ignore the parts I don't agree with. I'm suing you for false advertising.
Cafe Owner: Is our lawyer still working pro bono?

Reply With Quote
  #11  
Old 10-20-2006, 06:58 PM
Syphic Syphic is offline
Junior Guru
 
Join Date: Jan 2003
Location: USA, FL
Posts: 241
As I stated within my code; the easier and better way would be to do by database. The small 5 min work was a concept to give a raw/basic idea of what you were askin for and what you were wanting. Again, as I stated, it was the hardcoded way and if you know the basics this could be easily integrated into the use of a database as below. Again, this is not for production but for a basic example.

Example and this is only the PHP part.

[code]
Code:
$get_to = $_POST['to'];
$get_from = $_POST['from'];
$get_ppl = $_POST['ppl'];

// table structure - flight table : Fields (flight_id, flight_to, flight_from, flight_price)

$result = mysql_query("SELECT * FROM flight_table WHERE flight_to='$get_to' && '$get_from' ");
$flight = mysql_fetch_assoc($result);

if(isset($get_to) && isset($get_from) && isset($get_ppl)){
if($get_to == 'london' && $get_from='leads'){
$price = $get_ppl * $flight['flight_price'];
echo 'Cost is: '.$price.'<br />';
}
}
This code atleast needs some some sql injection and validation of variables. I would also suggest a more optmized approach for the database. Something like:

table: location_to
location_to_id
location_to_name

table: location_from
location_from_id
location_from_name

table: flight_price
flight_id
flight_to
flight_from
flight_price

Again this is just one of the many ways of doing it. It hightly depends on how complex and detailed it needs to be.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
Phoenix NAP Offers Colocation Services Out of Ashburn Data Center Web Hosting News 2013-02-01 12:13:04
Prolexic Study Offers E-Commerce Website Strategies to Combat Holiday DDoS Attacks Web Hosting News 2012-10-29 12:27:45
Netwise Hosting Launches Real-time Colocation Cost Calculator Web Hosting News 2012-06-22 15:00:14
Research Shows Plenty of Further Savings in Government Cloud Computing Web Hosting News 2012-04-26 11:59:49
Security Firm StillSecure Launches Free PCI Calculator for Retailers Web Hosting News 2011-07-06 16:56:39


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

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 Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?