Jump to content

how to query date range


mcerveni

Recommended Posts

I have 2 queries that i'm trying to put together:

 

$sql = "SELECT * FROM teams LEFT JOIN import_stats ON teams.EmpID = import_stats.EmpID WHERE import_stats.EmpID = '$agentID' ORDER BY date ASC";
$sql_range = "SELECT date FROM import_stats WHERE date Between '$start' && '$end' ";

 

Basically, it will find the employee by their EmpID and email there information to them. But when i try and put a second query, the $sql_range, it will email no records.

 

my full code is :

 

$agentID = $_GET['aID'];
$agentName = $_GET['n'];
$date = "03/09/2009";

$start = "03-02-2009";
$end = "03-03-2009";


$sql = "SELECT * FROM teams LEFT JOIN import_stats ON teams.EmpID = import_stats.EmpID WHERE import_stats.EmpID = '$agentID' ORDER BY date ASC";
$sql_range = "SELECT date FROM import_stats WHERE date Between '$start' && '$end' ";

$result = mysql_query($sql);
$range_result = mysql_query($sql_range);
$row=mysql_fetch_array($result);

$email = $row['email']; //this must be here, else it won't grab the email. 
$TeamCoach = $row['TeamCoach'];

while($row=mysql_fetch_array($result, $range_result))
{

$array_s['date'][]= $row['date'];
$array_s['StaffedTime'][]=$row['StaffedTime'];
$array_s['AHT'][]=$row['AHT'];
$array_s['ACDCalls'][]=$row['ACDCalls'];
$array_s['ACDTime'][]=$row['ACDTime'];
$array_s['AvgACDTime'][]=$row['AvgACDTime'];
$array_s['ACWTime'][]=$row['ACWTime'];
$array_s['AvgACWTime'][]=$row['AvgACWTime'];
$array_s['HoldCalls'][]=$row['HoldCalls'];
$array_s['HoldTime'][]=$row['HoldTime'];
$array_s['AvgHoldTime'][]=$row['AvgHoldTime'];
$array_s['OutboundCalls'][]=$row['OutboundCalls'];
$array_s['OutboundTime'][]=$row['OutboundTime'];
$array_s['AvailTime'][]=$row['AvailTime'];
$array_s['RingTime'][]=$row['RingTime'];
$array_s['AvgRingTime'][]=$row['AvgRingTime'];
$array_s['utilization'][]=$row['utilization'];

}



$to= $email;
$subject = " $agentName's Stats";

$body="  $agentName,  below are your current stats.
<br><br>

<table style = 'color:#212732;'>
<tr> <th style='background-color:#b9cbe9;'> Date </th> <th style='background-color:#b9cbe9;'>  Staffed Time  </th>  <th style='background-color:#b9cbe9;'>  AHT  </th> <th style='background-color:#b9cbe9;'>  ACD Calls  </th>  <th style='background-color:#b9cbe9;'>  ACD Time  </th>  
<th style='background-color:#b9cbe9;'>  Avg. ACD Time  </th>  <th style='background-color:#b9cbe9;'>  ACW Time </th> <th style='background-color:#b9cbe9;'>  Avg. ACW Time  </th>  <th style='background-color:#b9cbe9;'>  Hold Calls  </th>  <th style='background-color:#b9cbe9;'>  Hold Time  </th>  <th style='background-color:#b9cbe9;'> Avg. Hold Time </th>  <th style='background-color:#b9cbe9;'>  Outbound Calls  </th>  
<th style='background-color:#b9cbe9;'>  Outbound Time  </th>  <th style='background-color:#b9cbe9;'>  Avail Time  </th>  <th style='background-color:#b9cbe9;'> Ring Time  </th>  <th style='background-color:#b9cbe9;'>   Avg. Ring Time </th>  <th style='background-color:#b9cbe9;'>  Utilization   </th> 
</tr>";


for($j=0;$j<count($array_s['date']);$j++)
{

$body .= "<tr> <td style='text-align:center'>  ".$array_s['date'][$j]." </td> <td style='text-align:center'> ".$array_s['StaffedTime'][$j]."   </td>
<td> ".$array_s['AHT'][$j]."  </td>  <td>  ".$array_s['ACDCalls'][$j]."  </td>  <td>  ".$array_s['ACDTime'][$j]."  </td>  <td>  ".$array_s['AvgACDTime'][$j]." </td> 
<td> ".$array_s['ACWTime'][$j]."  </td>  <td>  ".$array_s['AvgACWTime'][$j]."  </td> <td> ".$array_s['HoldCalls'][$j]."  </td> <td> ".$array_s['HoldTime'][$j]."</td> 
<td> ".$array_s['AvgHoldTime'][$j]."  </td> <td> ".$array_s['OutboundCalls'][$j]." </td>  <td>  ".$array_s['OutboundTime'][$j]."</td>  
<td>  ".$array_s['AvailTime'][$j]."</td> <td> ".$array_s['RingTime'][$j]." </td>  <td> ".$array_s['AvgRingTime'][$j]."</td> <td>  ".$array_s['utilization'][$j]."  </td> 
</tr>
";
}

$body .= "</table>
<br><br><br>
Your Team Coach: <b> $TeamCoach </b>

";


$headers = "From: Team Coach: ".$TeamCoach." \r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";



mail($to, $subject, $body, $headers);
echo ' <span id="emailConfirm"> The stats have been sent to ' . $agentName; '</span>';



 

Any help?

Link to comment
https://forums.phpfreaks.com/topic/149783-how-to-query-date-range/
Share on other sites

Thanks! it worked.. however i'm having an issue with the range.. when I try and find records from 3/3/2009 ANd 3/9/2009  it will display 3/4/2009 until 3/9/2009 . It won't show the 3/3/2009.

 

I'll double check it later tonight, but that's what it was doing earlier.

just wondering why?

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.