php - Datatable Requested unknown parameter '1' for row -
i have following datatable
<br><button id="addrow">add new row</button><br> <table class="table table-striped table-bordered table-hover " id="example" cellspacing=0 width="100%"> <thead> <tr> <th>image</th> <th>number</th> <th>creation_date</th> <th>ei</th> <th>name</th> <th>profit</th> </tr> </thead> <?php foreach ( $data_req_table $k => $v ) : ?> <tr style="text-align: center;"> <td> <img width="100px" data-original="image.jpg" src="image.jpg" /> </td> <td><? echo $v['number']; ?></td> <td><? echo $v['creationdate']; ?></td> <td><? echo $v['ei']; ?></td> <td><? echo $v['name']; ?></td> <td><? echo $v['profit']; ?></td> </tr> <?php endforeach; ?> </table>
on add rows trough jquery - ajax script. following :
<script type="text/javascript"> $(document).ready(function () { debugger; var t = $('#example').datatable({ "searching": true, //"paging": true, "order": [[ 2, "desc" ]], alengthmenu: [ [25, 50, 100, 200, -1], [25, 50, 100, 200, "all"] ], idisplaylength: -1 }); var counter = 1; $('#addrow').on('click', function ciicici() { var = new date(); var = now.tomysqlformat(); var tii = new date(); tii.setseconds(tii.getseconds() - 15); var tii = tii.tomysqlformat(); //alert(tii); $.post( "sql.php", { timing: now,seconding: tii })//.done({}); .done(function( data ) { var dataparts = data.split("##") var lenghtylenght = dataparts.length; (i = 0; <= lenghtylenght; i++) { var datapart = dataparts[i]; var splitdata = datapart.split("///"); t.row.add([ splitdata[0], splitdata[1], splitdata[2], splitdata[3], splitdata[4], splitdata[5] ]).draw(); alert('done'); } counter++; }); //settimeout(function(){ciicici();}, 15000); }); $('#addrow').click(); }); </script>
and php being
$ippi = 0; foreach ( $data_rreq $k => $v ) : //data_rreq pdo fetched array $ippi++; echo "<td><img width='100px' src='image.jpg' /></td>".'///'; echo '<td>'.$v['number'].'</td>'.'///'; echo '<td>'.$v['creationdate'].'</td>'.'///'; echo '<td>'.$v['ei'].'</td>'.'///'; echo '<td>'.$v['name'].'</td>'.'///'; echo '<td>'.$v['profit'].'</td>'; if($ippi < $len){ echo "##"; } endforeach;
the code works have 2 problems :
1) datatable problem, everytime row automatically added, error : requested unknown parameter '1' row ... . looks loops once much, doesn't find results , has error. datatable reference being following :
<script src="http://cdnjs.cloudflare.com/ajax/libs/datatables/1.10.0/js/jquery.datatables.min.js"></script>
2) , wanted ask wether there way avoid using split function puss 5 different parameters request, using may sort of json encoded arrays.
markoc
i think loop need patched:
for (i = 0; <= lenghtylenght; i++)
replace with:
for (i = 0; < lenghtylenght; i++)
else go outofindex.
Comments
Post a Comment