ROHIT JHA ROHIT JHA - 3 months ago 11
JSON Question

not able to fetch huge amonut of data in json php

<?php
i am using limit suppose 2000 it is fetch data but without using limit it is not fetching data
$db=new PDO('mysql:dbname="";host=;','','',array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'"));

$str_id=$_POST['Store_Id'];
$row=$db->prepare("select Store_Id from store where Store_Id='$str_id'");
$row->execute();//execute the query
header("content-type:application/json");
$json_data=array();//create the array
foreach($row as $rec)//foreacc loop
{
$Store_id=$rec['Store_Id'];



array_push($json_data,$json_array);
}
header("content-type:application/json");



//-------------------------------------------------------------------------------------retail_str_po_detail_hold-----------------------------------------------------------------//

$row49=$db->prepare("SELECT * FROM storeprod where S_Flag='0' and Store_Id='$Store_id'");
$row49->setFetchMode(PDO::FETCH_ASSOC);

$row49->execute();//execute the query
$json_data49=array();//create the array

$json_arr=array();
while($record49=$row49->fetch())
{
foreach($record49 as $rec49)//foreacc loop
{
$json_array49['field']=$rec49;
$array_push($json_data49,$json_array49);
}
}


i am using limit suppose 2000 it is fetch data but without using limit it is not fetching data

$result['Retail_store_prod_com'] =$json_data49;
echo json_encode($result,JSON_PRETTY_PRINT);
$json_arr = json_encode($result,JSON_PRETTY_PRINT);
//-----------------------------------------------------sucessresponse--------------------------------------------------------------------

?>

Answer
<?php

$row= array('John',123, 'Lloyds Office','Jane',124, 'Lloyds Office','Billy',125, 'London Office','Miranda', 126, 'Bristol Office');
$arraychuk = array_chunk($row, 3);

foreach ($arraychuk as $array_num => $array) {
  echo "Array $array_num:\n";
 }


?>

//you can easily chunk like which will break into a perfect array

Comments