第二次发布此问题。希望我会得到一些必要的答案。
好吧,我是PHP的新手。我知道这是一个天真的问题,但我面临两个问题。
1)我应该根据所选的选项值显示div中字段'display_duration'
的数据(选择框选项是从表中的字段'priority'获取的)。当用户点击声明选择选项“高”时,持续时间(3-4周)应显示在Div。
我的第二个问题是计算调度和到达日期,并在单独的div标签中显示结果。格式应为'01-Jan-2017'(dd-MMM-yyyy)
。
arrival date = current date+arrival_interval_days(a field given in table);
同样适用于发货日期的计算。 到达和发送日期计算也基于所选的优先级选项。
感谢您的帮助。
答案 0 :(得分:0)
jquery应该有变化
$("#priority_duration").text(employeeData.display_duration);
此行应替换为
$("#priority_duration").html(employeeData.display_duration);
您要返回true
或false
以获取下拉选项,因此只有response data
而不是equals to(==)
才能获得(!== 0)
public function checkduration($priority_id){
$result = $this->db->query("SELECT priority_id, display_duration FROM tblpriority WHERE priority_id='".$priority_id."'");
$is_priority = $result->fetchAll();
if(count($is_priority)!== 0){
//return true;
//Here instead of return true you need to pass the data what you get in response
return $is_priority;
}
else{
return false;
}
}
如果我错了,请检查并告诉我。
error: main wallet password incorrect
第二个答案。
如果您正在计算表格中给出的current_date + interval的到达日期,那么如果您没有更新间隔,则每天都会更改日期。它将永远延伸到下一个日期。在表格中给定持续时间的间隔
答案 1 :(得分:0)
首先在order.php类中更改函数
public function checkduration($priority_id)
{
$result = $this->db->query("SELECT priority_id, display_duration,dispatch_interval_days,arrival_interval_days FROM tblpriority WHERE priority_id='" . $priority_id . "'");
$priorityData = $result->fetchAll();
return $priorityData;
}
而且,在ajax call()中,php文件应如下所示。
<?php
use Cosmo\ConfigSettings;
use Cosmo\DAL\Order;
//End
//Application/DB Configuration
$config = ConfigSettings::getInstance();
$basePath = $config->getBasePath();
//End
$response = [];
if (!empty($_REQUEST["priority_id"])) {
print_r($_REQUEST);
print_r($_REQUEST);
$priority_id = $_REQUEST['priority_id'];
$addUser = new Order();
$priorityData = $addUser->checkduration($priority_id);
$response['display_duration'] = '';
$response['dispatch_interval_days'] = '';
$response['arrival_interval_days'] = '';
if (!empty($priorityData)) {
$response['display_duration'] = $priorityData[0]['display_duration'];
$response['dispatch_interval_date'] = date('j-M-Y', strtotime("+{$priorityData[0][dispatch_interval_days]} days"), time());
$response['arrival_interval_date'] = date('j-M-Y', strtotime("+{$priorityData[0][arrival_interval_days]} days"), time());
}
}
header('Content-Type: application/json');
echo json_encode($response);
exit;
现在,您可以在客户端显示所有数据,并以格式(201-Jan-2018)计算到达和发送日期
并且还为到达和派遣添加了2个div,并按优先级填充了ajax响应值。
<?php
use Cosmo\ConfigSettings;
use Cosmo\DAL\Order;
//End
//Application/DB Configuration
$config = ConfigSettings::getInstance();
$priority_list_data = new Order();
$priority_data = $priority_list_data->getPriorityList();
$priority_option = '<option value=""></option>';
if ($priority_data != false) {
for ($i = 0; $i < count($priority_data); $i++) {
$priority_option .= '<option value= "' . $priority_data[$i]['priority_id'] . '" >' . $priority_data[$i]['priority'] . '</option>';
}
}
?>
<div class="panel-body">
<span class="pull-left">Priority:</span>
<select class="form-control" id="priority_selected">>
<?php echo $priority_option; ?>
</select>
<div class="small" id="priority_duration" ></div>
<div class="small" id="arrival_date" ></div>
<div class="small" id="dispatch_date" ></div>
</div>
<script type="text/javascript" src="/jquery.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
// code to get all records from table via select box
$("#priority_selected").change(function() {
var id = $(this).find(":selected").val();
var dataString = 'priority_id='+ id;
$.ajax({
url: '_getEmployee.php',
dataType: "json",
data: dataString,
cache: false,
success: function(employeeData) {
if(employeeData) {
$("#priority_duration").html(employeeData.display_duration);
$("#arrival_date").html(employeeData.arrival_interval_date);
$("#dispatch_date").html(employeeData.dispatch_interval_date);
} else {
$("#priority_duration").hide();
}
}
});
})
});
</script>