简体   繁体   English

php pdo代码从表中选择日期并在所选日期添加+ 1个月

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

table name - receipt_entry 表名 - receipt_entry

column name - startingdate 列名 - 开始日期

I need to select startingdate from receipt_entry table and add + 1 month in selected date and display in another date textbox. 我需要从receipt_entry表中选择起始日期,并在所选日期中添加+ 1个月并显示在另一个日期文本框中。

For EX - 对于EX -

startingdate = 23-02-2015 then display 23-03-2015 in date textbox. startingdate = 23-02-2015 然后在日期文本框中显示23-03-2015。

this function works on selected event changed of listbox... 此功能适用于列表框更改的选定事件...

Every thing is working in my code except this date textbox..not getting proper date....this display wrong date in my textbox.. 每个东西都在我的代码中工作,除了这个日期文本框...没有得到正确的日期....这在我的文本框中显示错误的日期..

**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 page 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"));

Need To add months number ...how many months you want to add. 需要添加月份数...您要添加的月数。

 <?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);
    ?> 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM