php - return 2 or more variables separately from looped $.post() -


i'm developing textarea whatever pasted after push of button, added database. setting aside database function aside. achieve is:

  • return number of records posted
  • return number of records not inserted telling duplicate

jquery code

$(function(){ $('#sw').click(function(){   if($("#txta").val().length>0)    {     var h=confirm("are sure?");     if(h==true)     {         var fld=$("#txta").val().split('\n');         $.each(fld, function(){           $.post('up.php',           { 'ldta': this.split('\t') },           function(data) {             $('#out').append(data);           }           );         });         alert('upload completed');     }     else       alert("cancelled");   }   else   {     alert("textarea empty.");     $('#out').html('');   } }); }); 

php

 $setsu = dbsetsuzoku();//connection string stored on separate file     $ldta=$_post['ldta'];     $qsql='';     $dthk=0;     $qsql="select * bet bet_id=".$ldta[0];     $stmt = $setsu->query($qsql);     $rwk=$stmt->rowcount();     if ($rwk==0)     {       //post database code..     }     else        $lkaku.=$lines.", ";//$lines tell line not added if(!is_null($lkaku)) {   $hj='<table><tr style="background-color:#ff0000">';//displays record not added table red in color..   foreach ($ldta $key => $value) {           $hj.='<td>'.$value.'</td>';       }   $hj.='</tr></table>';   echo $hj; } else {   $hj='<table border="1"><tr>';//displays added record/line   foreach ($ldta $key => $value) {           $hj.='<td>'.$value.'</td>';       }   $hj.='</tr></table>';   echo $hj; } 

i noticed whatever echoed on php $.post() function on part

function(data) {     $('#out').append(data); } 

workarounds or ideas welcome.

using array in php code. , using return json.

$data['first'] = "firstdata"; $data['second'] = array(0=>"iam",1=>"cool");  echo json_encode($data); 

Comments

Popular posts from this blog

google chrome - Developer tools - How to inspect the elements which are added momentarily (by JQuery)? -

angularjs - Showing an empty as first option in select tag -

php - Cloud9 cloud IDE and CakePHP -