Forum Moderators: coopster

Message Too Old, No Replies

PHP Math with changing elements

PHP Math with changing elements

         

mattdawson

8:13 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



Hi,

I have been trying to wrap my brains around this all evening but still can't work it out so asking for help.

I have 2 tables in a mysql database, guests and hotels. Guest table has "userid" row and "favouritehotel" row. Hotel has "hotelid" row.

The hotelid is already saved in a session as $hotelid.

I want the following to happen:

When i input the "userid" into a text box, i want it to compare the "favouritehotel" from the user table to the "hotelid". If they are the same, i want it to do a sum which would be:

"Transaction Cost" x 1.5

If the "favouritehotel and the "hotelid" do not match, i want the sum to do:
"Transaction Cost" x 1

Just to give you the context behind it incase this is confusing... it's a points system. If the user's favorite hotel is the same as the hotelid doing the sum then they get 1.5 x the transaction cost. If they are not the favourite hotel, they only get 1 x the transaction cost.

Any support greatly appreciated!

MattAU

10:43 pm on Aug 28, 2008 (gmt 0)

10+ Year Member



Welcome to WW.

Something like this will work assuming you're using MySQL.

$query = "SELECT * FROM guests WHERE userid = '$userid' AND favouritehotel = '$hotelid'";
$result = mysql_query($query);
if(mysql_num_rows($result))
{
$total = $transaction_cost * 1.5;
}
else
{
$total = $transaction_cost;
}

jimboharris21

8:41 am on Sep 1, 2008 (gmt 0)

10+ Year Member



I think what i am looking for is simeler, i need a script that for example a customer will look at an online menu, and enter the quantity of each item they would like in a textbox, then at the bottom of the page display a total cost and the products ordered, and a copy to be emailed back to the resterant. would i have to use mysql or is there a way round it?