duanhuan7750 2019-01-29 05:41
浏览 79

表单在php中的ajax加载后提交后,无法保存多个复选框值

I have one simple form which has: From date, To date When i click on submit i get list of car bookings on ajax load. In each row there is a checkbox to select that row and after multiple selection of row a common button is clicked to add bill on next page. Now my problem is I want to select multiple rows and again fill from date, to date and then submit form to get other list to again select other rows to add bill, now the problem is when I again submit form the old selected rows does not get saved so that i can get all rows selected all together on bill page. Right now below snippets are all working correctly but i have no idea how to do this when form is filled again and selection is done. Below code is only doing selection of current page. 1. This is ajax script

<script> $("#button").click(function(){
document.getElementById("loading").style.display = "block"; 
document.getElementById("overlay").style.opacity = '0.2';
var toDate = $("#datepicker2").val();
var fromDate = $("#datepicker").val();  
// var comp = $("#comp").val();
var dataString = 'fromDate='+ fromDate + '&toDate='+ toDate;
$.ajax({
  url: 'CloseBookingload.php',
  data:dataString,
  type: 'POST',
  success: function(result){
          // console.log(result);
           $("#load").show();
          $("#resultData").html(result);
           document.getElementById("loading").style.display = "none"; 
           document.getElementById("overlay").style.opacity = '1';
        }
      }); });</script>

This is my ajax page checkbox field after loads

 <input type="checkbox" id="checkselect" name="checkselect[]" value="<?php echo $row['car_booking_id'];?>">

This where checkbox values are fetched

    $checkselect=array();
if(!empty($_POST['checkselect']))
{
    $checkselect=$_POST['checkselect']; 
    $nc = count($checkselect);
    for($i=0;$i<$nc;$i++)
    {
    $dids = $checkselect[$i];
    }
    $ids = join(",",$checkselect);
    $booking_car = $db->prepare("SELECT * FROM `car_booking`
    left join driver_master on driver_master.driver_id = car_booking.driver_id
    left join vendor_master on vendor_master.vendor_id=car_booking.vendor_name
    left join company_master on company_master.company = car_booking.company
    inner join city_master on city_master.city_id=car_booking.action
    WHERE booked_status=1 and car_booking.slip=1 and car_booking.car_booking_id in ($ids)  order by  str_to_date( booking_date,'%d/%m/%Y') asc ");
    $booking_car->execute();
    $MyArr=$booking_car->fetchall();
    // print_r($MyArr);
    // die;
    $booking_car2 = $db->prepare("SELECT * FROM `car_booking`
    left join driver_master on driver_master.driver_id = car_booking.driver_id
    left join vendor_master on vendor_master.vendor_id=car_booking.vendor_name
    left join company_master on company_master.company = car_booking.company
    inner join city_master on city_master.city_id=car_booking.action WHERE booked_status=1 and car_booking.slip=1 and car_booking.car_booking_id in ($ids) order by  str_to_date( booking_date,'%d/%m/%Y') asc ");
    $booking_car2->execute();
    $r2=$booking_car2->fetch();
}

for($i=0;$i<count($MyArr);$i++){

    $NewIDArr[$i][0]=$MyArr[$i]['car_booking_id'];
}
$Mixed = $NewIDArr;
$r = json_encode($Mixed);
$RequestText = urlencode($r);
?>
    <input type="hidden" name="RequestText" value="<?php echo $RequestText; ?>"> 
    <input type = "submit" name = "update" value = "Update">

First Page IMAGE Main Page IMAGE

The page where actual values are fetched and updated

<?php
                require_once '../dbconfig.php';
                $r = urldecode($_REQUEST['RequestText']);
                $Mixed = json_decode($r);
                $bill=$_POST['bill'];
                $remark=$_POST['remark'];

                //$RequestText = $_POST['RequestText'];
                $singleArray = []; 
                foreach ($Mixed as $childArray) 
                { 
                    foreach ($childArray as $value) 
                    { 
                    $singleArray[] = $value; 
                    } 
                }


                // print_r($singleArray);
                // print_r( $bill);
                // print_r($remark);
                // die;7615, 7631

                    $nc = count($singleArray);
                    //print_r($nc);
                        for($i=0;$i<$nc;$i++)
                        {
                        $did = $singleArray[$i];
                        $data=array('bill_no'=>$bill,'remark'=>$remark);
                        $where = array('car_booking_id' =>$did);    
                        $update = $db->update('car_booking',$data,$where)- 
                       >affectedRows();

                        }
                        header("Location:close_booking.php");
                            //echo "Updated";

    ?>
  • 写回答

1条回答 默认 最新

  • douliao8760 2019-01-29 08:51
    关注

    Now when you will send selected rows in arrays check id from session values of closed bookings and do your manipulation without hitting again and proceed for bill page. Create your session with closed bookings before sending response back to client server and store like as below:-

    Array
    (
    [closed_bookings] => Array
        (
            [123] => Array
                (
                    [name] => abc
                    [company_name] => abc pvt ltd
                    [id] => 123
                )
    
            [1234] => Array
                (
                    [name] => xyz
                    [company_name] => abc pvt ltd
                    [id] => 1234
                )
    
        )
    
    )
    

    Selected Rows values will be like..

    Array
    (
    [0] => 123,
    [1] => 1234
    )
    

    Now use foreach Loop with selected rows and get values from closed bookings with that key(value of selected value ex 123) and do you manipulation.

    评论

报告相同问题?

悬赏问题

  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制