alphaswerve
07-17-2007, 12:23 PM
Hi - This is my first thread as a newbie, so please be patient if I'm not making much sense!
I've searched the net for the last week without success...
I've streamlined a bookings administration system (using PHP & MySQL)whereby displayed results are filtered using a simple drop down menu for each year. The drop down options are for individual years (i.e. 2006, 2007) and the drop down menu values are of a date range, i.e. menu option 2006 has an associated menu value of 20060101 and 20061231. This relates to the "between" value shown below:
mysql_select_db($database_dBconnect, $dBconnect);
$query_bookings = sprintf("SELECT *, date_format(date, '%%e %%b %%Y') as newdate FROM `bookings01` WHERE date between %s ORDER BY `date` ASC", GetSQLValueString($colname_bookings, "-1"));
$query_limit_bookings = sprintf("%s LIMIT %d, %d", $query_bookings, $startRow_bookings, $maxRows_bookings);
$bookings = mysql_query($query_limit_bookings, $dBconnect) or die(mysql_error());
$row_bookings = mysql_fetch_assoc($bookings);
I am attempting to display a total value for the filtered results, i.e. if option 2006 selected, only for the relevant date range described above. However when I attempt to incorporate the same "between" value code into the Sum calculation (assuming %s is the drop down menu value) I receive the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1" - My code I have used to try and display the filtered results total value is shown below:
<?php $sql = 'SELECT Sum(price) As total '.' FROM bookings01 WHERE newdate between %s';
$result = mysql_query($sql) or die(mysql_error());
$i = mysql_fetch_array($result);?>
<?php echo $i['total'];?>
Can anybody possibly provide a solution? Many thanks in advance.
I've searched the net for the last week without success...
I've streamlined a bookings administration system (using PHP & MySQL)whereby displayed results are filtered using a simple drop down menu for each year. The drop down options are for individual years (i.e. 2006, 2007) and the drop down menu values are of a date range, i.e. menu option 2006 has an associated menu value of 20060101 and 20061231. This relates to the "between" value shown below:
mysql_select_db($database_dBconnect, $dBconnect);
$query_bookings = sprintf("SELECT *, date_format(date, '%%e %%b %%Y') as newdate FROM `bookings01` WHERE date between %s ORDER BY `date` ASC", GetSQLValueString($colname_bookings, "-1"));
$query_limit_bookings = sprintf("%s LIMIT %d, %d", $query_bookings, $startRow_bookings, $maxRows_bookings);
$bookings = mysql_query($query_limit_bookings, $dBconnect) or die(mysql_error());
$row_bookings = mysql_fetch_assoc($bookings);
I am attempting to display a total value for the filtered results, i.e. if option 2006 selected, only for the relevant date range described above. However when I attempt to incorporate the same "between" value code into the Sum calculation (assuming %s is the drop down menu value) I receive the error "You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '%s' at line 1" - My code I have used to try and display the filtered results total value is shown below:
<?php $sql = 'SELECT Sum(price) As total '.' FROM bookings01 WHERE newdate between %s';
$result = mysql_query($sql) or die(mysql_error());
$i = mysql_fetch_array($result);?>
<?php echo $i['total'];?>
Can anybody possibly provide a solution? Many thanks in advance.