Page 1 of 1

session? Query and VAT

Posted: Thu Jan 13, 2011 12:24 pm
by jsk1gcc
My brain no longer works, It has packed up and left for the day. o.0

In a table called ride there is a price 2.50. I need this result to calculate VAT for one seat and then two seats.

here is what I have so far =)

query:

Code: Select all

$query =mysql_query("SELECT price FROM ride WHERE rideID ='1' LIMIT 1");
while ($row=mysql_fetch_array($query))
{
echo $row['price'];
echo "<br>";
}
her is the VAT function:

Code: Select all

$seatPrice2=($price*2);
		$seatPrice1=($price*1);
		
		$vat1=17.5;
		$priceXvat=$price;
		
		function vat($vat, $priceXvat)
			{
				return sprintf("%01.2f", ($vat*$priceXvat/ 100));
			}
				$vatprice1 = vat(17.5, 2.50);
				$vatprice2 = vat(17.5, 2.50);
		
		$total2=($vatprice2*2);
		$SSendPrice2= ($total2+$seatPrice2);
		
		
		$total1=($vatprice1*1);
		$SSendPrice1= ($total1+$seatPrice1);
		
I know hat the VAT function is messy, there must be an easier way to do this. could someone please help me combine the query and VAT function to give two variables 1 for 1 seat and 1 for 2 seats.

also the query I have doesn't need to have the price displayed, the 2.50 is just a base price =) I just had an echo to see if it was working first.
=)

any help would be fantastic.

Re: Simple question Query and VAT

Posted: Thu Jan 13, 2011 12:37 pm
by superdezign
Well, I have no idea what you mean by a VAT, but your code is certainly strange. You have the value of $price saved in $seatPrice1 and $priceXvat, and $vatprice1 is equal to $vatprice2. I'm not sure what you are doing, but it makes the code odd to follow.

Anyway, why do you use sprintf() if you are hoping to receive a numerical value? What that will give you is a formatted numerical string. The value of vat(17.5, 2.50) should be "0.43", though I am not entirely sure. You should echo it to check. But I get the feeling that what you are doing isn't what you are trying to do.

I'd suggest you try explaining what data/input you have available to you and what output you are trying to get, and this time without using any acronyms.

Re: Simple question Query and VAT

Posted: Thu Jan 13, 2011 12:58 pm
by McInfo
Wikipedia proposes that VAT means Value Added Tax.

Re: Simple question Query and VAT

Posted: Thu Jan 13, 2011 1:31 pm
by jsk1gcc
Sorry about the rubbish explanation. I'll try again =) You'd think I'd know better by now =P

I have one table with a column named price. (to be clear the price is £2.50)
I am trying to calculate the VAT at 17.5% using price from the table called ride. Within the programme there is a chance to book two seats. what I an trying to do is to calculate the VAT for one seat or two seats; depending on what the user picked.

The user picks the seats from a drop down box on the second page of the booking system

Swing.php

Code: Select all


//DROP DOWN BOX ONE
$extract =mysql_query("SELECT * FROM ride WHERE rideID ='1'");
$numrows = mysql_num_rows($extract);

echo '<form method="post" name="f2" action="card.php">';
echo 'Please choose a seat:  '; 
echo"<select name='seat' >";
		while( $row = mysql_fetch_assoc($extract)) 
		{   
			$rideID = $row ['rideID'];
			$name = $row ['name'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat'> $seatNumber </option>";
			$_SESSION['extract']=$_POST['seat'];
		}  
echo '</select><br>'; 

//DROP DOWN BOX TWO
$extract2 =mysql_query("SELECT * FROM ride WHERE rideID ='1'");
$numrows = mysql_num_rows($extract2);

echo '<form method="post" name="f2" action="card.php">';
echo 'Please choose a seat:  '; 
echo"<select  name='seat2' >";
		while( $row = mysql_fetch_assoc($extract2)) 
		{   
			$rideID = $row ['rideID'];
			$name = $row ['rideName'];
			$seatNumber = $row ['seatNumber'];
			$time = $row ['time'];
			$price = $row ['price'];
			
			echo "<option name='seat2'> $seatNumber </option>";
			$_SESSION['extract2']=$_POST['seat2'];
		}  
echo '</select><br>'; 

The price is called here and using the VAT function above shows the VAT of one seat and two seats, though just as variables. The end page for the insert into database query is three more pages away. Being as though there is already a SESSION for the seat number chosen I didn't think it possible to have price as a session too.

The price from the database has to have a VAT calculation applied and the total inserted into the database on the last page. It does not matter which page the VAT calculation is made on if the end results can be put into sessions; But I have little idea how to do this =(

The VAT function came from a code snippet that I modified to fit my script. here is the original if it helps.

Code: Select all

<?php
function vat($vat, $priceexvat)
{
return sprintf("%01.2f",($vat*$priceexvat/ 100));
}
?>

<?php
echo vat(17.5,300);
?>
At this present moment, I am unsure as to how I got my results but using the modified VAT function it returned the vat at 0.43 the price for one seat was $SSendPrice1 and for two seats was $SSendPrice2.
One seat is 2.94 (inc VAT)
Two seas is 5.88 (inc VAT)

If as you suggest the VAT function does not work then I am unsure how the code works properly and cannot explain how i got those results, at first I was just happy that I got them.. until i tired to insert them into the database that is =|

Sorry if this is long and If I have repeated myself alot.