Jump to content

[SOLVED] Using results from an SQL query, adding them together to define a variable


matt.sisto

Recommended Posts

I want to use the results from my first sql query to define a variable. Basically I am selecting the months bookings but I want to add the fees for each booking together to create a total, unfortunately I am failing miserably. Any help please, much appreciated.  8)

<?php
  require "dbconn2.php"; 
  
  $org_id = $_POST["org_id"]; 
  $month1 = $_POST["month1"];
  $day1 = $_POST["day1"];
  $year1 = $_POST["year1"];
  $month2 = $_POST["month2"];
  $day2 = $_POST["day2"];
  $year2 = $_POST["year2"];

  $invoice_start = $year1."-".$month1."-".$day1." ".$_POST["event_start"];
  $invoice_end = $year2."-".$month2."-".$day2." ".$_POST["event_end"];


if ($org_id !=null){
  $sql = "SELECT event_id, event_start, event_end, service_id, unit, quantity, fee FROM calendar_events  CROSS JOIN client USING (client_id) WHERE calendar_events.event_start >= '".$invoice_start."' AND calendar_events.event_end <= '".$invoice_end."' AND client.org_id = '".$org_id."'";
  $result1 = mysql_query ($sql, $connection)
    or die ("Couldn't perform query $sql <br />".mysql_error())
  if($result1 != null){
    $result2 = mysql_query("SELECT SUM(fee) FROM '$result1'");
    if($result2 !=null){
      $totalFee = mysql_result($result2, 0);
    }
  }
}
echo $totalFee;
?>
<html>
<head>
<title>Invoice</title>
</head>
<body>
</body>
</html>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.