Forum Moderators: coopster
$start=$end=null;
$where = "`username` = '".$_SESSION['user']."'";
//
if (preg_match('/\d{4}/',$_POST['syear']) and
preg_match('/\d{2}/',$_POST['smonth']) and
preg_match('/\d{2}/',$_POST['sday'])) {
$start = $_POST['syear'] . '-' $_POST['smonth'] . '-' $_POST['sday'];
}
if (preg_match('/\d{4}/',$_POST['eyear']) and
preg_match('/\d{2}/',$_POST['emonth']) and
preg_match('/\d{2}/',$_POST['eday'])) {
$end = $_POST['eyear'] . '-' $_POST['emonth'] . '-' $_POST['eday'];
}
//
$query = "SELECT * FROM `quotes` WHERE $where";
//
// Note the spaces before AND, important
if ($start) {
$query .= " AND `datesent` >= '$start'";
}
if ($end) {
$query .= " AND `datesent` <= '$end'";
}
$query .= " ORDER BY `quoteid` DESC LIMIT 100";
js calander to populate date fields on form. Looks like this after choice 2010-09-14 which it should do to match date field in mysql db.
session_start();
// Presuming, of course, you have an include to connect to db, etc.
$username=null;
if (isset($_SESSION['user'] and is_numeric($_SESSION['user']) and ($_SESSION['user'] > 0)) {
$username = $_SESSION['user'];
// Using the logic from my post, we will presume if they get past that,
// $username has been set.
//
$where=$findbetqdatestart=$findbetqdateend=null;
if (isset($_POST['findbetqdatestart']) and
preg_match('/\d{4}\-\d{2}\-\d{2}/',$_POST['findbetqdatestart'])) {
$findbetqdatestart = $_POST['findbetqdatestart'];
}
if (isset($_POST['findbetqdateend']) and
preg_match('/\d{4}\-\d{2}\-\d{2}/',$_POST['findbetqdateend'])) {
$findbetqdateend = $_POST['findbetqdateend'];
}
//
if ($findbetqdatestart) {
$where .= " `datesent` >= '$findbetqdatestart'";
}
if ($findbetqdateend) {
// If where has been set, we need an AND
if ($where) { $where .= ' and'; }
$where .= " `datesent` <= '$findbetqdateend'";
}
// If where has been set, we need an AND
if ($where) { $where .= ' and'; }
$where .= " `username` = '$username'";
//
$query = "SELECT * FROM `quotes` where $where order by `quoteid` desc limit 100";
// execute your query HERE
} END if $username
else {
// redirect to log in script or log in
}
$username = (isset($_SESSION['user']) ? $_SESSION['user'] : 'Log in');
Create variables ?
Like? $sday = $_POST['sday']; (How get findbetqdatestart)
Then where would this go
session_start();
// Presuming, of course, you have an include to connect to db, etc.
$username=null;
if (isset($_SESSION['user'] and is_numeric($_SESSION['user']) and ($_SESSION['user'] > 0)) {
$username = $_SESSION['user'];
$where=$findbetqdatestart=$findbetqdateend=null;
//
// Note the extra dots around '-' - oops, fixed here
if (preg_match('/\d{4}/',$_POST['syear']) and
preg_match('/\d{2}/',$_POST['smonth']) and
preg_match('/\d{2}/',$_POST['sday'])) {
$findbetqdatestart = $_POST['syear'] . '-' . $_POST['smonth'] . '-' . $_POST['sday'];
}
if (preg_match('/\d{4}/',$_POST['eyear']) and
preg_match('/\d{2}/',$_POST['emonth']) and
preg_match('/\d{2}/',$_POST['eday'])) {
$findbetqdateend = $_POST['eyear'] . '-' . $_POST['emonth'] . '-' . $_POST['eday'];
}
if ($start) {
$where .= " `datesent` >= '$findbetqdatestart'";
}
if ($end) {
// If where has been set, we need an AND
if ($where) { $where .= ' and'; }
$where .= " `datesent` <= '$findbetqdateend'";
}
// If where has been set, we need an AND
if ($where) { $where .= ' and'; }
$where .= " `username` = '$username'";
//
$query = "SELECT * FROM `quotes` where $where order by `quoteid` desc limit 100";
// execute your query HERE
} END if $username
else {
// redirect to log in script or log in
}