I am having a problem that I have tried to fix for over 3 hours. I cannot figure it out!!! The problem query is this...
"SELECT count(*) FROM consignments WHERE consignment_consigned != 'Settled' AND consignment_date_consigned BETWEEN '".$datestart."' AND '".$datestop."'"
// Which returns as...
"SELECT count(*) FROM consignments WHERE consignment_consigned != 'Settled' AND consignment_date_consigned BETWEEN '1111-11-11' AND '2222-11-11' "
This code works fine in PHPMyAdmin, but it does not work in the query below. Can someone please help me figure this darn thing out? Thanks in advance, -Robert
$datestart = (!empty($_POST['datestart'])) ? clean($_POST['datestart']) : "";
$datestop = (!empty($_POST['datestop'])) ? clean($_POST['datestop']) : "";
if(@$_POST['orderby'] == "nts")
{
if(admin($_SESSION['username']))
$query = (!empty($datestart) || !empty($datestop)) ? @mysql_query("SELECT count(*) FROM consignments WHERE consignment_consigned != 'Settled' AND consignment_date_consigned BETWEEN '".$datestart."' AND '".$datestop."'") or die(mysql_error()) : @mysql_query("SELECT * FROM consignments WHERE consignment_consigned != 'Settled' ") or die(mysql_error());
else
$query = (isset($datestart) || !empty($datestop)) ? @mysql_query("SELECT * FROM consignments WHERE consignment_consigned != 'Settled' AND consignment_date_consigned BETWEEN ".$datestart." AND ".$datestop." AND owner=' ".$_SESSION['username']."' " ) or die(mysql_error()) : @mysql_query("SELECT * FROM consignments WHERE consignment_consigned != 'Settled' AND owner='".$_SESSION['username']."'") or die(mysql_error());
?>
<table width="746" border="0" cellpadding="0" cellspacing="0">
<tr>
<td height="186" valign="top"><p align="center"><span class="bigg">
</span><span class="bigg"><br>
Need to Settle Report</span><br>
<span class="main">Select a report and desired criteria below to viewreport.</span><br>
<span class="main">
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=view_records" style="color: #000000;">View Your Consignments</a> |
<a href="javascript:history.back(-1);" style="color: #000000;">View Your Reports</a> |
<a href="<?php echo $_SERVER['PHP_SELF']; ?>" style="color: #000000;">Home</a> |
<a href="<?php echo $_SERVER['PHP_SELF']; ?>?action=logout" style="color: #000000;">Logout</a></span>
</p>
<table width="100%" height="668" border="0" align="center" cellpadding="2" cellspacing="1" class="tables">
<?php
if(@mysql_num_rows($query) == 0)
{
?>
<tr>
<td height="17" nowrap class="mainblackbold" colspan="6">Sorry - No results found.</td>
</tr>
<?php
exit;
}
else
{
while($row = @mysql_fetch_array($query))
{
$totalunits = 0;
$estcost = 0;
$saleprice = 0;
?>
<tr class="mainCopy">
<td height="17" nowrap bgcolor="#CCCCCC" class="mainblack"> </td>
<td height="17" colspan="4" nowrap bgcolor="#CCCCCC" class="mainblack">
<div align="left">Vendor: <?php echo $row['vehicle_location_company_name']; ?></div></td>
<td colspan="3" nowrap bgcolor="#CCCCCC"><div align="left">
<p class="mainblackbold">Report Date: <?php echo $row['consignment_date_consigned']; ?></p>
</div></td>
</tr>
<?php
$query2 = (isset($datestart) && !empty($datestart)) ? @mysql_query("SELECT DISTINCT vehicle_location_company_name FROM consignments WHERE consignment_date_consigned='".$datestart."' AND vehicle_location_company_name = '".$row['vehicle_location_company_name']."'") or die(mysql_error()) : @mysql_query("SELECT DISTINCT vehicle_location_company_name FROM consignments WHERE vehicle_location_company_name = '".$row['vehicle_location_company_name']."'") or die(mysql_error());
while($row2 = @mysql_fetch_array($query2))
{
$totalunits++;
$estcost += ($row['vehicle_cost'] + $row['misc_expenses'] + $row['auction_expenses']);
$saleprice += $row['bid_information_amount_recieved'];
?>
<tr>
<td width="52" height="17" nowrap class="main"> <p align="left" class="mainblackbold">Unit #:</p></td>
<td width="118" nowrap class="main"><div align="left"><?php echo $row['consignment_lease_company_unit_number']; ?></div></td>
<td width="52" nowrap class="main"><p align="left" class="mainblackbold">Year:</p></td>
<td width="100" nowrap class="main"><div align="left"><?php echo $row['vehicle_information_year']; ?></div></td>
<td width="91" nowrap class="main"><p align="left" class="mainblackbold">Miles:</p></td>
<td width="136" nowrap class="main"><div align="left"><?php echo $row['vehicle_information_mileage']; ?></div></td>
<td width="56" nowrap class="main"><p align="left" class="mainblackbold">Price:</p></td>
<td width="96" nowrap class="main"> <div align="left"><?php echo $row['bid_information_amount_recieved']; ?></div></td>
</tr>
<tr>
<td height="17" nowrap class="main"> <p align="left" class="mainblackbold">Sold To:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['contact_name']; ?></div></td>
<td nowrap class="main"> <p align="left" class="mainblackbold">Make:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['vehicle_information_make']; ?></div></td>
<td nowrap class="main"> <p align="left" class="mainblackbold">VIN:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['vehicle_information_vin']; ?></div></td>
<td nowrap class="main"> <p align="left" class="mainblackbold">Cost:</p></td>
<td nowrap class="main"> <div align="left"><?php echo ($row['vehicle_cost'] + $row['misc_expenses'] + $row['auction_expenses']); ?></div></td>
</tr>
<tr>
<td height="17" nowrap class="main"> <p align="left" class="mainblackbold">Stock #:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['id']; ?></div></td>
<td nowrap class="main"> <p align="left" class="mainblackbold">Model:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['vehicle_information_model']; ?></div></td>
<td nowrap class="main"> <p align="left" class="mainblackbold">Sold On:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['vehicle_information_sold_on']; ?></div></td>
<td nowrap class="main"> <p align="left" class="mainblackbold">Recon:</p></td>
<td nowrap class="main"> <div align="left"><?php echo $row['recon']; ?></div></td>
</tr>
<tr>
<td height="17" colspan="8" nowrap class="toplineCopy"> </td>
</tr>
<?php } ?>
<tr>
<td height="17" nowrap class="main"> </td>
<td height="17" colspan="2" nowrap class="topline">Total Units: <?php echo number_format($totalunits); ?></td>
<td height="17" colspan="2" nowrap class="topline"><span class="mainblackbold">Total Est. Cost: $<?php echo number_format($estcost); ?> </td>
<td height="17" colspan="3" nowrap class="topline">Total Sale Price: $<?php echo number_format($saleprice); ?></td>
</tr>
<?php
}
}
echo " </table>";