PHP json_encode JSON_NUMERIC_CHECK with 5808e70581507 - json

Hi I'm experiencing some difficulties with the json_encode function in PHP.
I have an object with a hash (uniq ID) but it can have this format 5808e70581507 and because of the "e" surrounded with numbers I think json_encode is trying to set this fellow as an integer.
My object looks like this :
stdClass Object
(
[id] => 16
[title] => userinf2
[desc] => Travail →
[startoff] => 2016-10-20 05:00:00
[stop] => 2016-10-20 13:00:00
[status] => 1
[allDay] => 0
[code_mode] => M
[uid] => 31250
[gid] => 502935
[recurrence_id] =>
[recurrence_mode] =>
[recurrence_repeat_every] =>
[recurrence_repeat_day] =>
[recurrence_end_mode] =>
[recurrence_end_date] =>
[recurrence_end_number] =>
[multiple_timeschedule_id] => 5808e70581507
[start] => 2016-10-20 05:00:00
[end] => 2016-10-20 13:00:00
[color] => #7AE7BF
[className] => working uid_31250 code_mode_M gid_502935
)
Is there a way to make this working as it is ?
The code :
echo json_encode($events[6], JSON_NUMERIC_CHECK);
var_dump($events[6]->multiple_timeschedule_id); // string(13)
Assignment code :
function _oms_planning_planning_get()
{
try {
global $user;
$intervenants = _oms_planning_get_cab_intervenants();
$sql = 'SELECT * FROM planning_event WHERE 1=1 AND (';
$params_sql = array();
foreach ($intervenants as $key => $a_user) {
$sql .= ' uid =:uid' . $key . ' OR ';
$params_sql[':uid' . $key] = $a_user->uid;
}
$sql = substr($sql, 0, -3);
$sql .= ')';
$result = db_query($sql, $params_sql);
$db_events = $result->fetchAll();
$events = array_map(function ($db_event) use ($intervenants) {
$db_event->start = $db_event->startoff;
$db_event->end = $db_event->stop;
$db_event->color = (isset($db_event->gid) && intval($db_event->gid) > 0) ?
_oms_planning_planning_get_color_from_gid($db_event->gid) :
_oms_planning_planning_get_color_from_uid($intervenants, $db_event->uid);
$db_event->className = ($db_event->status == 1) ? 'working ' : 'idleness ';
$db_event->className .= 'uid_' . $db_event->uid . ' ';
$db_event->className .= 'code_mode_' . $db_event->code_mode . ' ';
$db_event->className .= 'gid_' . $db_event->gid;
return $db_event;
}, $db_events);
return $events;
} catch (Exception $e) {
print_r($e);
}
}
Mysql column type : multiple_timeschedule_id varchar(200) utf8_general_ci

Related

how to create short code for data array sql

i'm already can insert data into database using below query. But i want to shortening code for my a few column name because my it just like a continues number. i already explode mark by m1=A, m2=B, m3=C, m4=A and continue..
Below is my controller:
$mark = 'ABCADDBBAACBCDDABBCA';
$totalquestion = '10';
for($i=0; $i<$totalquestion; $i++):
$no = $i+1;
$m = substr($mark, 0, $no);
endfor;
$data[] = array(
'TotalQuestion' => $totalquestion,
'Mark' => $mark,
'm1' => $m[0],
'm2' => $m[1],
'm3' => $m[2],
'm4' => $m[3],
'm5' => $m[4],
'm6' => $m[5],
'm7' => $m[6],
'm8' => $m[7],
'm9' => $m[8],
'm10' => $m[9],
'm11' => $m[10],
'm12' => $m[11],
'm13' => $m[12],
'm14' => $m[13],
'm15' => $m[14],
'm16' => $m[15],
'm17' => $m[16],
'm18' => $m[17],
'm19' => $m[18],
'm20' => $m[19]
);
$this->excel_import_model->insert($data);
This is my result:
My question is how to re-code for my data[] array so i dont need to type manually m1, m2, m3 till m20. Sorry for my bad english
$mark = 'ABCADDBBAACBCDDABBCA';
$totalquestion = '20';
$data = array();
$data = array(
'TotalQuestion' => $totalquestion,
'Mark' => $mark,
);
//Split String into array
$list = str_split($mark);
$mlist = array();
//Loop through splited string
for($i=0; $i<$totalquestion; $i++):
$mlist['m'.$i] = $list[$i];
endfor;
//Merge here or you an even use push array in for loop itslef
$data = array_merge($data,$mlist);

JSON to VB.NET Deserialize Coding

I have a column in a table where all the details of the bill are getting stored. My brother used PHP web project to do that. Now I am trying to deserialize in VB.NET
Here is the PHP code (Controller)
public function add_to_list() {
$this->load->model('product_model', 'Product');
$pdts = $this->Product->get_data(true);
$available = $this->in_cart($this->input->post('id'));
$cart_qty = $available ? $available : 0;
if (!is_numeric($this->input->post('qty')) || !$this->input->post('id')) {
$res['success'] = false;
$res['msg'] = "Please enter the valid input";
} else {
$discount_percentage = $this->input->post('discount_percentage') ? $this->input->post('discount_percentage') : 0;
$discount_rate = $pdts->selling_price * ($discount_percentage / 100);
$final = $pdts->selling_price - $discount_rate;
$igst = $pdts->igst;
$igst_amt = calculate_price_by_precentage($this, $final, $pdts->igst);
$gross = $pdts->selling_price;
$total = $final + $igst_amt;
// $total = $gross + $igst_amt;
$available_qty = 5;
$data = array(
'id' => $pdts->id,
'qty' => $this->input->post('qty'),
'price' => $pdts->final_price,
'name' => $pdts->product,
'options' => array(
'product_id' => $pdts->id,
'product_hsn' => $pdts->hsn,
'product_name' => $pdts->product,
'product_unit' => $pdts->unit,
'product_rate' => $pdts->selling_price,
'product_mrp' => $pdts->mrp,
'product_gst' => $pdts->igst,
'product_cgst' => $pdts->cgst,
'product_gst_amount' => $igst_amt * $this->input->post('qty'),
'product_net_rate' => $pdts->cost_price,
'product_qty' => $this->input->post('qty'),
'product_free' => 0,
'product_discount_percentage' => $discount_percentage,
'product_discount_rate' => $discount_rate,
'product_total' => $total * $this->input->post('qty'),
'available_qty' => $available_qty,
'category' => $pdts->category,
'rate' => $pdts->selling_price,
'gross' => $gross,
'igst' => $igst,
'cgst' => $igst / 2,
'sgst' => $igst / 2,
'igst_amount' => $igst_amt,
'cgst_amount' => $igst_amt / 2,
'sgst_amount' => $igst_amt / 2,
'total' => $total //final_price($this, $pdts->selling_price, calculate_price_by_precentage($this, $pdts->selling_price, $pdts->discount), calculate_price_by_precentage($this, $pdts->selling_price, $pdts->sgst))
)
);
$this->cart->insert($data);
$this->pageViewData['final_discount'] = $this->input->post('discount') == '' ? '0' : $this->input->post('discount');
$this->pageViewData['final_discount_percentage'] = $this->input->post('discount_percentage') == '' ? '0' : $this->input->post('discount_percentage');
$this->pageViewData['ajax'] = true;
$res['success'] = true;
$res['msg'] = $this->load->view('order/cart_item', $this->pageViewData, true);
}
echo json_encode($res);
}
And this is how the cell Value looks.
> a:1:{s:32:"b3712e169500f4754be4a6a681220a96";a:7:{s:2:"id";s:2:"69";s:3:"qty";d:1;s:5:"price";d:26.25;s:4:"name";s:28:"Seeded
> Dates 200gm Wet
> Dates";s:7:"options";a:26:{s:10:"product_id";s:2:"69";s:11:"product_hsn";s:8:"08041020";s:12:"product_name";s:28:"Seeded
> Dates 200gm Wet
> Dates";s:12:"product_unit";s:2:"GM";s:12:"product_rate";s:5:"26.25";s:11:"product_mrp";s:2:"35";s:11:"product_gst";s:2:"12";s:12:"product_cgst";s:1:"6";s:18:"product_gst_amount";d:3.149999999999999911182158029987476766109466552734375;s:16:"product_net_rate";s:5:"24.70";s:11:"product_qty";s:1:"1";s:12:"product_free";i:0;s:27:"product_discount_percentage";i:0;s:21:"product_discount_rate";d:0;s:13:"product_total";d:29.39999999999999857891452847979962825775146484375;s:13:"available_qty";i:5;s:8:"category";s:9:"AD
> Seeded";s:4:"rate";s:5:"26.25";s:5:"gross";s:5:"26.25";s:4:"igst";s:2:"12";s:4:"cgst";i:6;s:4:"sgst";i:6;s:11:"igst_amount";d:3.149999999999999911182158029987476766109466552734375;s:11:"cgst_amount";d:1.5749999999999999555910790149937383830547332763671875;s:11:"sgst_amount";d:1.5749999999999999555910790149937383830547332763671875;s:5:"total";d:29.39999999999999857891452847979962825775146484375;}s:5:"rowid";s:32:"b3712e169500f4754be4a6a681220a96";s:8:"subtotal";d:26.25;}}
That looks a lot to me. As a beginner, I need a big help from you guys to get this done.

fetch data from array and save it in database

I had this code
echo "<pre>";
print_r($data);
echo "</pre>";
through which i got the following data
Spreadsheet_Excel_Reader Object
(
[sheets] => Array
(
[0] => Array
(
[maxrow] => 0
[maxcol] => 0
[numRows] => 2
[numCols] => 5
[cells] => Array
(
[1] => Array
(
[1] => sno
[2] => candidta name
[3] => email
[4] => ctc
[5] => location
)
)
)
)
)
I needed numCols so i used the following code
echo $data->sheets[0]['numCols'];
and got the result 5
Now i wish to fetch the following values
[1] => sno
[2] => candidta name
[3] => email
[4] => ctc
[5] => location
and store them in the table like this
id value
1 sno
2 candidta name
3 email
4 ctc
5 location
Can anyone please tell how it can be done
$Data = array();
foreach($data->sheets[0]['cells']['1'] as $key=>$value):
$Data[] = "('".$key."','".$value."')";
endforeach;
mysql_query("INSERT INTO tbl_name(`id`,`value`) VALUES".implode(",",$Data)) or die (mysql_error());
$newarray = $data->sheets[0]['cells'][1];
for ( $i=1; $i < count($newarray); $i++)
{
echo $newarray[$i];
$sql= "INSERT INTO `tablename` (value) VALUES ('$newarray[$i]')";
if(!mysqli_query($con,$sql))
{
echo "Error: " . $sql. "<br>" . mysqli_error($con);
}
}

Import categories with magmi datapump

This is an example of my category CSV.
I never used datapump and I can't find any sample code.
I use this code to create a category tree:
ini_set('display_errors', '1');
error_reporting(E_ALL);
set_time_limit(0);
$url = "www.xxxxxxxxx.com/category.csv";
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
$app = Mage::app('default');
$exit= 0;
$continua = 0;
$cont = 0;
$f = fopen('php://temp', 'w+');
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_FILE, $f);
curl_exec($curl);
curl_close($curl);
rewind($f);
function searchForId($id, $array) {
foreach ($array as $key => $val) {
if ($val['id'] === $id) {
return $val['nombre'];
}
}
return null;
}
while (($data = fgetcsv($f, 10000 , ",")) !== FALSE ) {
$fila="";
foreach($data as $row) {
$fila= $fila.$row;
}
$datos = explode(";",$fila);
// ID_CATEGORY CATEGORY_NAME Father_CATEGORY
$clave = $datos[0];
$cat = $datos[1];
$padre = $datos[2];
$categoria[$cont] = array ('id'=>$clave, 'nombre'=>$cat);
$nomPad = searchForId($padre,$categoria);
}
Example Result:
[21] => Array
(
[id] => 160
[name] => Madera de Teca
)
[22] => Array
(
[id] => 163
[name] => Polyrattan Natur
)
[23] => Array
(
[id] => 165
[name] => Polyrattan / acero / cristal
)
[24] => Array
(
[id] => 166
[name] => Polyrattan / forja / cristal
)
How can use this in magmi datapump?
Do I need to import a category creator plugin? How can I combine the sample code with my own.

Insert data with insert_batch

I'm using the following statement to insert data in mysql with codeigniter.
$this->db->insert_batch($table, $query);
$query is generated dynamically can have different number of columns on each array element
and maybe the number of elements may differ on condition
array (
0 => array(
'column1'=>'insert1',
'column2'=>'insert2'
),
1 => array(
'column1'=>'insert1';
'column2'=>'insert2',
'column4'=>'insert4'
)
)
could this cause an error or handles codigniter from deafult?
I'm building up the query as it follows
foreach ($sql_xml as $children) {
$children = $this->xml2array($children);
foreach ($children as $index => $child) {
if ($child != 'feed_id') {
$keys[$index] = $child;
}
}
}
switch (strtolower($this->config[0]->affiliate)) {
case 'case1':
$target_xml = $target_xml->productItems;
break;
case 'case2':
$target_xml = $target_xml;
break;
default :
break;
}
$query = array();
$data = array();
foreach ($target_xml as $feeds) {
$feeds = $this->xml2array($feeds);
$columns = new RecursiveIteratorIterator(new RecursiveArrayIterator($feeds));
foreach ($columns as $index => $column) {
if (array_key_exists($index, $keys)) {
if($column != ''){
$data[$keys[$index]] = $column;
$data['feed_id'] = $this->id;
}
//*TODO //$data['affiliate'] = "'.$this->config[0]->affiliate.'";
}
}
$query[] = $data;
}
if (count($query > 0)) {
foreach ($query as $t){
$this->db->insert($table, $t);
}
}
The array's would need to have the same amount of "columns".
So what I would recommend is the following (setting certain columns to null if no there is no data):
array (
0 => array(
'column1' => 'insert1',
'column2' => 'insert2',
'column3' => null,
'column4' => null
),
1 => array(
'column1' => 'insert1',
'column2' => 'insert2',
'column3' => 'insert3',
'column4' => 'insert4'
)
)
Also, your syntax is invalid and it would cause an error since you are using a ; instead of an , on the first column insert.