Below is the code snippet for printing values in a PDF report using codeigniter.
foreach ($data as $key => $getData)
{
$html1 = $this->load->view('pdf/pod2', $getData, true);
//echo $html;exit;
$this->load->library('pdf');
$pdf = $this->pdf->load();
$pdf->setAutoTopMargin = 'stretch';
$pdf->setAutoBottomMargin = 'stretch';
//$pdf->SetFooter($_SERVER['HTTP_HOST'].'|{PAGENO}|'.date(DATE_RFC822));
$pdf->WriteHTML($html1);
}
If i do echo '<pre>';print_r($data);exit;
I get the following output
Array
(
[316] => Array
(
[CNote] => stdClass Object
(
[Consignment_Details_id] => 316
)
[Invoice_Nos] => Array
(
[0] => stdClass Object
(
[invoice] => 161052
)
[1] => stdClass Object
(
[invoice] => 161053
)
)
[Invoice_Copies] => Array
(
)
[CNote_data] => Array
(
)
[no_packages] => 0
[driver] =>
)
[317] => Array
(
[CNote] => stdClass Object
(
[Consignment_Details_id] => 317
)
[Invoice_Nos] => Array
(
[0] => stdClass Object
(
[invoice] => 161066
)
)
[Invoice_Copies] => Array
(
)
[CNote_data] => Array
(
)
[no_packages] => 0
[driver] =>
)
[318] => Array
(
[CNote] => stdClass Object
(
[Consignment_Details_id] => 318
)
[Invoice_Nos] => Array
(
[0] => stdClass Object
(
[invoice] => 161067
)
)
[Invoice_Copies] => Array
(
)
[CNote_data] => Array
(
)
[no_packages] => 0
[driver] =>
)
)
Now the problem is in the pdf report only the last array values is being displayed
i.e 318
Actual scenario what i need is o display three array values but only last value is getting displayed. How to solve this, any help appreciated.
Related
I have an array coming as below which is dynamic. Now I want to edit a specific array for "BHD0000000002". I am getting the following array through ajax request. However I cannot edit the inner array element. For example, I am trying to edit the inner array value for the key "BHD0000000002" but unable to fix the issues. Can anyone help sir/madam?
This is the original array:
$budget_detail_array=Array
(
[0] => Array
(
[BHD0000000001] => 10000
)
[1] => Array
(
[BHD0000000002] => 12212121
)
[2] => Array
(
[BHD0000000003] => 212121
)
[3] => Array
(
[BHD0000000004] => 212121
)
[4] => Array
(
[BHD0000000005] => 212121
)
[5] => Array
(
[BHD0000000006] => 2121
)
[6] => Array
(
[BHD0000000007] => 2121
)
[7] => Array
(
[BHD0000000008] => 21221
)
[8] => Array
(
[BHD0000000009] => 2112212
)
)
I want to edit the above array as :
Array
(
[0] => Array
(
[BHD0000000001] => 10000
)
[1] => Array
(
[BHD0000000002] => 5000
)
[2] => Array
(
[BHD0000000003] => 212121
)
[3] => Array
(
[BHD0000000004] => 212121
)
[4] => Array
(
[BHD0000000005] => 212121
)
[5] => Array
(
[BHD0000000006] => 2121
)
[6] => Array
(
[BHD0000000007] => 2121
)
[7] => Array
(
[BHD0000000008] => 21221
)
[8] => Array
(
[BHD0000000009] => 2112212
)
)
So far I have tried with the following code but it is not working. Anyone can help?
foreach($budget_detail_array as $key=>$value){
foreach($value as $keyval=>$val){
if($keyval=='BHD0000000002'){
$val=5000;
}
}
/*if($value[$budget_id]){
$value[$budget_id]=100;
}else{
$value[$budget_id]=700;
}*/
}
print_r($budget_detail_array);exit;
In order to modify an associative array value you can do this:
$budget_detail_array[1]['BHD0000000002'] = 5000;
And then check the result again
print_r($budget_detail_array);
I have JSON arrays of objects. I am trying to sort an array using usort. I want to use value field from field_listing_order. It sorted using value. I am missing something but not able to figure it out. please review the code. Thanks!
stdClass Object
(
[node_title] => abc
[nid] => 2281
[field_api_order_value] => 201
[field_node_entity_type] => node
[_data] => Array
(
[nid] => Array
(
[entity_type] => node
[entity] => stdClass Object
(
[title] => abc
[field_listing_order] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 8
[format] =>
[safe_value] => 8
)
)
)
)
)
)
)
stdClass Object
(
[node_title] => abc
[nid] => 2243
[field_api_order_value] => 204
[field_node_entity_type] => node
[_data] => Array
(
[nid] => Array
(
[entity_type] => node
[entity] => stdClass Object
(
[title] => abc
[field_listing_order] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 3
[format] =>
[safe_value] => 3
)
)
)
)
)
)
) stdClass Object
(
[node_title] => abc
[nid] => 2431
[field_api_order_value] => 242
[field_node_entity_type] => node
[_data] => Array
(
[nid] => Array
(
[entity_type] => node
[entity] => stdClass Object
(
[title] => abc
[field_listing_order] => Array
(
[und] => Array
(
[0] => Array
(
[value] => 1
[format] =>
[safe_value] => 1
)
)
)
)
)
)
)
and So on ...
foreach ($view->result as $result) {
$node = $result->_data['nid']['entity'];
$listing_order = $node->field_listing_order[LANGUAGE_NONE][0];
.....
// code goes here and it works well. sorting issue
}
usort ($node->field_listing_order[LANGUAGE_NONE][0], function($a, $b){
return strcmp($a->value, $b->value);
}); ?>
If you need to sort all the nodes using the field_listing_order value, you need to compare the values along the full path, from the first object to the value:
usort($view->result, function($a, $b) {
$la = $a->_data['nid']['entity']->field_listing_order[LANGUAGE_NONE][0]['value'];
$lb = $b->_data['nid']['entity']->field_listing_order[LANGUAGE_NONE][0]['value'];
return $la - $lb ;
});
In this case $a and $b are two different nodes which could be compared. That why you should compare the field_listing_order's value of these nodes. The answer is working with $la- $lb
I am success to import email contact with yahoo Oauth API. And I can see that all my contact email is listed in the page when I echo it. However, while it success to print the email, there is an error message there :
Trying to get property of non-object in globalses.php on line 295 AND
Undefined offset: 1 in globalses.php on line 295
This is the code who shows that error:
if (! empty($response)) {
list($info, $header, $body) = $response;
if ($body) {
//logit("callcontact:INFO:response:");
//print(json_pretty_print($body));
$yahoo_array = json_decode($body);
echo "<pre/>";
//print_r($yahoo_array);
foreach($yahoo_array as $key=>$values){
foreach($values->contact as $keys=>$values_sub){
// echo '<pre/>';
// print_r($values_sub);
// echo $values_sub->fields[1]->value->givenName;
$email = $values_sub->fields[1]->value; //This is line 295
if(trim($email)!="")
$newList .= $email.",";
}
}
}
$retarr = $newList."";
}
return $retarr;
[UPDATE] Th print result of $values->contact
Array
(
[0] => stdClass Object
(
[isConnection] =>
[id] => 50331977
[fields] => Array
(
[0] => stdClass Object
(
[id] => 50332026
[type] => email
[value] => academic_interlingua#cbn.net.id
[editedBy] => OWNER
[flags] => Array
(
)
[categories] => Array
(
)
)
)
[categories] => Array
(
)
[error] => 0
[restoredId] => 0
)
[1] => stdClass Object
(
[isConnection] =>
[id] => 41
[fields] => Array
(
[0] => stdClass Object
(
[id] => 63
[type] => email
[value] => access#sampoernafoundation.org
[editedBy] => OWNER
[flags] => Array
(
)
[categories] => Array
(
)
)
)
[categories] => Array
(
)
[error] => 0
[restoredId] => 0
)
[2] => stdClass Object
(
[isConnection] =>
[id] => 50331986
[fields] => Array
(
[0] => stdClass Object
(
[id] => 50332036
[type] => email
[value] => activeindonesia#yahoo.com
[editedBy] => OWNER
[flags] => Array
(
)
[categories] => Array
(
)
)
[1] => stdClass Object
(
[id] => 50332037
[type] => guid
[value] => APQMLKWC3QLQRAMYZQABSF63ZA
[editedBy] => OWNER
[flags] => Array
(
[0] => Y360
)
[isConnection] =>
[categories] => Array
(
)
)
)
[categories] => Array
(
)
[error] => 0
[restoredId] => 0
)
[UPDATE]
foreach($values->contact as $keys=>$values_sub){
if(property_exists($values_sub, 'value') && !is_array($values_sub->value))
//echo $values_sub->fields[1]->value->givenName;
$email = $values_sub->fields[1]->value;
if(trim($email)!="")
$newList .= $email.",";
[UPDATE] the result of var_dump
academic_interlingua#cbn.net.idstring(31) "academic_interlingua#cbn.net.id"
access#sampoernafoundation.orgstring(30) "access#sampoernafoundation.org"
APQMLKWC3QLQRAMYZQABSF63ZAstring(26) "APQMLKWC3QLQRAMYZQABSF63ZA"
activeindonesia#yahoo.comstring(25) "activeindonesia#yahoo.com"
ade.nugraha#bisnis.co.idstring(24) "ade.nugraha#bisnis.co.id"
IKN34TUEMHOJNOBUJQP5D2CBDQstring(26) "IKN34TUEMHOJNOBUJQP5D2CBDQ"
adebete#yahoo.comstring(17) "adebete#yahoo.com"
aditamiva.recruitment#gmail.comstring(31) "aditamiva.recruitment#gmail.com"
admin#goodlife.co.idstring(20) "admin#goodlife.co.id"
admin#klaudia.p.htstring(18) "admin#klaudia.p.ht"
admin#l-cq.comstring(14) "admin#l-cq.com"
admin#mujahidpress.comstring(22) "admin#mujahidpress.com"
agoes#kesaintblanc.co.idstring(24) "agoes#kesaintblanc.co.id"
agro.rekrutmen#agromediagroup.comstring(33) "agro.rekrutmen#agromediagroup.com"
You are accessing the email by its fields as:
$email = $values_sub->fields[1]->value; //This is line 295
When you see the first element of an array, there is no any fields with key 1, since it is only value in the array. $fields[0].
By seeing your code and the actual array, i come up with the following, this may not be the complete solution, but hope guides towards the result.
So this must be something like this:
foreach($values->contact as $keys=>$values_sub){
$fields = $values_sub->fields;
foreach($fields as $field){
if(property_exists($field,'value') && !is_array($field->value)){
echo (string) $field->value;
}
}
}
I have parsed my xml into array using xml2array.php.
It gave array like
Array(
[HotelImage] => Array
(
[0] => Array
(
)
[1] => Array
(
)
[0_attr] => Array
(
[Type] => Bar/Lounge
[URL] => http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-11.jpg
)
[1_attr] => Array
(
[Type] => Lobby
[URL] => http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-8.jpg
)
[2] => Array
(
)
[2_attr] => Array
(
[Type] => Exterior
[URL] => http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-1.jpg
)
[3] => Array
(
)
[3_attr] => Array
(
[Type] => Recreational Facilities
[URL] => http://images.gta-travel.com/HH/Images/SA/ELS/ELS-HOL1-12.jpg
)
)
)
how can i store all _attr key values in a separate array.
// this may cause a dereference error.. if it does just run array_keys
// and stro it in a sperate var that is then passed to preg_grep
$attrKeys = preg_grep('#\d+_attr#', array_keys($xmlArray));
$attrKeys = array_flip($attrKeys);
$attributes = array_intersect_key($xmlArray, $attrKeys);
$tags = array_diff_key($xmlArray, $attributes);
I know I must be doing something simple wrong. When I do this:
echo '<pre>';
print_r($event->when);
echo '</pre>';
I get this:
Array
(
[0] => Zend_Gdata_Extension_When Object
(
[_rootElement:protected] => when
[_reminders:protected] =>
[_startTime:protected] => 2011-06-16T10:00:00.000-05:00
[_valueString:protected] =>
[_endTime:protected] => 2011-06-17T11:00:00.000-05:00
[_rootNamespace:protected] => gd
[_rootNamespaceURI:protected] =>
[_extensionElements:protected] => Array
(
)
[_extensionAttributes:protected] => Array
(
)
[_text:protected] =>
[_namespaces:protected] => Array
(
[atom] => Array
(
[1] => Array
(
[0] => http://www.w3.org/2005/Atom
)
)
[app] => Array
(
[1] => Array
(
[0] => http://purl.org/atom/app#
)
[2] => Array
(
[0] => http://www.w3.org/2007/app
)
)
[gd] => Array
(
[1] => Array
(
[0] => http://schemas.google.com/g/2005
)
)
[openSearch] => Array
(
[1] => Array
(
[0] => http://a9.com/-/spec/opensearchrss/1.0/
)
[2] => Array
(
[0] => http://a9.com/-/spec/opensearch/1.1/
)
)
[rss] => Array
(
[1] => Array
(
[0] => http://blogs.law.harvard.edu/tech/rss
)
)
)
)
)
I'm then trying to get startTime by doing this:
$StartTime = $event->when->startTime;
But I'm not getting anything.
And yet, when I do this:
pr($event->published);
I get this:
Zend_Gdata_App_Extension_Published Object
(
[_rootElement:protected] => published
[_rootNamespace:protected] => atom
[_rootNamespaceURI:protected] =>
[_extensionElements:protected] => Array
(
)
[_extensionAttributes:protected] => Array
(
)
[_text:protected] => 2011-06-15T03:32:14.000Z
[_namespaces:protected] => Array
(
[atom] => Array
(
[1] => Array
(
[0] => http://www.w3.org/2005/Atom
)
)
[app] => Array
(
[1] => Array
(
[0] => http://purl.org/atom/app#
)
[2] => Array
(
[0] => http://www.w3.org/2007/app
)
)
)
)
and I can do this:
$dateAdded = $event->published->text;
echo $dateAdded;
and I see an output...
According to to the official Zend_Gdata_Extension_When documentation, there's a method called getStartTime() which will give you the time.
If you do $event->when[0]->getStartTime() or $event->when[0]->startTime, you'll get the start time.
startTime is marked protected. You can't reference it from outside like you did. There must be a getter function 'getStartTime()' function in that object that would allow you to reference it publicly.
EDIT: Also it is returning an object array - not an single object, so you would need to reference the it like: $event[0]->getterFunction() or loop through the array with a foreach accessing the individual objects in the loop