Ricky_182
10-19-2006, 06:52 PM
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
tnndotnet
10-19-2006, 07:01 PM
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 =/
Ricky_182
10-19-2006, 07:07 PM
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
spryandrew
10-19-2006, 08:00 PM
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.
Ricky_182
10-19-2006, 08:02 PM
cheers andrew Ill keep that in mind
Syphic
10-20-2006, 12:12 AM
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
<?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>
hosting4life
10-20-2006, 07:52 AM
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
<?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.
Ricky_182
10-20-2006, 10:52 AM
To be honest i cant be botherd messing about withdata base's id rather have it in a script and edited the scripts
Xenatino
10-20-2006, 01:53 PM
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.
cywkevin
10-20-2006, 02:20 PM
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.
Syphic
10-20-2006, 06:58 PM
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]
$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.