coupon = 700,701,702,703
startdate = 25-02-2015
现在我需要计算优惠券栏的价值。
例如 - 现在优惠券列中有4个值。
现在我需要当我搜索700时,它选择startdate并在startdate中添加+1个月boz 700处于第1位并生成如下输出
for ex - 25-03-2015
当我搜索701然后它获得startdate并且在startdate中获得+2个月boz 701处于第二位并生成如下输出
for ex - 25-04-2015
当我搜索702然后它获得startdate并且+3个月boz 702处于第3位,对所有人来说都是明智的。
for ex - 25-05-2015
并将结果返回generateddate
变量以便插入数据库。
<?php
if(!empty($_GET['q'])) {
$db = new PDO('mysql:host=localhost;dbname=circulation_scheme_prepaid', 'root', '');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$q = $_GET['q'];
$result = $db->prepare('SELECT * FROM receipt_entry WHERE coupon = :coupon');
$result->execute(array(':coupon' => "$q"));
$data = $result->fetchAll(PDO::FETCH_ASSOC);
$info = array();
foreach($data as $row) {
$coupon = $row['coupon'];
$startingdate = $row['startingdate'];
$temp = explode(',', $coupon);
$key = array_search($search_word, $temp);
$inc_month = $key + 1;
$generateddate = date('d-m-Y', strtotime("+$inc_month months", strtotime($startingdate )));
$info[] = array('date' =>$generateddate );
}
echo json_encode($info);
}
?>
<!--AUTO POPULATE TEXTBOX ON COMBOBOX CHANGED EVENT START -->
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.1/jquery.min.js" type="text/javascript"></script>
<script>
function showUser(str)
{
if (str=="")
{
document.getElementByName("cityname").value="";
return;
}
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
var data = JSON.parse(xmlhttp.responseText);
for(var i=0;i<data.length;i++)
{
document.getElementById("generateddate").value = data[i].date;
}
}
}
xmlhttp.open("GET","coupondata.php?q="+str,true);
xmlhttp.send();
}
</script>
<input type="text" name="coupon" id="coupon" onChange="showUser(this.value)" class="field size4" />
答案 0 :(得分:0)
爆炸后试试这个:
$coupon = $row['coupon'];
$startingdate = $row['startingdate'];
$temp = explode(',', $coupon);
$key = array_search($search_word, $temp);
$inc_month = $key + 1;
$generateddate = date('d-m-Y', strtotime("+$inc_month months", strtotime($startingdate )));