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

Posted on 2005-04-03
Medium Priority
Last Modified: 2008-02-07
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:

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);
      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)) //;
          <table border="" cellpadding="0" cellspacing="1" style="border-collapse: collapse; border-width: 0" bordercolor="" width="100%" id="AutoNumber6">
              <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>
Question by:acslater
  • 2
LVL 12

Accepted Solution

Gregory Miller earned 2000 total points
ID: 13691777
add this after your query and date calculations
if(dateDiff( $pickupdate, $dropoffdate )==0){
   $thisPrice = $row["price"];
   $thisPrice = $row["price"] * dateDiff( $pickupdate, $dropoffdate );

and then replace the price variable as such...

              <td width="116" valign="top"><? echo $row["Make"]; ?></td>
            <td width="112" valign="top"><? echo $row["transmission"]; ?></td>
              <td width="115" valign="top"><? echo $thisPrice; ?></td>

Author Comment

ID: 13691973
dat worked a treat
LVL 12

Expert Comment

by:Gregory Miller
ID: 13691989
great... Thanks!

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

569 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question