Link to home
Start Free TrialLog in
Avatar of acslater
acslater

asked on

im doin car rental site where i have set price to each car. i have worked out number of days between dates. i need this multiply two values to get quota

Im doin a car rental site where each car has a set price. I have an orderpage2.php that takes in the pick up date and the drop off date. I have calculated the difference in dates. The next page displaycar.php shows the model, make and transmission and price for each car. I want to show the quoted price for each car. That is the price per day multiplied by the number of days.
The following is the code i used for displaycar.php to get price per day and day difference:

<?php
session_start();
header("Cache-control: private"); //IE 6 fix*/
$pickup = $_POST['pickup'];
$dropoff = $_POST['dropoff'];
$pickupdate = $_POST['Pick_Up_Date'];
$dropoffdate = $_POST['Drop_Off_Date'];
$transmission = $_POST['transmission'];
$_SESSION['pickup'] = $pickup;
$_SESSION['dropoff'] = $dropoff;
$_SESSION['Pick_Up_Date'] = $pickupdate;
$_SESSION['Drop_Off_Date'] = $dropoffdate;
$_SESSION['price'] = $price;
$_SESSION['transmission'] = $transmission;
?>
<?php function makeTimestamp( $date )
{    
static $months = array( 1 => 'Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec' );  
$fixed = preg_replace('#^\s*(\d{1,2})\s*([-/\.])\s*(\d{1,2})\s*\\2\s*(\d{2,4})\s*$#e', 'sprintf(\'%02d-%s-%04d\', intval(\'\\1\'), $months[intval(\'\\3\')], (strlen(\'\\4\') < 4 ? 1900 : 0) + intval(\'\\4\') )', $date);    
return strtotime($fixed);
}  
function toDays( $timestamp )
{  
  return intval(intval($timestamp) / (24 * 60 * 60));
}
 function dateDiff( $date1, $date2 )
{    $date1 = toDays(makeTimestamp( $date1 ));  
 $date2 = toDays(makeTimestamp( $date2 ));        
return abs($date1 - $date2);
}
echo dateDiff( $pickupdate, $dropoffdate );

?>


I know i wont need to echo datediff. its just how to get price in database, for each car that is available multipiled by datediff.



I just echoed out the differnce in dates to see if it worked. i want to multiply this date difference by the price per day and display it in the price field. But there is small complication on to this. if the datediff = 0 i want the price field to just display the price in the database else if datediff = 1 i want the price to be price in the database + price in the database(price in database * price in database) else if datediff > 1 i want the price in price field to display the price in database * datediff + price in database,
for example if price per day in database = 20 and calculated date diff = 4
price field should hold value of 4*20+20 = 100


the following is the code for printing out the results. i know the last echo wont be echo row['price']. it must be whatever calculation i worked out:

<?
include "db_connection.php";
$connect = db_connect();
if ($connect)
$_SESSION['pickup'] = $pickup;
//$_SESSION['username'] = $username;
{
$query = "select * from car Where pickup ='$pickup' && transmission Like '%$transmission'"; //Selecting all Entries from the database

      $result = mysql_query($query,$connect); //Assigns the variable result to the Query Connection
      
      //$temp = mysql_fetch_array($result);
                  
      if(mysql_num_rows($result)==0)
      {
      
      echo"There are no Records with the location You have entered.";?>        <P>  
          <a href="orderpage.php">
      
      
          <?
      echo"Please Click Back";
      
      }
      
      while($row = mysql_fetch_assoc($result)) //;
      {
        ?>       
          </center>
        
      
      
          <table border="" cellpadding="0" cellspacing="1" style="border-collapse: collapse; border-width: 0" bordercolor="" width="100%" id="AutoNumber6">
            <!--DWLayoutTable-->
            <b>
            <tr>
              <td width="105" height="44" valign="top"><b><a href = "EnterCreditCard.php?model=<? echo $row['Model']?>&make=<? echo $row['Make']?> " ><? echo $row["Model"]; ?>  </a></b></td>
              <td width="116" valign="top"><? echo $row["Make"]; ?></td>
            <td width="112" valign="top"><? echo $row["transmission"]; ?></td>
              <td width="115" valign="top"><? echo $row["price"]; ?></td>
            </tr>
                  
                 <?
ASKER CERTIFIED SOLUTION
Avatar of Gregory Miller
Gregory Miller
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of acslater
acslater

ASKER

dat worked a treat
great... Thanks!