AJAX ve PHP ile düzenleme \ mysql

0 Cevap php

ziyaretleri bol i hepinizden faydalı yanıtlar buldu ve bu da bana sorun hakkında bir fikir vermek umuyoruz.

Temelde ajax ile mysql verileri düzenlemek için çalışıyorum. i aşağıdaki kodu ile yaptık.

Step 1- i loaded data from server with following script

$("#editselected,#addselected").live("click", function(){
   var whatto=$(this).attr('id');var edit_ids = new Array();
   $(".selectable:checked").each(function() {
   edit_ids.push($(this).attr('name'));
    });
   $("#editadd").load("ajaxloads/addedit.php?idarray="+edit_ids+"&action="+whatto,Hide_Load());
   //centerPopup();//loadPopup();
     }); 

AND ITs Server DATA is

if($selectall_action=='editselected'){   ?>
    <table id="main" class="editallmainwidth">
    <thead>
    <tr>
    <th scope="col" >Vendor</th>
    <th scope="col" >ItemType</th>
    <th scope="col" >ItemCode</th>
    <th scope="col" >ItemName</th>
    <th scope="col" >SerialNo</th>
    <th scope="col" >AssetCode</th>
    <th scope="col" >Ownership</th>
    <th scope="col" >PO</th>
    </tr>
    </thead>
    <tbody>
    <?php
   $ids= split(",",$selectall_id_array);
foreach($ids as $sid)
{

$stock=mysql_query("select * FROM $region where id='$sid'");

            while($q=mysql_fetch_array($stock))
            {
    echo "<tr>";      

    echo "<td width=\"5%\"><input type='hidden' name='id_all' value='{$q[8]}' /><input type='text'  name='vend_all' value='$q[0]' /></td>";
    echo "<td width=\"5%\"><input type='text' name='type_all' value='$q[1]' /></td>";
    echo "<td width=\"8%\"><input type='text' name='code_all' value='$q[2]' /></td>";
    echo "<td width=\"20%\"><input type='text' name='desc_all' value='$q[3]' /></td>";
    echo "<td width=\"10%\"><input type='text' name='seno_all' value='$q[4]' /></td>";
    echo "<td width=\"5%\"><input type='text' name='acode_all' value='$q[5]' /></td>";
    echo "<td width=\"2%\"><input type='text' name='os_all' value='$q[9]' /></td>";
    echo "<td width=\"5%\"><input type='text' name='porder_all' value='$q[12]' />  </td>";

    echo "</tr>";
            }

     }  
     ?>
      </tbody>
      </table>
      <fieldset id="add">
            <input type="submit" id='editall' name="Modify" value="EditAll" />   </fieldset>

Step-2 Then I edited The loaded text boxes filled with server data and send back ajax request to server

$("#editall").live("click", function(){

    var id_alledit = new Array();
    var vendor_alledit = new Array();
    var type_alledit = new Array();
    var code_alledit = new Array();
    var desc_alledit = new Array();
    var seno_alledit = new Array();
    var acode_alledit = new Array();
    var os_alledit = new Array();
    var po_alledit = new Array();

    var isedited=$("#editall").val();



$("input[name='id_all']").map(function(index) {
id_alledit.push($(this).attr('value'));
});

var tcount=$("input[name='id_all']").length;

 $("input[name='vend_all']").map(function(index) {
vendor_alledit.push($(this).attr('value'));
 });


 $("input[name='type_all']").map(function(index) {
 type_alledit.push($(this).attr('value'));
 });

 $("input[name='code_all']").map(function(index) {
code_alledit.push($(this).attr('value'));
});

 $("input[name='desc_all']").map(function(index) {
 desc_alledit.push($(this).attr('value'));
 });

 $("input[name='seno_all']").map(function(index) {
 seno_alledit.push($(this).attr('value'));
});

$("input[name='acode_all']").map(function(index) {
acode_alledit.push($(this).attr('value'));
});
$("input[name='os_all']").map(function(index) {
os_alledit.push($(this).attr('value'));
});
 $("input[name='porder_all']").map(function(index) {
po_alledit.push($(this).attr('value'));
});



jQuery.ajax({
type:"POST",url:"ajaxloads/addedit.php",
data:"&id_arrays=" + id_alledit + "&vend_arrays=" + vendor_alledit + "&type_arrays=" +         type_alledit + "&code_arrays=" + code_alledit + "&desc_arrays=" + desc_alledit +   "&seno_arrays=" + seno_alledit + "&os_arrays=" + os_alledit + "&acode_arrays=" +   acode_alledit + "&po_arrays=" + po_alledit + "&ifedited=" + isedited + "&tcount=" + tcount  ,
      complete:function(data){


 //$("#main").load("ajaxloads/addedit.php",null,function(responseText){ 
 //$("#main").html(responseText);
//$('tr:even',this).addClass("odd");
   alert(data.responseText);
 //}); 

   }
 }); 

  //disablePopup(); 
   return false;
  });

AND Updation was done with the following server side code

if(isset($_POST[ifedited])=='EditAll')

{

$id_count= $_POST[tcount];
$idarray=split(",",$_POST[id_arrays]);
$vendarray=split(",",$_POST[vend_arrays]);
$typearray=split(",",$_POST[type_arrays]);
$codearray=split(",",$_POST[code_arrays]);
$descarray=split(",",$_POST[desc_arrays]);
$senoarray=split(",",$_POST[seno_arrays]);
$acodearray=split(",",$_POST[acode_arrays]);
$osarray=split(",",$_POST[os_arrays]);
$poarray=split(",",$_POST[po_arrays]);
//print_r($idarray);

       for($i=0;$i<=$id_count;$i++)
 {
 //echo $id_count;
 echo $idarray[$i];
 echo $typearray[$i];
 echo $vendarray[$i];
 echo $codearray[$i];
 echo $descarray[$i];
 echo $senoarray[$i];
 echo $acodearray[$i];
 echo $osarray[$i];
 echo $poarray[$i];

 mysql_query("update Query");



 }

    }

*Every thing working fine but it seems like steps for this are being used are quite lengthy and may cause a performance issue. i Need if some can suggest me a better way of doing all this. Or if JSON is better option? and if it is then how i can Creat A JSON with associative arrays.

Teşekkürler *

0 Cevap