Welcome to WebmasterWorld Guest from 100.25.214.89

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP Math with changing elements

PHP Math with changing elements

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

New User

10+ Year Member

joined:Aug 28, 2008
posts: 1
votes: 0


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!

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

Junior Member

10+ Year Member

joined:June 6, 2005
posts:109
votes: 0


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;
}

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

New User

10+ Year Member

joined:Sept 1, 2008
posts: 8
votes: 0


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?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members