php pdo 代码从 table 到 select 日期并在 selected 日期添加 +1 个月

php pdo code to select date from table and add +1month in selected date

table 姓名 - receipt_entry

列名称 - 开始日期

我需要 select 从 receipt_entry table 开始日期并在 select 日期中添加 + 1 个月并显示在另一个日期文本框中。

对于EX -

开始日期 = 23-02-2015 然后在日期文本框中显示 23-03-2015。

此函数适用于列表框的 selected 事件更改...

除了这个日期文本框之外,我的代码中的所有东西都在工作..没有得到正确的日期....这个在我的文本框中显示错误的日期..

**Index.php page** 

     <!--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>
     <!--AUTO POPULATE TEXTBOX ON COMBOBOX CHANGED EVENT ENDS -->


    <select class="special-flexselect"  name="coupon" tabindex="1" onChange="showUser(this.value)">                 
                            <option  value="" ></option>                        
                             <?php foreach ($loadcoupon as $coup){ ?>   
                                <option  value="<?php echo $coup["coupon"]; ?>"><?php echo $coup["coupon"]; ?></option>
                            <?php }?>
                            </select>

<input type="text" name="generateddate" id="generateddate"  value="" class="field size4" />

coupondata.php 页

  <?php
    require_once('includes/config.php');
    $q = $_GET['q'];
    $city = $database->getRows("SELECT * FROM receipt_entry WHERE coupon = :coupon", array(':coupon'=>"$q"));  
    $info = array();
    foreach($city as $row)
    {    
        $startingdate = $row['startingdate'];   
        $generateddate = date("d-m-Y", strtotime($startingdate . " +" . " MONTHS"));    
        //$generateddate = date("d-m-Y", strtotime($startingdate) . " + MONTHS");

        $cWeb[] = $row['customer_name'];
        $receipt = $row['receipt_no'];
        $book = $row['book_no'];
        $booking = $row['bookingdate'];      
        $info[] = array('web' => $cWeb,'rec' =>$receipt,'book' =>$book,'booking' =>$booking,'date' =>$generateddate );
    }
    echo json_encode($info);
    ?> 

您需要告诉您要添加多少个月,php默认情况下不知道

    $generateddate = date("d-m-Y", strtotime($startingdate . " + 1 MONTHS"));    
$generateddate = date("d-m-Y", strtotime("$startingdate + 1 MONTH"));

需要添加月数...您要添加多少个月。

 <?php
    require_once('includes/config.php');
    $q = $_GET['q'];
    $city = $database->getRows("SELECT * FROM receipt_entry WHERE coupon = :coupon", array(':coupon'=>"$q"));  
    $info = array();
    foreach($city as $row)
    {    
        $startingdate = $row['startingdate'];   
        $generateddate = date("d-m-Y", strtotime($startingdate . " +" . " 1MONTHS"));   
        //$generateddate = date("d-m-Y", strtotime($startingdate) . " + MONTHS");

        $cWeb[] = $row['customer_name'];
        $receipt = $row['receipt_no'];
        $book = $row['book_no'];
        $booking = $row['bookingdate'];      
        $info[] = array('web' => $cWeb,'rec' =>$receipt,'book' =>$book,'booking' =>$booking,'date' =>$generateddate );
    }
    echo json_encode($info);
    ?>