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
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 11

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 11

Expert Comment

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

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

770 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