我需要用户输入 1.城市 2.最低预算和最高预算 3.日期
城市=城市,最低预算<=儿童价格,最大预算> =成人价格,日期=天。
我的问题,价格范围以及如何使用datepicker从用户输入中获取日期?在数据库中,我存储了城市,儿童价格,成人价格和日期。 我尝试城市和价格范围,如下面的代码,结果仅根据城市显示。
日期选择器代码:
<script src="js/jquery-ui.js"></script>
<script>
$(function() {
$( "#datepicker" ).datepicker();
});
</script>
我在php和html中的代码:
<form method="post" action="search.php">
<label>City: </label>
<select name="city">
<option> Select </option>
<option value="bandar hilir"> bandar hilir </option>
<option value="bukit katil"> bukit katil</option>
<option value="ayer keroh"> ayer keroh </option>
<option value="alor gajah"> alor gajah </option>
<option value="jasin"> jasin</option>
</select>
<h6>Budget per Person </h6>
<h6>Minimum Budget: RM <input type="text" name="minbudget" id="minbudget" placeholder="10.00"></h6>
<h6>Maximum Budget: RM <input type="text" name="maxbudget" id="maxbudget" placeholder="20.00"></h6>
<h6>Date:<input class="date" id="datepicker" type="text" placeholder="dd-mm-yyyy" name="date"></h6>
<br><br><input type="submit" name="search" class="btn-primary btn" value="Search">
</form>
我在评论中写的问题
<?php
$city="";
$PackageName="";
$address="";
$OperationHour="";
$minbudget="";
$maxbudget="";
$ChildPrice="";
$AdultPrice="";
$SeniorPrice="";
$PackageFetures="";
$PackageImage="";
if (isset($_POST["search"]))
{
include('includes/config.php');
$city = $_POST['city'];
$minbudget = $_POST['minbudget'];
$maxbudget = $_POST['maxbudget'];
$date=$_POST['date'];
$_POST['date'] = date('1', strtotime($_POST['date']));
$sql = "SELECT * FROM tbltourpackages WHERE city LIKE '%$city%' AND (ChildPrice >= $minbudget AND AdultPrice <= $maxbudget) OR OperationDay LIKE '%$date%'";
$query = $dbh -> prepare($sql);
$city="%$_POST[city]%";
$query->bindParam(':city', $city, PDO::PARAM_STR);
$query->bindParam(':minbudget', $_POST['minbudget'], PDO::PARAM_STR);
$query->bindParam(':maxbudget', $_POST['maxbudget'], PDO::PARAM_STR);
$query->bindParam(':date', $_POST['date'], PDO::PARAM_STR);
$exec=$query->execute();
if($exec)
{
if ($query -> rowcount() >0)
{
foreach($query as $row)
{
$city=$row['city'];
$PackageId=$row['PackageId'];
$PackageName=$row['PackageName'];
$address=$row['address'];
$ChildPrice=$row['ChildPrice'];
$OperationHour=$row['OperationHour'];
$AdultPrice=$row['AdultPrice'];
$SeniorPrice=$row['SeniorPrice'];
$PackageFetures=$row['PackageFetures'];
$PackageImage=$row['PackageImage'];
?>
<div class="container">
<div class="holiday">
<div class="rom-btm">
<div class="col-md-3 room-left wow fadeInLeft animated" data-wow-delay=".5s">
<img src="admin/pacakgeimages/<?php echo $PackageImage; ?>" class="img-responsive" alt="">
</div>
<div class="col-md-6 room-midle wow fadeInUp animated" data-wow-delay=".5s">
<h4><?php echo $PackageName;?></h4>
<h6><b>Address : </b></h6><p><b><?php echo $address;?></b>
<h6><b>Operation Hour:</b></h6> <p><b><?php echo $OperationHour;?></b></p>
<h6><b>Features:</b></h6> <p><b><?php echo $PackageFetures;?></b></p>
</div>
<div class="col-md-3 room-right wow fadeInRight animated" data-wow-delay=".5s">
<h6><b>Child Price:</b> RM <?php echo $ChildPrice;?></h6>
<h6><b>Adult Price:</b> RM <?php echo $AdultPrice;?></h6>
<h6><b>Senior Price:</b> RM <?php echo $SeniorPrice;?></h6>
<a href="package-details.php?pkgid=<?php echo $PackageId;?>" class="view">Details</a>
</div>
</div>
</div>
</div>
<?php
}
}
else
{
echo 'no data';
}
}
else
{
echo 'error';
}
}
?>
日期选择器
function Datepicker() {
this.debug = false; // Change this to true to start debugging
this._curInst = null; // The current instance in use
this._keyEvent = false; // If the last event was a key event
this._disabledInputs = []; // List of date picker inputs that have been disabled
this._datepickerShowing = false; // True if the popup picker is showing , false if not
this._inDialog = false; // True if showing within a "dialog", false if not
this._mainDivId = 'ui-datepicker-div'; // The ID of the main datepicker division
this._inlineClass = 'ui-datepicker-inline'; // The name of the inline marker class
this._appendClass = 'ui-datepicker-append'; // The name of the append marker class
this._triggerClass = 'ui-datepicker-trigger'; // The name of the trigger marker class
this._dialogClass = 'ui-datepicker-dialog'; // The name of the dialog marker class
this._disableClass = 'ui-datepicker-disabled'; // The name of the disabled covering marker class
this._unselectableClass = 'ui-datepicker-unselectable'; // The name of the unselectable cell marker class
this._currentClass = 'ui-datepicker-current-day'; // The name of the current day marker class
this._dayOverClass = 'ui-datepicker-days-cell-over'; // The name of the day hover marker class
this.regional = []; // Available regional settings, indexed by language code
this.regional[''] = { // Default regional settings
closeText: 'Done', // Display text for close link
prevText: 'Prev', // Display text for previous month link
nextText: 'Next', // Display text for next month link
currentText: 'Today', // Display text for current month link
monthNames: ['January','February','March','April','May','June',
'July','August','September','October','November','December'], // Names of months for drop-down and formatting
monthNamesShort: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'], // For formatting
dayNames: ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'], // For formatting
dayNamesShort: ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'], // For formatting
dayNamesMin: ['Su','Mo','Tu','We','Th','Fr','Sa'], // Column headings for days starting at Sunday
weekHeader: 'Wk', // Column header for week of the year
dateFormat: 'yy-mm-dd', // See format options on parseDate
firstDay: 0, // The first day of the week, Sun = 0, Mon = 1, ...
isRTL: false, // True if right-to-left language, false if left-to-right
showMonthAfterYear: false, // True if the year select precedes month, false for month then year
yearSuffix: '' // Additional text to append to the year in the month headers
};
答案 0 :(得分:0)
要将日期选择器日期转换为一天,您可以使用
$_POST['date'] = date('l', strtotime($_POST['date']));
如果您的日以小写形式存储,则需要
$_POST['date'] = strtolower(date('l', strtotime($_POST['date'])));
因此您的实际查询可能类似于:
$sql = "SELECT * FROM tbltourpackages
WHERE city LIKE :city AND ChildPrice >= :minbudget AND AdultPrice <= :maxbudget AND yourDateColumn = :date";
$select = $db->prepare($sql);
$city= "%$_POST[city]%";
$select->bindParam(':city', $city, PDO::PARAM_STR);
$select->bindParam(':minbudget', $_POST['minbudget'], PDO::PARAM_STR);
$select->bindParam(':maxbudget', $_POST['maxbudget'], PDO::PARAM_STR);
$select->bindParam(':date', $_POST['date'], PDO::PARAM_STR);
$select->execute();
但是请不要忘记,您仍然需要在输入字段上使用value
标签。
此外,您永远不要直接在sql语句中使用$ _POST值。 Read this。