Reputation: 21
<?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--------------------------------------------------------------------
?>
Upvotes: 0
Views: 96
Reputation: 21
<?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
Upvotes: 0
Reputation: 5039
$cnt = 0;
$rows = array('John',123, 'Lloyds Office','Jane',124, 'Lloyds Office','Billy',125, 'London Office','Miranda', 126, 'Bristol Office');
$insertQry = "insert into MyTable ( Name, Id, Location) values ";
foreach($rows as $row) {
if($cnt == 3) {
$insertQry = rtrim($insertQry ,", ");
$insertQry .= "), ";
}
if($cnt > 2) {
$cnt = 0;
}
if($cnt == 0) {
$insertQry .= "(";
}
$insertQry .= $row.", ";
$cnt++;
}
$insertQry = rtrim($insertQry ,", ");
$insertQry .= ");";
Output:
insert into MyTable ( Name, Id, Location) values (John, 123, Lloyds Office), (Jane, 124, Lloyds Office), (Billy, 125, London Office), (Miranda, 126, Bristol Office);
Upvotes: 0
Reputation: 4637
Try array_chunk
i hope its helps to you
<?php
$row= array('John',123, 'Lloyds Office','Jane',124, 'Lloyds Office','Billy',125, 'London Office','Miranda', 126, 'Bristol Office');
$arraychuk = array_chunk($row, 3);
for($i=0;$i<count($arraychuk);$i++){
echo "<pre>".print_r($arraychuk[$i]);
insert into MyTable ( Name, Id, Location)
values ($arraychuk[$i][0], $arraychuk[$i][1], $arraychuk[$i][2]));
}
While using array_chunk
you will get something like this
Array
(
[0] => Jane
[1] => 124
[2] => Lloyds Office
)
Array
(
[0] => Billy
[1] => 125
[2] => London Office
)
Array
(
[0] => Miranda
[1] => 126
[2] => Bristol Office
)
Upvotes: 1