Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Fetching records from only last month..

Status
Not open for further replies.

tgignac

IS-IT--Management
May 13, 2004
18
CA
Hi folks, I seem to have a problem with my script for only getting records from the previous month... my script is below: Any help would be greatly appreciated :)

*<?php require_once('../../Connections/MySQL.php'); ?>
<?php
$month = date('n');
$year = date('Y');

$lastmonth = $month-1;
if ($lastmonth==0) { $lastmonth=12; $year--; }

$startdate = $year . '-' . $lastmonth . '-01';
$enddate = date('Y') . '-' . $month . '-01';

mysql_select_db($database_MySQL, $MySQL);
$query_Recordset1 = "SELECT * FROM PlanInsp WHERE InspDate>='" . $startdate . "' AND InspDate<'" . $enddate . "' ";
$Recordset1 = mysql_query($query_Recordset1, $MySQL) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>*
 
I dont know about php but in asp you need to have yoour dates wrapped up in a '#' as in
Code:
SELECT * FROM PlanInsp WHERE InspDate>=#" . $startdate . "# AND InspDate<#" . $enddate . "# ";

Cheech

[Peace][Pipe]
 
PHP Forum forum434



Chris.

Indifference will be the downfall of mankind, but who cares?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top