Referencing an index in an array in SMARTY template - php

I have a variable that is an array in Smarty, and I am trying to figure out how to retrieve that information. The variable is called $COMMENTS and I did $COMMENTS|#print_r and this is what I got:
Array (
[0] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11686
[crmid] => 11686
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2011-06-08 15:00:31
[createdtime] => 2011-06-08 15:00:31
[7] => 2011-06-08 15:00:31
[modifiedtime] => 2011-06-08 15:00:31
[8] => 2011-06-29 12:00:23
[viewedtime] => 2011-06-29 12:00:23
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 11686
[modcommentsid] => 11686
[14] => aasd
[commentcontent] => aasd
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 11686
)
)
[1] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11685
[crmid] => 11685
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2011-06-08 14:58:42
[createdtime] => 2011-06-08 14:58:42
[7] => 2011-06-08 14:58:42
[modifiedtime] => 2011-06-08 14:58:42
[8] =>
[viewedtime] =>
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 11685
[modcommentsid] => 11685
[14] => comment
[commentcontent] => comment
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 11685
)
)
[2] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 6731
[crmid] => 6731
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
[smownerid] => 1679
[3] => 0
[modifiedby] => 0
[4] => ModComments
[setype] => ModComments
[5] =>
[description] =>
[6] => 2010-11-02 10:15:06
[createdtime] => 2010-11-02 10:15:06
[7] => 2010-11-02 10:15:06
[modifiedtime] => 2010-11-02 10:15:06
[8] =>
[viewedtime] =>
[9] =>
[status] =>
[10] => 0
[version] => 0
[11] => 1
[presence] => 1
[12] => 0
[deleted] => 0
[13] => 6731
[modcommentsid] => 6731
[14] => Test comment
[commentcontent] => Test comment
[15] => 6730
[related_to] => 6730
[16] =>
[parent_comments] =>
[17] => 6731
)
)
)
I am trying to retrieve the 11686 number from that. Any help? I have tried $COMMENTS[0][data:private][0] but that didn't work.
Any help greatly appreciated :)

First, put print_r() output into <pre> tags so it is readable.
Array (
[0] => ModComments_CommentsModel Object (
[data:private] => Array (
[0] => 11686
[crmid] => 11686
[1] => 1679
[smcreatorid] => 1679
[2] => 1679
...
)
)
...
)
You're trying to access the first object in your array, $COMMENTS[0]. Since that it is object, and your data property is private, you cannot access it in Smarty. You would have to edit the ModComments_CommentsModel class to give you access to either the data property or the crmid key of the property.
Example:
class ModComments_CommentsModel {
// ...
public function CrmId(){
return $this->data['crmid'];
}
// ...
}
{* template *}
{$COMMENTS[0]->CrmId()}
{* might have to assign before using method call *}
{assign var='comment' value=$COMMENTS[0]}
{$comment->CrmId()}

Related

handling an Array of objects

I have a JSON array of objects each object contains a MySQL database row that also contains information about an item. my question is how can I get a certain key-value from an object depending on another key? let me get it straight, items is a JSON array contains a couple of objects each object is generated with both numeric and string keys, So what I need is to get the value of the price key that in the same Object with a specific codenumber basically getting the price value from the codenumber key
the Second thing is how to add a new key within a new value to the object? like if I have a variable called $Count how can I add his value to the object within a new key like Count? is the function array_push can add a new key to the Object?
the JSON array
Array (
[0] => stdClass Object (
[0] => 1
[1] => o4
[2] => Efexor
[3] => Eklil
[4] => 1
[5] => 30
[6] => 15
[7] => Phezer
[8] => Venlafaxine
[9] =>
[10] => 0
[11] => 2020-03-25
[12] => 2021-08-25
[13] => 1
[14] => 0
[15] => 0
[16] => caps
[17] => ..\upload\Efexor.jpg
[id] => 1
[qty] => 15
[Sale] => 1
[name] => Efexor
[bonus] => 0
[price] => 30
[company] => Phezer
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\Efexor.jpg
[owned-com] => Eklil
[pack-size] => 0
[codenumber] => o4
[chemicalcom] => Venlafaxine
[dosage-form] => caps
[concentration] =>
[expiration-date] => 2021-08-25
[production-date] => 2020-03-25
)
[1] => stdClass Object (
[0] => 2
[1] =>
[2] => Efexor
[3] => Eklil
[4] => 1
[5] => 15
[6] => 10
[7] => Phezer
[8] => Venlafaxine
[9] =>
[10] => 0
[11] => 2020-03-25
[12] => 2021-08-25
[13] => 0
[14] => 0
[15] => 0
[16] => caps
[17] => ..\upload\Efexor.jpg
[id] => 2
[qty] => 10
[Sale] => 0
[name] => Efexor
[bonus] => 0
[price] => 15
[company] => Phezer
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\Efexor.jpg
[owned-com] => Eklil
[pack-size] => 0
[codenumber] =>
[chemicalcom] => Venlafaxine
[dosage-form] => caps
[concentration] =>
[expiration-date] => 2021-08-25
[production-date] => 2020-03-25
)
[2] => stdClass Object (
[0] => 3
[1] =>
[2] => panadol
[3] => com2
[4] => 1
[5] => 5
[6] => 12
[7] => GSK
[8] => Paracetamol
[9] =>
[10] => 0
[11] => 2020-04-09
[12] => 2021-02-09
[13] => 0
[14] => 0
[15] => 2
[16] => taps
[17] => ..\upload\panadol.png
[id] => 3
[qty] => 12
[Sale] => 0
[name] => panadol
[bonus] => 2
[price] => 5
[company] => GSK
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\panadol.png
[owned-com] => com2
[pack-size] => 0
[codenumber] =>
[chemicalcom] => Paracetamol
[dosage-form] => taps
[concentration] =>
[expiration-date] => 2021-02-09
[production-date] => 2020-04-09
)
[3] => stdClass Object (
[0] => 4
[1] => codenumber
[2] => name
[3] => owned
[4] => 1
[5] => 9
[6] => 1
[7] => gsk
[8] => gscom
[9] => 12mg
[10] => 3
[11] => 2020-03-25
[12] => 2021-02-09
[13] => 1
[14] => 0
[15] => 0
[16] => caps
[17] => ..\upload\panadol.png
[id] => 4
[qty] => 1
[Sale] => 1
[name] => name
[bonus] => 0
[price] => 9
[company] => gsk
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\panadol.png
[owned-com] => owned
[pack-size] => 3
[codenumber] => codenumber
[chemicalcom] => gscom
[dosage-form] => caps
[concentration] => 12mg
[expiration-date] => 2021-02-09
[production-date] => 2020-03-25
)
[4] => stdClass Object (
[0] => 5
[1] => d322
[2] => fsdfds
[3] => ewfwef
[4] => 1
[5] => 3232
[6] => 222
[7] => none
[8] => nonoe
[9] => nonoe
[10] => 12
[11] => 2020-03-25
[12] => 2021-02-09
[13] => 1
[14] => 0
[15] => 2
[16] => caps
[17] => ..\upload\panadol.png
[id] => 5
[qty] => 222
[Sale] => 1
[name] => fsdfds
[bonus] => 2
[price] => 3232
[company] => none
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\panadol.png
[owned-com] => ewfwef
[pack-size] => 12
[codenumber] => d322
[chemicalcom] => nonoe
[dosage-form] => caps
[concentration] => nonoe
[expiration-date] => 2021-02-09
[production-date] => 2020-03-25
)
[5] => stdClass Object (
[0] => 6
[1] =>
[2] =>
[3] =>
[4] => 1
[5] => 0
[6] => 0
[7] =>
[8] =>
[9] =>
[10] => 0
[11] => 0000-00-00
[12] => 0000-00-00
[13] => 0
[14] => 0
[15] => 0
[16] => eyedrop
[17] => ..\upload\panadol.png
[id] => 6
[qty] => 0
[Sale] => 0
[name] =>
[bonus] => 0
[price] => 0
[company] =>
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\panadol.png
[owned-com] =>
[pack-size] => 0
[codenumber] =>
[chemicalcom] =>
[dosage-form] => eyedrop
[concentration] =>
[expiration-date] => 0000-00-00
[production-date] => 0000-00-00
)
[6] => stdClass Object (
[0] => 7
[1] =>
[2] =>
[3] =>
[4] => 1
[5] => 0
[6] => 0
[7] =>
[8] =>
[9] =>
[10] => 0
[11] => 0000-00-00
[12] => 0000-00-00
[13] => 0
[14] => 0
[15] => 0
[16] =>
[17] => ..\upload\panadol.png
[id] => 7
[qty] => 0
[Sale] => 0
[name] =>
[bonus] => 0
[price] => 0
[company] =>
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\panadol.png
[owned-com] =>
[pack-size] => 0
[codenumber] =>
[chemicalcom] =>
[dosage-form] =>
[concentration] =>
[expiration-date] => 0000-00-00
[production-date] => 0000-00-00
)
[7] => stdClass Object (
[0] => 8
[1] =>
[2] =>
[3] =>
[4] => 1
[5] => 0
[6] => 0
[7] =>
[8] =>
[9] =>
[10] => 0
[11] => 0000-00-00
[12] => 0000-00-00
[13] => 0
[14] => 0
[15] => 0
[16] => eardrop
[17] => ..\upload\panadol.png
[id] => 8
[qty] => 0
[Sale] => 0
[name] =>
[bonus] => 0
[price] => 0
[company] =>
[draftid] => 1
[discount] => 0
[imageurl] => ..\upload\panadol.png
[owned-com] =>
[pack-size] => 0
[codenumber] =>
[chemicalcom] =>
[dosage-form] => eardrop
[concentration] =>
[expiration-date] => 0000-00-00
[production-date] => 0000-00-00
)
)
my attempt to make the first function core.php:-
<?PHP
public function getPrice($id,$codenumber){
if($this->connected === true){
try{
$items = $this->connection->prepare("SELECT `items` FROM `bills` WHERE id=:id");
$items->bindParam(":id",$id);
$items->execute();
$fetchedItems = $items->fetchColumn();
$items = json_decode($fetchedItems);
foreach ($items as $item){
$price = $item->price;
echo $price; // What i want is to echo the Price-Key for the value that has the $codenumber [key]
}
}
catch(PDOException $e){
if($this->errors === true){
return $this->error($e->getMessage());
}else{
return false;
}
}
}
}
?>
Assuming that codenumber is unique in the array, just re-index your array with codenumber and then it's simple (PHP >= 7):
$codenumber = 'o4';
$array = array_column($array, null, 'codenumber');
echo $array[$codenumber]->price; // outputs 30
That's reusable multiple times. If you just need to do it once:
echo array_column($array, null, 'codenumber')[$codenumber]->price;
I believe what you are looking for is something like this, where $id is the value you are searching for and $json is your array. If count doesn't exist, it will automatically be created with a value of 0.
$id = 100;
$items = json_decode($fetchedItems, true);
foreach($items as $k => $v){
if(isset($json[$k]["count"]) === false){
$json[$k]["count"] = 0;
}
if($v["codenumber"] == $id){
$json[$k]["count"] += $v["price"];
}
}

How to Change XLXS excel data into a multidimensional array

enter image description here
How can I convert this XLXS excel file into following array format. Also I attached the Screenshot of Excel file. Please review it and let me know
I am using this library to fetch the data from Excel file which i have mentioned given below:-
require_once "EXCEL/simplexlsx.class.php";
$xlsx = new SimpleXLSX('EXCEL/Testingexcel.xlsx');
Excel Array
$xlsx->rows()
Array
(
[0] => Array
(
[0] => Section / Department
1 => Notes
[2] => No
[3] => Great Offer
[4] => Code
[5] => Use Photo
[6] => Item Number
[7] => English Description
[8] => Greek Description
[9] => Price From
[10] => Price
[11] => Text1
[12] => Exclusive Brand
[13] => Date From
[14] => Date To
)
[1] => Array
(
[0] => Chair
[1] => Cover
[2] => 1
[3] =>
[4] =>
[5] =>
[6] =>
[7] => etge
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[2] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP1
[5] =>
[6] =>
[7] => wefewf
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[3] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP2
[5] =>
[6] =>
[7] => TITLE 1
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[4] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP3
[5] =>
[6] =>
[7] => TITLE 12
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[5] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP4
[5] =>
[6] =>
[7] => TITLE 13
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[6] => Array
(
[0] =>
[1] =>
[2] => 2
[3] =>
[4] => AP5
[5] =>
[6] =>
[7] => TITLE 14
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[7] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP6
[5] =>
[6] =>
[7] => TITLE 15
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[8] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP7
[5] =>
[6] =>
[7] => TITLE 16
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[9] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP8
[5] =>
[6] =>
[7] => TITLE 17
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[10] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP9
[5] => Y
[6] =>
[7] => TITLE 18
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[11] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP10
[5] =>
[6] =>
[7] => TITLE 19
[8] =>
[9] =>
[10] =>
[11] => 40%
[12] =>
[13] =>
[14] =>
)
[12] => Array
(
[0] => Table
[1] => cover
[2] => 2
[3] =>
[4] =>
[5] =>
[6] =>
[7] => TITLE 20
[8] =>
[9] =>
[10] =>
[11] => 1+1
[12] =>
[13] =>
[14] =>
)
[13] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP11
[5] =>
[6] =>
[7] => TITLE 145
[8] =>
[9] =>
[10] =>
[11] => 1+1
[12] =>
[13] =>
[14] =>
)
[14] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] => AP12
[5] =>
[6] =>
[7] => TITLE 1657
[8] =>
[9] =>
[10] =>
[11] => 1+1
[12] =>
[13] =>
[14] =>
)
[15] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
)
[16] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
)
[17] => Array
(
[0] =>
[1] =>
[2] =>
[3] =>
[4] =>
[5] =>
[6] =>
[7] =>
[8] =>
[9] =>
[10] =>
[11] =>
[12] =>
[13] =>
[14] =>
)
)
foreach ($xlsx->rows() as $key => $valueRows){
}
Array [0] => Array
(
[chair] => Array
(
[offer 1] => Array
(
[0] => AP1
[1] => AP2
[2] => AP3
[3] => AP4
)
[offer 2] => Array
(
[0] => AP5
[1] => AP6
[2] => AP7
[3] => AP8
[4] => AP9
)
)
[table] => Array
(
[offer 1] => Array
(
[0] => AP10
)
)
)

How to get current prdocut category ID in Virtuemart [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
Does anyone know what is conditional statement to detect a category id?
I need something like this:
If product is in category ID = 64 show some HTML
print_r($this->category);
TableCategories Object ( [virtuemart_category_id] => 16 [virtuemart_vendor_id] => 1 [category_name] => Chiloți, boxeri, indispensabili [slug] => chiloti-boxeri-indispensabili [category_description] => [category_template] => default [category_layout] => 0 [category_product_layout] => 0 [products_per_row] => 0 [ordering] => 3 [shared] => 0 [limit_list_step] => 0 [limit_list_initial] => 0 [metadesc] => [customtitle] => [metakey] => [metarobot] => [metaauthor] => [published] => 1 [_pkey:protected] => virtuemart_category_id [_pkeyForm:protected] => [_obkeys:protected] => Array ( [category_name] => Category in record is missing ! Can't save the record with no Category. [slug] => The given Sef Alias already exists. ) [_unique:protected] => 1 [_unique_name:protected] => Array ( [slug] => The given Sef Alias already exists. ) [_orderingKey:protected] => ordering [_slugAutoName:protected] => category_name [_slugName:protected] => slug [_loggable:protected] => 1 [_xParams:protected] => 0 [_varsToPushParam:protected] => Array ( ) [_translatable] => 1 [_translatableFields:protected] => Array ( [0] => category_name [1] => category_description [2] => metadesc [3] => metakey [4] => customtitle [slug] => slug ) [_langTag:protected] => en_gb [_tbl_lang:protected] => #__virtuemart_categories_en_gb [_updateNulls:protected] => [_tablePreFix] => c. [_tbl:protected] => #__virtuemart_categories [_tbl_key:protected] => virtuemart_category_id [_db:protected] => JFDatabase Object ( [mlTableList] => Array ( [0] => content [1] => modules [2] => menu ) [skipSetRefTables] => [orig_limit] => 0 [orig_offset] => 0 [skipjf] => 0 [translate] => 1 [tableFields:JFDatabase:private] => [profileData] => Array ( [JFDatabase::JFDatabase] => Array ( [total] => 0.0002288818359375 [count] => 1 [start] => Array ( ) ) [interceptDB::loadObjectList] => Array ( [total] => 0.0227241516113281 [count] => 62 [start] => Array ( [0] => 1397209811.22307 [1] => 1397209811.22406 [2] => 1397209811.22585 [3] => 1397209811.22628 [4] => 1397209811.23031 [5] => 1397209811.23254 [6] => 1397209811.24075 [7] => 1397209811.24117 [8] => 1397209811.24466 [9] => 1397209811.24608 [10] => 1397209811.27806 [11] => 1397209811.28038 [12] => 1397209811.28142 [13] => 1397209811.28238 [14] => 1397209811.28439 [15] => 1397209811.28616 [16] => 1397209811.28671 [17] => 1397209811.28773 [18] => 1397209811.28882 [19] => 1397209811.28975 [20] => 1397209811.29121 [21] => 1397209811.29171 [22] => 1397209811.29234 [23] => 1397209811.29328 [24] => 1397209811.29369 [25] => 1397209811.29412 [26] => 1397209811.2953 [27] => 1397209811.29915 [28] => 1397209811.29965 [29] => 1397209811.30009 [30] => 1397209811.30052 [31] => 1397209811.30295 [32] => 1397209811.304 [33] => 1397209811.30527 [34] => 1397209811.3057 [35] => 1397209811.30631 [36] => 1397209811.3067 [37] => 1397209811.30721 [38] => 1397209811.3123 [39] => 1397209811.32571 [40] => 1397209811.32638 [41] => 1397209811.32792 [42] => 1397209811.32891 [43] => 1397209811.32985 [44] => 1397209811.3308 [45] => 1397209811.33191 [46] => 1397209811.33233 [47] => 1397209811.333 [48] => 1397209811.33367 [49] => 1397209811.33744 [50] => 1397209811.33793 [51] => 1397209811.3384 [52] => 1397209811.33884 [53] => 1397209811.33928 [54] => 1397209811.34905 [55] => 1397209811.3519 [56] => 1397209811.35311 [57] => 1397209811.35398 [58] => 1397209811.35685 [59] => 1397209811.35732 ) ) [JFDatabase::getTableName] => Array ( [total] => 0.00406312942504883 [count] => 59 [start] => Array ( ) ) [JFDatabase::setLanguage] => Array ( [total] => 0.000144720077514648 [count] => 2 [start] => Array ( ) ) [JFDatabase::loadResult] => Array ( [total] => 0.000228643417358398 [count] => 13 [start] => Array ( ) ) [JFDatabase::loadAssoc] => Array ( [total] => 0.000162124633789062 [count] => 7 [start] => Array ( ) ) [JFDatabase::loadAssocList] => Array ( [total] => 0.000132083892822266 [count] => 4 [start] => Array ( ) ) [JFDatabase::loadResultArray] => Array ( [total] => 0.000250816345214844 [count] => 14 [start] => Array ( ) ) [JFDatabase::loadRow] => Array ( [total] => 0 [count] => 2 [start] => Array ( [0] => 1397209811.30335 [1] => 1397209811.30605 ) ) ) [name] => mysqli [nameQuote:protected] => ` [nullDate:protected] => 0000-00-00 00:00:00 [dbMinimum:protected] => 5.0.4 [_database:JDatabase:private] => 7624-magazin [connection:protected] => mysqli Object ( [affected_rows] => 0 [client_info] => mysqlnd 5.0.11-dev - 20120503 - $Id: bf9ad53b11c9a57efdb1057292d73b928b8c5c77 $ [client_version] => 50011 [connect_errno] => 0 [connect_error] => [errno] => 0 [error] => [error_list] => Array ( ) [field_count] => 1 [host_info] => ns13.host-md.net via TCP/IP [info] => [insert_id] => 0 [server_info] => 5.5.32-MariaDB-log [server_version] => 50532 [stat] => Uptime: 346321 Threads: 6 Questions: 164660555 Slow queries: 35 Opens: 1823800 Flush tables: 293 Open tables: 1024 Queries per second avg: 475.456 [sqlstate] => 00000 [protocol_version] => 10 [thread_id] => 2168966 [warning_count] => 0 ) [count:protected] => 0 [cursor:protected] => mysqli_result Object ( [current_field] => [field_count] => [lengths] => [num_rows] => [type] => ) [debug:protected] => [limit:protected] => 0 [log:protected] => Array ( ) [offset:protected] => 0 [sql:protected] => SELECT `virtuemart_vendor_id` FROM `#__virtuemart_vmusers` `au` WHERE `au`.`virtuemart_user_id`="687" AND `au`.`user_is_vendor` = "1" [tablePrefix:protected] => l50ti_ [utf:protected] => 1 [errorNum:protected] => 0 [errorMsg:protected] => [hasQuoted:protected] => [quoted:protected] => Array ( ) ) [_trackAssets:protected] => [_rules:protected] => [_locked:protected] => [_errors:protected] => Array ( ) [created_on] => 2014-03-16 21:10:24 [created_by] => 685 [modified_on] => 2014-04-08 13:29:22 [modified_by] => 685 [virtuemart_media_id] => Array ( ) [haschildren] => [children] => Array ( ) [productcount] => 6 [parents] => [images] => Array ( [0] => VmMediaHandler Object ( [media_attributes] => 0 [setRole] => [file_name] => [file_extension] => [virtuemart_media_id] => 0 [_foldersToTest:VmMediaHandler:private] => Array ( [0] => /var/www/vhosts/7624/domains/maicom.md/public_html/images/stories/virtuemart/category/ [1] => /var/www/vhosts/7624/domains/maicom.md/public_html/images/stories/virtuemart/category/resized/ ) [_actions:VmMediaHandler:private] => Array ( ) [_mLocation:VmMediaHandler:private] => Array ( ) [_hidden:VmMediaHandler:private] => Array ( ) [theme_url] => http://maicom.md/components/com_virtuemart/ [virtuemart_vendor_id] => 0 [file_title] => [file_description] => [file_meta] => [file_mimetype] => [file_type] => categories [file_url] => images/stories/virtuemart/category/ [file_url_thumb] => [published] => 0 [file_is_downloadable] => 0 [file_is_forSale] => 0 [file_is_product_image] => 0 [shared] => 0 [file_params] => 0 [file_lang] => [_translatable] => [_tablePreFix] => [created_on] => [created_by] => 0 [modified_on] => [modified_by] => 0 [file_url_folder] => images/stories/virtuemart/category/ [file_path_folder] => images/stories/virtuemart/category/ [file_url_folder_thumb] => images/stories/virtuemart/category/resized/ [media_role] => file_is_displayable ) ) [file_url_thumb] => [file_url] => images/stories/virtuemart/category/ ) </div>
What are you trying so far ?
did you need it in details page ?
if yes then try following method. I assume you are in any of the product details page layout.
if($this->product->virtuemart_category_id == 64){
echo 'your Custom HTML';
}
else{
//nothing
}
Also you need to get more details about current product just use.
echo "<pre/>";
print_r($this->product);
Hope its works..

Enjin API (JSON) to PHP part 2

I'm trying to figure out how to get the data from http://www.natomilcorp.com/api/get-tags
But I doesn't work the way it was working with http://www.natomilcorp.com/api/get-users
<?php
$content = file_get_contents('http://natomilcorp.com/api/get-tags');
$array = json_decode($content, TRUE);
foreach ($array as $key => $value) {
}
?>
Should return something like : Major
There's the id for the rank + id of each user with that rank. How could I do that?
Data I'm trying to get.
Array ( [tags] => Array ( [766910] => Array ( [name] => Major [visible] => 2 [users] => Array ( [0] => 200159 ) ) [766912] => Array ( [name] => Captain [visible] => 2 [users] => Array ( [0] => 2261591 ) ) [766913] => Array ( [name] => 1st Lieutenant [visible] => 2 [users] => Array ( [0] => 9054053 ) ) [766914] => Array ( [name] => 2nd Lieutenant [visible] => 2 [users] => Array ( [0] => 8987889 ) ) [773490] => Array ( [name] => Sergeant First Class [visible] => 2 [users] => Array ( [0] => 7725577 ) ) [773492] => Array ( [name] => Sergeant [visible] => 1 [users] => Array ( [0] => 1060956 [1] => 7302252 [2] => 8757300 [3] => 8863799 [4] => 8965561 [5] => 9261041 ) ) [773493] => Array ( [name] => Corporal [visible] => 2 [users] => Array ( [0] => 3021405 [1] => 7007387 [2] => 9139763 [3] => 9213371 ) ) [773494] => Array ( [name] => Private First Class [visible] => 2 [users] => Array ( [0] => 2200849 [1] => 3641961 [2] => 9178511 [3] => 9261322 [4] => 9323849 [5] => 9389371 [6] => 9430088 ) ) [773495] => Array ( [name] => Private [visible] => 2 [users] => Array ( [0] => 114357 [1] => 261041 [2] => 304466 [3] => 549312 [4] => 1118346 [5] => 1710685 [6] => 2141867 [7] => 3211667 [8] => 3310027 [9] => 3553805 [10] => 4528862 [11] => 7379434 [12] => 8403949 [13] => 8428123 [14] => 8650774 [15] => 8910960 [16] => 9010718 [17] => 9141940 [18] => 9223268 [19] => 9276028 [20] => 9308336 [21] => 9324049 [22] => 9343007 [23] => 9379991 [24] => 9388650 [25] => 9388744 [26] => 9501913 ) ) [773499] => Array ( [name] => Recruit [visible] => 2 [users] => Array ( [0] => 89975 [1] => 205838 [2] => 384035 [3] => 1607344 [4] => 3131066 [5] => 6461552 [6] => 7126984 [7] => 7233456 [8] => 8594187 [9] => 9210020 [10] => 9319294 [11] => 9324467 [12] => 9368201 [13] => 9401020 [14] => 9401208 [15] => 9411271 [16] => 9412511 [17] => 9442152 [18] => 9472151 [19] => 9481048 [20] => 9507716 [21] => 9519155 [22] => 9519665 [23] => 9524202 [24] => 9524528 [25] => 9527256 [26] => 9528148 [27] => 9528464 [28] => 9532974 [29] => 9532993 ) ) [794713] => Array ( [name] => NMC Member [visible] => 0 [users] => Array ( [0] => 89975 [1] => 114357 [2] => 200159 [3] => 205838 [4] => 304466 [5] => 384035 [6] => 549312 [7] => 857679 [8] => 870831 [9] => 1060956 [10] => 1118346 [11] => 1607344 [12] => 1710685 [13] => 2141867 [14] => 2200849 [15] => 2261591 [16] => 3021405 [17] => 3131066 [18] => 3211667 [19] => 3310027 [20] => 3553805 [21] => 3641961 [22] => 4528862 [23] => 5888412 [24] => 6461552 [25] => 7007387 [26] => 7126984 [27] => 7233456 [28] => 7302252 [29] => 7379434 [30] => 7725577 [31] => 8403949 [32] => 8428123 [33] => 8594187 [34] => 8650774 [35] => 8757300 [36] => 8863799 [37] => 8910960 [38] => 8965561 [39] => 8987889 [40] => 9010718 [41] => 9017629 [42] => 9054053 [43] => 9139763 [44] => 9141940 [45] => 9178511 [46] => 9210020 [47] => 9213371 [48] => 9223268 [49] => 9261041 [50] => 9261322 [51] => 9276028 [52] => 9289688 [53] => 9308336 [54] => 9319294 [55] => 9323849 [56] => 9324049 [57] => 9324467 [58] => 9343007 [59] => 9361657 [60] => 9368201 [61] => 9379991 [62] => 9388650 [63] => 9388744 [64] => 9389371 [65] => 9401020 [66] => 9401208 [67] => 9411271 [68] => 9412511 [69] => 9430088 [70] => 9442152 [71] => 9472151 [72] => 9481048 [73] => 9501913 [74] => 9507716 [75] => 9519155 [76] => 9519665 [77] => 9524202 [78] => 9524528 [79] => 9527256 [80] => 9528148 [81] => 9528464 [82] => 9532974 [83] => 9532993 ) ) [905780] => Array ( [name] => Reserve / Inactive [visible] => 2 [users] => Array ( [0] => 1116431 [1] => 1146450 [2] => 1327008 [3] => 3488556 [4] => 4057254 [5] => 4109011 [6] => 4442271 [7] => 5075797 [8] => 6348486 [9] => 6727549 [10] => 7482138 [11] => 7669434 [12] => 7810956 [13] => 7813040 [14] => 7845349 [15] => 7873320 [16] => 8163829 [17] => 8610931 [18] => 8720229 [19] => 8758932 [20] => 8944586 [21] => 8988410 [22] => 9009221 [23] => 9016644 [24] => 9143121 ) ) [916781] => Array ( [name] => High Command [visible] => 2 [users] => Array ( [0] => 192868 ) ) [950454] => Array ( [name] => (AF) 2nd Lieutenant [visible] => 2 [users] => Array ( [0] => 870831 [1] => 5888412 [2] => 9017629 [3] => 9289688 [4] => 9361657 ) ) [950472] => Array ( [name] => (AF) 1st Lieutenant [visible] => 2 [users] => Array ( [0] => 857679 ) ) [964515] => Array ( [name] => 8 Week Service Ribbon 1A [visible] => 2 [users] => Array ( [0] => 857679 [1] => 3021405 [2] => 8428123 ) ) [964541] => Array ( [name] => 8 Week Service Ribbon 2A [visible] => 2 [users] => Array ( [0] => 7725577 ) ) [964552] => Array ( [name] => 8 Week Service Ribbon 4A [visible] => 2 [users] => Array ( [0] => 200159 ) ) [964580] => Array ( [name] => Altis War Service Ribbon [visible] => 2 [users] => Array ( [0] => 200159 [1] => 857679 [2] => 870831 [3] => 1060956 [4] => 2261591 [5] => 5888412 [6] => 7302252 [7] => 7725577 [8] => 8757300 [9] => 8863799 [10] => 8965561 [11] => 9054053 ) ) [964632] => Array ( [name] => Commanding Officers Commendation [visible] => 2 [users] => Array ( [0] => 2261591 [1] => 9054053 [2] => 9139763 [3] => 9261322 ) ) [964807] => Array ( [name] => Executive Officers Commendation [visible] => 2 [users] => Array ( [0] => 5888412 [1] => 8863799 [2] => 9017629 ) )
It should be
echo $array['tags'][$key]['name'];
You could see there is a tags key , so you need to add that too while accessing.
Working code..
<?php
$content = file_get_contents('http://natomilcorp.com/api/get-tags');
$array = json_decode($content, TRUE);
$key = "766910";
echo $array['tags'][$key]['name'];

Loop to read array

sorry if that can be a simple question. I need to read the index value of an array. The code that I have and try to correct read only the index 0. I have try with a ciclebut continue to make mistakes.
<? if($entrata != ""){
$nome_condomino = getCondominoByIdEntrata($entrata[0]['id']);
$saldo += (float) $entrata[0]['importo_versato'];
//echo '<pre>' . print_r( $entrata,true ) . '</pre>';
?>
<tr class="gradeX">
<td class="center"><?echo $giorno;?></td>
<td class="center"><?echo $nome_condomino[0]['nome_cognome'];?></td>
<td class="center"><b><?echo "€ ".$entrata[0]['importo_versato'];?></b></td>
<td class="center"><?echo "€ ".$saldo;?></td>
<td class="center"><?echo $giorno_ok;?></td>
<td class="center"><?echo $entrata_id[0];?></td>
</tr>
<? } ?>
I need to show the other index value for the variables $nome_condominio and $entrata
That is print_r( $entrata,true )
Array
(
[0] => Array
(
[0] => 41
[id] => 41
[1] => 35
[id_condominio] => 35
[2] => 38
[id_condomino] => 38
[3] => 12
[importo_versato] => 12
[4] => 2013-11-30
[data] => 2013-11-30
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] =>
[causale] =>
[13] =>
[causale_altro] =>
[14] => 10_2013
[causale_mese] => 10_2013
[15] => Ottobre 2013
[causale_mese_periodo_esteso] => Ottobre 2013
)
[1] => Array
(
[0] => 40
[id] => 40
[1] => 35
[id_condominio] => 35
[2] => 52
[id_condomino] => 52
[3] => 18.2
[importo_versato] => 18.2
[4] => 2013-11-30
[data] => 2013-11-30
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
Array
(
[0] => Array
(
[0] => 39
[id] => 39
[1] => 35
[id_condominio] => 35
[2] => 34
[id_condomino] => 34
[3] => 12.5
[importo_versato] => 12.5
[4] => 2013-12-01
[data] => 2013-12-01
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
[1] => Array
(
[0] => 44
[id] => 44
[1] => 35
[id_condominio] => 35
[2] => 51
[id_condomino] => 51
[3] => 10
[importo_versato] => 10
[4] => 2013-12-01
[data] => 2013-12-01
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
Array
(
[0] => Array
(
[0] => 42
[id] => 42
[1] => 35
[id_condominio] => 35
[2] => 39
[id_condomino] => 39
[3] => 10
[importo_versato] => 10
[4] => 2013-12-03
[data] => 2013-12-03
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 3
[causale] => 3
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
Array
(
[0] => Array
(
[0] => 43
[id] => 43
[1] => 35
[id_condominio] => 35
[2] => 38
[id_condomino] => 38
[3] => 9
[importo_versato] => 9
[4] => 2013-12-05
[data] => 2013-12-05
[5] =>
[numero_ricevuta] =>
[6] =>
[allegato_ricevuta] =>
[7] => 0
[consumi_idrici_importo] => 0
[8] => 0000-00-00
[data2] => 0000-00-00
[9] =>
[allegato_consumi_idrici] =>
[10] => 0
[lavori_straordinari_importo] => 0
[11] => 0000-00-00
[data3] => 0000-00-00
[12] => 2
[causale] => 2
[13] =>
[causale_altro] =>
[14] =>
[causale_mese] =>
[15] =>
[causale_mese_periodo_esteso] =>
)
)
the function:
function getCondominoByIdEntrata($idEntrata){
$sql1 = "SELECT * FROM entrate WHERE id = '".$idEntrata."'";
$r1 = executeQuery($sql1);
$id_condomino = $r1[0]['id_condomino'];
$sql2 = "SELECT * FROM anagrafe WHERE id = '".$id_condomino."'";
$r2 = executeQuery($sql2);
return $r2;
}
The print_r( $nome_condomino):
Array
(
[0] => Array
(
[0] => 38
[id] => 38
[1] => 35
[id_condominio] => 35
[2] => Carlo Vincenzo
[nome_cognome] => Carlo Vincenzo
[3] =>
[codice_fiscale] =>
[4] =>
[dati_catastali_foglio] =>
[5] =>
[dati_catastali_particella] =>
[6] =>
[dati_catastali_subalterno] =>
[7] =>
[dati_catastali_piano] =>
[8] =>
[recapito] =>
[9] => 2
[civico] => 2
[10] =>
[citta] =>
[11] => TA
[provincia] => TA
[12] =>
[telefono] =>
[13] =>
[cellulare] =>
[14] =>
[fax] =>
[15] =>
[email] =>
[16] =>
[pec] =>
[17] => si
[occupante_uguale_titolare] => si
[18] =>
[occupante] =>
[19] =>
[occupante_rapporto] =>
[20] =>
[occupante_telefono] =>
[21] =>
[occupante_cellulare] =>
[22] =>
[occupante_email] =>
[23] =>
[occupante_pec] =>
[24] =>
[nome_utente] =>
)
)
Array
(
[0] => Array
(
[0] => 52
[id] => 52
[1] => 35
[id_condominio] => 35
[2] => Mario Giancarlo
[nome_cognome] => Mario Giancarlo
[3] =>
[codice_fiscale] =>
[4] =>
[dati_catastali_foglio] =>
[5] =>
[dati_catastali_particella] =>
[6] =>
[dati_catastali_subalterno] =>
[7] =>
[dati_catastali_piano] =>
[8] => Via Rossi
[recapito] => Via Rossi
[9] => 5
[civico] => 5
[10] =>
[citta] =>
[11] =>
[provincia] =>
[12] =>
[telefono] =>
[13] =>
[cellulare] =>
[14] =>
[fax] =>
[15] =>
[email] =>
[16] =>
[pec] =>
[17] => si
[occupante_uguale_titolare] => si
[18] =>
[occupante] =>
[19] =>
[occupante_rapporto] =>
[20] =>
[occupante_telefono] =>
[21] =>
[occupante_cellulare] =>
[22] =>
[occupante_email] =>
[23] =>
[occupante_pec] =>
[24] =>
[nome_utente] =>
)
)
You want foreach statement to get all data from array $entrata & $nome_condominio. Something like this maybe work:
UPDATED:
<?php if($entrata != ""){
//echo '<pre>' . print_r( $entrata,true ) . '</pre>';
$i = 0;
foreach($entrata as $entr){
$nome_condomino = getCondominoByIdEntrata($entr['id']);
$saldo += (float) $entr['importo_versato'];
?>
<tr class="gradeX">
<td class="center"><?echo $giorno;?></td>
<td class="center"><?echo $nome_condomino['nome_cognome'];?></td>
<td class="center"><b><?echo "€ ".$entr['importo_versato'];?></b></td>
<td class="center"><?echo "€ ".$saldo;?></td>
<td class="center"><?echo $giorno_ok;?></td>
<td class="center"><?echo $entr['id'];?></td>
</tr>
<?php
$i++;
} ?>
<? } ?>
Seems like $entrata isn't an array or is empty? Try changing
if ($entrata != '') {
to
if (!empty($entrata) && is_array($entrata)) {
will ensure that you're getting a non empty array

Categories