PHP Fatal error out of memory while building tree - php
I got trouble with bulding tree of categories in php.
It's builds tree for very long time and after that i got error:
Fatal error: Out of memory (allocated 637796352) (tried to allocate
208666926 bytes) in
D:\OpenServer\domains\site.local\Core\Widgets.php on line 488
Here is my functions to build tree.
First i made an array of categories:
public function makeCategoriesArray()
{
// $row = DB::select()
// ->from('catalog_tree')
// ->where('parent_id', '=', $this->post['parent_id'])
// ->union(DB::select()
// ->from('catalog_tree')
// ->where('id', 'in', DB::expr("(SELECT catalog_tree_id FROM catalog_tree_parents WHERE parent_id = '".$this->post['parent_id']."')")))
// ->find_all();
$row = DB::select()
->from('catalog_tree')
->where('status', '=', '1')
->find_all();
$categories_arr = array();
foreach ($row as $cat) {
$categories_arr[$cat->parent_id][] = $cat;
}
unset($cat);
unset($row);
foreach($categories_arr as $key=>$value) {
$row = DB::select()
->from('catalog_tree')
->where('id', 'in', DB::expr("(SELECT catalog_tree_id FROM catalog_tree_parents WHERE parent_id = '".$key."')"))
->find_all();
foreach($row as $cat) {
$categories_arr[$key][] = $cat;
}
unset($cat);
unset($row);
}
return $categories_arr;
}
Then i begin to build tree with this array:
public function BuildMainTree($array, $pid) {
global $MainMenu;
if (isset($array[$pid])) { // If category with $pid exist
$MainMenu.= "<ul class=\"dropdown-menu\" role=\"menu\">";
foreach ($array[$pid] as $value)
{
if ($pid!='0' && !isset($array[$value->id])) {
$MainMenu.= '<li class="divider"></li>
<li class="dropdown">
<a href="/catalog/' . $value->alias . '">
'. $value->name .'
</a>
</li>';
}
else {
$MainMenu.= '<li class="divider"></li>
<li class="dropdown">
<a href="/catalog/' . $value->alias . '">
'. $value->name .'
<span class="caret"></span>
</a>
</li>';
$this->BuildMainTree($array, $value->id);
}
}
if ($pid=='0') {
$MainMenu .= "</ul>";
}
else {
$MainMenu .= "</ul></li>";
}
}
}
Initialization of this process are in this function:
public function Header() {
$contentMenu = Common::factory('sitemenu')->getRows(1, 'sort');
$array['contentMenu'] = $contentMenu;
$array['user'] = User::info();
$array['countItemsInTheCart'] = Cart::factory()->_count_goods;
$categories_arr = $this->makeCategoriesArray();
$this->BuildMainTree($categories_arr, 0);
$array['mainMenu'] = $MainMenu;
return $array;
}
Also if i just make array with makeCategoriesArray() it's works fine, but BuildMainTree($array, $pid) function causes an error...
Most funny part, is that this code works perfect on other site.
Maybe I just missed some details here... Spent two days of tried to run this code, but got nothing.
Here is array var_dump:
array(156) {
[0]=>
array(21) {
[0]=>
object(stdClass)#17 (18) {
["id"]=>
string(4) "2075"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1473775697"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(27) "Садовая мебель"
["alias"]=>
string(14) "sadovaja-mebel"
["ikea_alias"]=>
string(7) "outdoor"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "dc30302d5e76ddf7d3be9cb0f8b4d711.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "129"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[1]=>
object(stdClass)#19 (18) {
["id"]=>
string(4) "2076"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1473950659"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(39) "Оформление интерьера"
["alias"]=>
string(19) "oformlenie-interera"
["ikea_alias"]=>
string(10) "decoration"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "91b3786d06e22081abbb945b9e4e02d8.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "287"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[2]=>
object(stdClass)#20 (18) {
["id"]=>
string(4) "2077"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472474523"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(27) "Офисная мебель"
["alias"]=>
string(14) "ofisnaja-mebel"
["ikea_alias"]=>
string(10) "workspaces"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "6884cb6cf5defdf8ec7fe467bad542ca.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "247"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[3]=>
object(stdClass)#21 (18) {
["id"]=>
string(4) "2078"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472409476"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(34) "Посуда для готовки"
["alias"]=>
string(19) "posuda-dlja-gotovki"
["ikea_alias"]=>
string(7) "cooking"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "ca3e4a8eb9d0d7ea22f9a7fc3c300ef9.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "514"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[4]=>
object(stdClass)#22 (18) {
["id"]=>
string(4) "2079"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472547042"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Столовая"
["alias"]=>
string(9) "stolovaja"
["ikea_alias"]=>
string(6) "dining"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "d5704ec3e70a3415b181c7c4f9005c1a.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "147"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[5]=>
object(stdClass)#23 (18) {
["id"]=>
string(4) "2080"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472547236"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(31) "Сервировка стола"
["alias"]=>
string(16) "servirovka-stola"
["ikea_alias"]=>
string(6) "eating"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "2d2142a8edd5fc3ce1ffa01fbe6655c9.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "338"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[6]=>
object(stdClass)#24 (18) {
["id"]=>
string(4) "2081"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472540142"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(21) "Кухни МЕТОД"
["alias"]=>
string(11) "kuhni-metod"
["ikea_alias"]=>
string(7) "kitchen"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "decf1d321c63aed673d949b34c452a37.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "304"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[7]=>
object(stdClass)#25 (18) {
["id"]=>
string(4) "2082"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472466401"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(18) "Освещение"
["alias"]=>
string(11) "osveschenie"
["ikea_alias"]=>
string(8) "lighting"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "3ac3d00a4734040cf346f2a63a09a7f9.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "243"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[8]=>
object(stdClass)#26 (18) {
["id"]=>
string(4) "2083"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472547518"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(14) "Детская"
["alias"]=>
string(8) "detskaja"
["ikea_alias"]=>
string(14) "childrens_ikea"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "8d78781b99b8ee7a1abc0f9cbfdc7e01.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "321"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[9]=>
object(stdClass)#27 (18) {
["id"]=>
string(4) "2084"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472411322"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Гостиная"
["alias"]=>
string(9) "gostinaja"
["ikea_alias"]=>
string(11) "living_room"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "c9c933ae12652bca96eb2ef66c832a82.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "181"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[10]=>
object(stdClass)#28 (18) {
["id"]=>
string(4) "2085"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472388754"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(35) "Домашняя прачечная"
["alias"]=>
string(24) "domashnjaja-prachechnaja"
["ikea_alias"]=>
string(7) "laundry"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "08c9713d828235679b861c095784af0e.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "106"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[11]=>
object(stdClass)#29 (18) {
["id"]=>
string(4) "2086"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472481068"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(45) "Дополнительное хранение"
["alias"]=>
string(22) "dopolnitelnoe-hranenie"
["ikea_alias"]=>
string(17) "secondary_storage"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "bb180b85cc1e34ab9b6185f4cf71fbf0.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "158"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[12]=>
object(stdClass)#31 (18) {
["id"]=>
string(4) "2088"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472136224"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Прихожая"
["alias"]=>
string(10) "prihozhaja"
["ikea_alias"]=>
string(7) "hallway"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "985600d075b4080f57488b87e0e898ff.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "64"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[13]=>
object(stdClass)#32 (18) {
["id"]=>
string(4) "2089"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472556911"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(14) "Спальня"
["alias"]=>
string(7) "spalnja"
["ikea_alias"]=>
string(7) "bedroom"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "439a1f90391568bffabcfbc5a8b22559.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "172"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[14]=>
object(stdClass)#33 (18) {
["id"]=>
string(4) "2090"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472481070"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(18) "Еда в ИКЕА"
["alias"]=>
string(10) "eda-v-ikea"
["ikea_alias"]=>
string(4) "food"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "1886868c925ed2f22a10fe7e51a6050c.JPG"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "24"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[15]=>
object(stdClass)#34 (18) {
["id"]=>
string(4) "2091"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472554267"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(16) "Текстиль"
["alias"]=>
string(7) "tekstil"
["ikea_alias"]=>
string(8) "Textiles"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "1ed5b13bc1abab2d5966b6ab074b7174.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "194"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[16]=>
object(stdClass)#35 (18) {
["id"]=>
string(4) "2092"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1473774214"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(33) "Домашние растения"
["alias"]=>
string(19) "domashnie-rastenija"
["ikea_alias"]=>
string(16) "indoor_gardening"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "a42bf2728494d635bc16b0f12db5855d.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
string(0) ""
["views"]=>
string(2) "55"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[17]=>
object(stdClass)#36 (18) {
["id"]=>
string(4) "2093"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472481066"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(39) "Беспроводная зарядка"
["alias"]=>
string(22) "besprovodnaja-zarjadka"
["ikea_alias"]=>
string(17) "wireless_charging"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "6ee6de2d3769d7f617b7e05fd81fbaa4.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "95"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[18]=>
object(stdClass)#37 (18) {
["id"]=>
string(4) "2094"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472517463"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(12) "Ванная"
["alias"]=>
string(7) "vannaja"
["ikea_alias"]=>
string(8) "bathroom"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "f69159cedca764bc7d44ff7d6a13b52a.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "157"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[19]=>
object(stdClass)#38 (18) {
["id"]=>
string(4) "2095"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472379447"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(24) "Товары IKEA FAMILY"
["alias"]=>
string(18) "tovary-ikea-family"
["ikea_alias"]=>
string(20) "ikea_family_products"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "9e0c8d67fd4189ebed7b821e1c6b9df8.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(2) "78"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
[20]=>
object(stdClass)#39 (18) {
["id"]=>
string(4) "2096"
["created_at"]=>
string(10) "1470080793"
["updated_at"]=>
string(10) "1472482584"
["status"]=>
string(1) "1"
["sort"]=>
string(1) "0"
["name"]=>
string(34) "Для вашего бизнеса"
["alias"]=>
string(20) "dlja-vashego-biznesa"
["ikea_alias"]=>
string(8) "business"
["parent_id"]=>
string(1) "0"
["image"]=>
string(36) "3b9d8f1d77703f38d3d043fb95dd2b5e.jpg"
["h1"]=>
NULL
["title"]=>
NULL
["keywords"]=>
NULL
["description"]=>
NULL
["text"]=>
NULL
["views"]=>
string(3) "118"
["course"]=>
string(4) "9.50"
["discount_percent"]=>
string(1) "0"
}
}
that is not a code issue. set memory_limit in php.ini file to more than 128m,
you should also increase post meta data to something like 10000
Problem solved with this function:
public static function BuildTree($pid) {
global $MainMenu;
$row = DB::select()
->from('catalog_tree')
->where('parent_id', '=', $pid)
->and_where('status', '=', '1')
->union(DB::select()
->from('catalog_tree')
->where('id', 'in', DB::expr("(SELECT catalog_tree_id FROM catalog_tree_parents WHERE parent_id = '".$pid."')"))
->and_where('status', '=', '1'))
->find_all();
if ($row->count() > 0) {
$MainMenu .= "<ul class=\"dropdown-menu\" role=\"menu\">";
foreach ($row as $value)
{
$MainMenu .= '
<li class="divider"></li>
<li class="dropdown">
<a href="/catalog/' . $value->alias . '">
'. $value->name .'
</a> ';
Widgets::BuildTree($value->id);
}
if ($pid=='0') {
$MainMenu .= " <li class=\"divider\"></li></ul>";
return $MainMenu;
}
else {
$MainMenu .= " <li class=\"divider\"></li></ul></li>";
}
}
}
This function works perfectly :)
I think #DoktorOSwaldo was right, previous recursion was endless.
Related
double loop to extract information from an array
I have an array that is quite large. I need to extract the information from the "citis" and "avatarScores".The information of avatarscores is related to the information of citis. For example city 1 belongs to player 1 who has the points that appear in avatarscores. The citis array is always 17 places, but there does not have to be 17 cities. The array of avatarscores is the size that cities actually exist. The question is how can I do a double foreach, to extract the information from both arrays, and that they associate well so that the information of each city is correct. I was doing a lot of testing, but duplicate records were continually coming out.There are only 10 cities in that array, and I always got about 100 cities (duplicate information) The array array(6) { [0]=> array(2) { [0]=> string(20) "updateBackgroundData" [1]=> object(stdClass)#2 (37) { ["id"]=> string(2) "74" ["type"]=> int(5) ["name"]=> string(8) "Shaymios" ["xCoord"]=> string(2) "44" ["yCoord"]=> string(2) "47" ["tradegood"]=> string(1) "3" ["tradegoodTarget"]=> string(8) "noluxury" ["resourceLevel"]=> string(2) "26" ["tradegoodLevel"]=> string(2) "21" ["wonder"]=> string(1) "2" ["wonderLevel"]=> string(1) "4" ["wonderName"]=> string(22) "Gruta Sagrada de Hades" ["showResourceWorkers"]=> int(0) ["showTradegoodWorkers"]=> int(0) ["showAgora"]=> int(1) ["canEnterResource"]=> int(1) ["canEnterTradegood"]=> int(1) ["tradegoodEndUpgradeTime"]=> int(0) ["resourceEndUpgradeTime"]=> int(0) ["wonderEndUpgradeTime"]=> int(0) ["isOwnCityOnIsland"]=> bool(true) ["cities"]=> array(17) { [0]=> object(stdClass)#3 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(6) "normal" } [1]=> object(stdClass)#4 (13) { ["type"]=> string(4) "city" ["name"]=> string(7) "Nothing" ["id"]=> int(64501) ["level"]=> string(2) "10" ["ownerId"]=> string(5) "27450" ["ownerName"]=> string(7) "Paisano" ["ownerAllyId"]=> string(3) "321" ["ownerAllyTag"]=> string(5) "CROMA" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [2]=> object(stdClass)#5 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(6) "normal" } [3]=> object(stdClass)#6 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(6) "normal" } [4]=> object(stdClass)#7 (12) { ["type"]=> string(4) "city" ["name"]=> string(5) "Polis" ["id"]=> int(64437) ["level"]=> string(1) "1" ["ownerId"]=> string(5) "28312" ["ownerName"]=> string(14) "Agamemnon-3798" ["ownerAllyId"]=> string(1) "0" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(2) ["infestedByPlague"]=> bool(false) } [5]=> object(stdClass)#8 (13) { ["type"]=> string(4) "city" ["name"]=> string(9) "Evaroschi" ["id"]=> int(5405) ["level"]=> string(2) "26" ["ownerId"]=> string(4) "3739" ["ownerName"]=> string(6) "cesar2" ["ownerAllyId"]=> string(3) "324" ["ownerAllyTag"]=> string(4) "-T1-" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [6]=> object(stdClass)#9 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(6) "normal" } [7]=> object(stdClass)#10 (13) { ["type"]=> string(4) "city" ["name"]=> string(9) "Cristal I" ["id"]=> int(849) ["level"]=> string(2) "27" ["ownerId"]=> string(3) "849" ["ownerName"]=> string(7) "DaniloJ" ["ownerAllyId"]=> string(1) "2" ["ownerAllyTag"]=> string(4) "-ZT-" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [8]=> object(stdClass)#11 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(6) "normal" } [9]=> object(stdClass)#12 (12) { ["type"]=> string(4) "city" ["name"]=> string(5) "Polis" ["id"]=> int(64892) ["level"]=> string(1) "1" ["ownerId"]=> string(5) "28488" ["ownerName"]=> string(8) "-NAGATO-" ["ownerAllyId"]=> string(1) "0" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(8) "inactive" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [10]=> object(stdClass)#13 (13) { ["type"]=> string(4) "city" ["name"]=> string(4) "0001" ["id"]=> int(40246) ["level"]=> string(2) "20" ["ownerId"]=> string(5) "18230" ["ownerName"]=> string(13) "NeWRomerOrdeR" ["ownerAllyId"]=> string(3) "307" ["ownerAllyTag"]=> string(4) "ROMA" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [11]=> object(stdClass)#14 (12) { ["type"]=> string(4) "city" ["name"]=> string(5) "Polis" ["id"]=> int(64942) ["level"]=> string(1) "1" ["ownerId"]=> string(5) "28503" ["ownerName"]=> string(13) "AnitaFacilita" ["ownerAllyId"]=> string(1) "0" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(8) "inactive" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [12]=> object(stdClass)#15 (12) { ["type"]=> string(4) "city" ["name"]=> string(5) "Polis" ["id"]=> int(64988) ["level"]=> string(1) "1" ["ownerId"]=> string(5) "28523" ["ownerName"]=> string(9) "Sklavidel" ["ownerAllyId"]=> string(1) "0" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(4) "noob" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [13]=> object(stdClass)#16 (12) { ["type"]=> string(4) "city" ["name"]=> string(5) "Polis" ["id"]=> int(63482) ["level"]=> string(2) "14" ["ownerId"]=> string(5) "27754" ["ownerName"]=> string(10) "OL-Fredy97" ["ownerAllyId"]=> string(1) "0" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [14]=> object(stdClass)#17 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(6) "normal" } [15]=> object(stdClass)#18 (13) { ["type"]=> string(4) "city" ["name"]=> string(6) "Atenas" ["id"]=> int(32646) ["level"]=> string(2) "24" ["ownerId"]=> string(5) "14700" ["ownerName"]=> string(7) "Charles" ["ownerAllyId"]=> string(3) "307" ["ownerAllyTag"]=> string(4) "ROMA" ["hasTreaties"]=> int(0) ["actions"]=> array(0) { } ["state"]=> string(0) "" ["viewAble"]=> int(0) ["infestedByPlague"]=> bool(false) } [16]=> object(stdClass)#19 (6) { ["id"]=> int(-1) ["type"]=> string(10) "buildplace" ["name"]=> string(7) "Terreno" ["level"]=> int(0) ["viewAble"]=> int(1) ["buildplace_type"]=> string(7) "premium" } } ["barbarians"]=> object(stdClass)#20 (11) { ["invisible"]=> int(0) ["actionTitle"]=> string(55) "¡Ninguna tropa/barco mercante disponible para saquear!" ["actionClass"]=> string(19) "plundering disabled" ["actionLink"]=> string(0) "" ["count"]=> int(1) ["wallLevel"]=> int(0) ["level"]=> int(1) ["underAttack"]=> int(0) ["isTradegoodSiege"]=> int(0) ["city"]=> string(8) "kingOlaf" ["destroyed"]=> int(0) } ["avatarScores"]=> object(stdClass)#22 (10) { ["849"]=> object(stdClass)#21 (6) { ["avatar_id"]=> string(3) "849" ["place"]=> string(1) "7" ["building_score_main"]=> string(11) "379,322,313" ["research_score_main"]=> string(10) "72,145,880" ["army_score_main"]=> string(7) "250,190" ["trader_score_secondary"]=> string(10) "12,848,160" } ["3739"]=> object(stdClass)#23 (6) { ["avatar_id"]=> string(5) "3,739" ["place"]=> string(3) "165" ["building_score_main"]=> string(10) "60,479,333" ["research_score_main"]=> string(9) "7,276,760" ["army_score_main"]=> string(7) "199,960" ["trader_score_secondary"]=> string(9) "4,120,270" } ["14700"]=> object(stdClass)#24 (6) { ["avatar_id"]=> string(6) "14,700" ["place"]=> string(3) "237" ["building_score_main"]=> string(10) "24,048,522" ["research_score_main"]=> string(9) "7,276,760" ["army_score_main"]=> string(7) "380,000" ["trader_score_secondary"]=> string(9) "7,027,608" } ["18230"]=> object(stdClass)#25 (6) { ["avatar_id"]=> string(6) "18,230" ["place"]=> string(3) "243" ["building_score_main"]=> string(10) "26,427,220" ["research_score_main"]=> string(9) "3,953,400" ["army_score_main"]=> string(7) "472,620" ["trader_score_secondary"]=> string(9) "2,657,737" } ["27450"]=> object(stdClass)#26 (6) { ["avatar_id"]=> string(6) "27,450" ["place"]=> string(3) "334" ["building_score_main"]=> string(9) "6,161,438" ["research_score_main"]=> string(7) "891,972" ["army_score_main"]=> string(7) "144,860" ["trader_score_secondary"]=> string(6) "41,764" } ["27754"]=> object(stdClass)#27 (6) { ["avatar_id"]=> string(6) "27,754" ["place"]=> string(3) "349" ["building_score_main"]=> string(9) "4,536,533" ["research_score_main"]=> string(7) "702,972" ["army_score_main"]=> string(6) "20,660" ["trader_score_secondary"]=> string(7) "125,021" } ["28312"]=> object(stdClass)#28 (6) { ["avatar_id"]=> string(6) "28,312" ["place"]=> string(3) "551" ["building_score_main"]=> string(1) "0" ["research_score_main"]=> string(1) "0" ["army_score_main"]=> string(1) "0" ["trader_score_secondary"]=> string(6) "61,843" } ["28488"]=> object(stdClass)#29 (6) { ["avatar_id"]=> string(6) "28,488" ["place"]=> string(3) "552" ["building_score_main"]=> string(1) "0" ["research_score_main"]=> string(1) "0" ["army_score_main"]=> string(1) "0" ["trader_score_secondary"]=> string(6) "18,439" } ["28503"]=> object(stdClass)#30 (6) { ["avatar_id"]=> string(6) "28,503" ["place"]=> string(3) "555" ["building_score_main"]=> string(1) "0" ["research_score_main"]=> string(1) "0" ["army_score_main"]=> string(1) "0" ["trader_score_secondary"]=> string(6) "14,262" } ["28523"]=> object(stdClass)#31 (6) { ["avatar_id"]=> string(6) "28,523" ["place"]=> string(3) "498" ["building_score_main"]=> string(1) "0" ["research_score_main"]=> string(1) "0" ["army_score_main"]=> string(3) "360" ["trader_score_secondary"]=> string(6) "10,879" } } ["specialServerBadges"]=> array(0) { } ["selectedCityParameters"]=> array(0) { } ["island"]=> string(2) "74" ["isHeliosTowerBuilt"]=> bool(false) ["heliosTop"]=> int(1) ["heliosMid"]=> int(1) ["heliosBase"]=> int(1) ["heliosName"]=> string(15) "Ruinas de torre" ["heliosTooltip"]=> string(24) "Torre de Helios inactiva" ["heliosActive"]=> int(0) ["showResourceBonusIcon"]=> int(0) ["showTradegoodBonusIcon"]=> int(0) ["walkers"]=> object(stdClass)#32 (1) { ["add"]=> array(0) { } } } } [1]=> array(2) { [0]=> string(18) "updateTemplateData" [1]=> string(0) "" } [2]=> array(2) { [0]=> string(9) "popupData" [1]=> NULL } [3]=> array(2) { [0]=> string(17) "ingameCounterData" [1]=> NULL } [4]=> array(2) { [0]=> string(23) "removeIngameCounterData" [1]=> NULL } [5]=> array(2) { [0]=> string(14) "updateBacklink" [1]=> NULL } } code to extract $owners = []; foreach($final[0][1]->cities as $city){ $owner = ""; $allyTag = ""; $namecity = ""; $citylevel =""; $idowner = ""; if(isset($city->ownerName)){ $owner = $city->ownerName; if(isset($city->ownerId)){ $idowner = $city->ownerId; if (isset($city->name)) { $namecity = $city->name; if (isset($city->level)) { $citylevel = $city->level; if(isset($city->ownerAllyTag)){ $allyTag = $city->ownerAllyTag; } array_push($owners, ["idowner"=>$idowner, "citylevel"=>$citylevel, "owner"=>$owner, "allyTag" => $allyTag, "namecity" => $namecity]); }}}} } code from avatarscores that has to be unified with the one above $vavatar_id = ""; $vplace = ""; $vbuilding_score_main = ""; $vresearch_score_main = ""; $varmy_score_main = ""; $vtrader_score_secondary = ""; if(isset($scores->avatar_id)){ $vavatar_id = $scores->avatar_id; } if(isset($scores->place)){ $vplace = $scores->place; } if(isset($scores->building_score_main)){ $vbuilding_score_main = $scores->building_score_main; } if(isset($scores->research_score_main)){ $vresearch_score_main = $scores->research_score_main; } if(isset($scores->army_score_main)){ $varmy_score_main = $scores->army_score_main; } if(isset($scores->trader_score_secondary)){ $vtrader_score_secondary = $scores->trader_score_secondary; } array_push($final, ["avatar_id"=>$vavatar_id,"place"=>$vplace,"building_score_main"=>$vbuilding_score_main,"research_score_main"=>$vresearch_score_main,"army_score_main"=>$varmy_score_main,"trader_score_secondary"=>$vtrader_score_secondary ]); }
Loop through the avatarScores array, then search for the key in the idowner field of the $owners array. foreach (foreach($final[0][1]->avatarScores as $avatarOwner => $scores) { $vavatar_id = ""; $vplace = ""; $vbuilding_score_main = ""; $vresearch_score_main = ""; $varmy_score_main = ""; $vtrader_score_secondary = ""; $city = null; foreach ($owners as $owner) { if ($owner['idowner'] == $avatarOwner) { $city = $owner; break; } } if(isset($scores->avatar_id)){ $vavatar_id = $scores->avatar_id; } if(isset($scores->place)){ $vplace = $scores->place; } if(isset($scores->building_score_main)){ $vbuilding_score_main = $scores->building_score_main; } if(isset($scores->research_score_main)){ $vresearch_score_main = $scores->research_score_main; } if(isset($scores->army_score_main)){ $varmy_score_main = $scores->army_score_main; } if(isset($scores->trader_score_secondary)){ $vtrader_score_secondary = $scores->trader_score_secondary; } }
print ckeditor content from mysql
I am trying to print my content from the ckeditor I uploaded to the db. In the admin panel editing ckeditor it's normal, but once I print it in the site via: <?if (!empty($show['participants'])){?> <Div class="participants"> <?=$show['participants']?> </Div> <?}?> It's echo the tags only: <p><strong>אנדרס מוסטונן</strong>, מנצח (אסטוניה)<br><strong>קרן הדר, </strong>סופרן (ישראל)<br><strong>ארה סאל</strong>, בריטון (אסטוניה)<br><strong>מקהלת עמק חפר </strong><br><strong>מקהלה אסטונית</strong><br><br><br><strong>בתוכנית:</strong><br><strong>אורף</strong>: כרמינה בורנה<br><strong>יואב תלמי</strong>: אלגריה למיתרים, טימפני ואקורדיון</p> Var dumped $show: array(27) { ["id"]=> string(3) "432" ["code"]=> string(36) "63c8bc24-f730-e811-bd2b-10604ba9908f" ["name"]=> string(10) "הקיסר" ["title_short"]=> string(163) "מפגש ענקים - כריסטיאן יארווי ורומן רבינוביץ' בביצוע "הפנטסטית" של ברליוז ו"הקיסר" של בטהובן" ["title_long"]=> string(0) "" ["description"]=> string(29) "<p> </p>" ["participants"]=> string(612) "<p><strong>כריסטיאן יארווי</strong>,מנצח (אסטוניה)<br><strong>רומן רבינוביץ'</strong>, פסנתר (ישראל)<br><br><strong>בתוכנית:</strong><br><strong>בן חיים</strong>: "תרועה לישראל"<br><strong>בטהובן</strong>: קונצ'רטו לפסנתר מס' 5 – הקיסר<br><strong>ברליוז</strong>: סימפוניה פנטסטית<br><strong>ארוו פרט</strong>: Fratres</p>" ["image"]=> string(11) "keisarx.jpg" ["image_banner"]=> string(15) "julioskeiar.jpg" ["img_credits"]=> string(18) "בלש בורוץ'" ["video"]=> string(0) "" ["category_id"]=> string(2) "60" ["category_order"]=> string(1) "0" ["show_on_main"]=> string(1) "1" ["main_order"]=> string(1) "2" ["show_on_slide"]=> string(1) "0" ["slide_order"]=> string(1) "1" ["home_page"]=> NULL ["direct_link"]=> string(58) "http://tickets.isorl.co.il/he-IL/shows/הקיסר/events/1" ["english_name"]=> NULL ["english_direct_link"]=> NULL ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["update_auto_timestamp"]=> string(19) "2018-09-02 12:12:33" ["active"]=> string(1) "1" ["is_amfi_show"]=> string(1) "0" ["is_kunhiya_show"]=> string(1) "0" ["events"]=> array(3) { ["by_id"]=> array(2) { [1191]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } [1193]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["by_order"]=> array(2) { [0]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } [1]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["by_date"]=> array(2) { ["2018-10-07"]=> array(1) { [0]=> &array(20) { ["id"]=> string(4) "1191" ["code"]=> string(36) "e7869a2b-ff30-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-07" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(43) "היכל התרבות ראשון לציון" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(99) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-7_20.00/היכל ראשון לציון/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3709" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } ["2018-10-09"]=> array(1) { [0]=> &array(20) { ["id"]=> string(4) "1193" ["code"]=> string(36) "49a650f7-f630-e811-bd2b-10604ba9908f" ["date"]=> string(10) "2018-10-09" ["time"]=> string(8) "20:00:00" ["show_id"]=> string(3) "432" ["venue_code"]=> NULL ["venue_name"]=> string(71) "המשכן לאמנויות הבמה, בית האופרה תל אביב" ["english_venue_name"]=> NULL ["city"]=> NULL ["english_city"]=> NULL ["country"]=> NULL ["english_country"]=> NULL ["start_sale_date"]=> NULL ["end_sale_date"]=> NULL ["direct_link"]=> string(88) "http://tickets.isorl.co.il/he-IL/events/הקיסר/2018-10-9_20.00/בית האופרה/1" ["english_direct_link"]=> string(67) "http://tickets.isorl.co.il/loader.aspx/?target=hall.aspx?event=3695" ["is_active"]=> string(1) "1" ["update_timestamp"]=> string(19) "2018-08-09 12:52:29" ["is_for_sale"]=> string(1) "1" ["show_on_upcoming"]=> string(1) "0" } } } } } What is going wrong? Thanks.
Extract $item code from array in k2store
I try to extract and to show on the page with echo product code field in K2store cart page (store extension for K2 for Joomla) but without success. The right value is "product_code" or "code" (is the same value): 26910. Both "echo $item->product_name" and "echo $item->product_id" works, but "echo $item->code" and "echo $item->product_code" return NULL. var_dump($item) show me this: object(stdClass)#381 (13) { ["key"]=> int(9928417) ["product_id"]=> string(7) "9928417" ["product_name"]=> string(71) "some title" ["product_model"]=> NULL ["product_total"]=> int(1) ["product_options"]=> object(stdClass)#382 (0) { } ["quantity"]=> int(1) ["stock"]=> object(JObject)#378 (18) { ["_errors":protected]=> array(0) { } ["item_enabled"]=> string(1) "1" ["item_sku"]=> NULL ["item_price"]=> NULL ["special_price"]=> NULL ["item_tax_id"]=> NULL ["item_shipping"]=> NULL ["item_qty"]=> NULL ["item_cart_text"]=> NULL ["product_id"]=> string(7) "9928417" ["product_name"]=> string(71) "some title" ["product_code"]=> string(5) "26910" ["price"]=> NULL ["product_sku"]=> NULL ["tax_profile_id"]=> NULL ["item_minimum"]=> string(1) "1" ["stock"]=> *RECURSION* ["product"]=> object(stdClass)#354 (38) { ["id"]=> string(7) "9928417" ["code"]=> string(5) "26910" ["title"]=> string(71) "some title" ["alias"]=> string(71) "some title" ["catid"]=> string(3) "694" ["published"]=> string(1) "1" ["introtext"]=> string(0) "" ["fulltext"]=> string(0) "" ["video"]=> NULL ["gallery"]=> NULL ["extra_fields"]=> string(29) "[{"id":"1","value":"25\/40"}]" ["extra_fields_search"]=> string(6) "25/40 " ["created"]=> string(19) "2012-09-14 10:20:09" ["created_by"]=> string(2) "52" ["created_by_alias"]=> string(0) "" ["checked_out"]=> string(1) "0" ["checked_out_time"]=> string(19) "0000-00-00 00:00:00" ["modified"]=> string(19) "2012-09-14 10:30:46" ["modified_by"]=> string(2) "52" ["publish_up"]=> string(19) "2012-09-14 10:20:09" ["publish_down"]=> string(19) "0000-00-00 00:00:00" ["trash"]=> string(1) "0" ["access"]=> string(1) "1" ["ordering"]=> string(1) "1" ["featured"]=> string(1) "0" ["featured_ordering"]=> string(1) "0" ["image_caption"]=> string(0) "" ["image_credits"]=> string(0) "" ["video_caption"]=> string(0) "" ["video_credits"]=> string(0) "" ["hits"]=> string(5) "17852" ["params"]=> string(1190) "catItemTitle= catItemTitleLinked= catItemFeaturedNotice= catItemAuthor= catItemDateCreated= catItemRating= catItemImage= catItemIntroText= catItemExtraFields= catItemHits= catItemCategory= catItemTags= catItemAttachments= catItemAttachmentsCounter= catItemVideo= catItemVideoWidth= catItemVideoHeight= catItemVideoAutoPlay= catItemImageGallery= catItemDateModified= catItemReadMore= catItemCommentsAnchor= catItemK2Plugins= itemDateCreated= itemTitle= itemFeaturedNotice= itemAuthor= itemFontResizer= itemPrintButton= itemEmailButton= itemSocialButton= itemVideoAnchor= itemImageGalleryAnchor= itemCommentsAnchor= itemRating= itemImage= itemImgSize= itemImageMainCaption= itemImageMainCredits= itemIntroText= itemFullText= itemExtraFields= itemDateModified= itemHits= itemTwitterLink= itemCategory= itemTags= itemShareLinks= itemAttachments= itemAttachmentsCounter= itemRelated= itemRelatedLimit= itemVideo= itemVideoWidth= itemVideoHeight= itemVideoAutoPlay= itemVideoCaption= itemVideoCredits= itemImageGallery= itemNavigation= itemComments= itemAuthorBlock= itemAuthorImage= itemAuthorDescription= itemAuthorURL= itemAuthorEmail= itemAuthorLatest= itemAuthorLatestLimit= itemK2Plugins= " ["metadesc"]=> string(0) "" ["metadata"]=> string(15) "robots= author=" ["metakey"]=> string(0) "" ["plugins"]=> string(27) "{"k2storeitem_enabled":"1"}" ["code_search"]=> string(0) "" ["language"]=> string(0) "" } } ["tax_amount"]=> int(0) ["price"]=> int(0) ["price_without_tax"]=> int(0) ["total"]=> int(0) ["total_without_tax"]=> int(0) }
The solution is: $item->stock->product_code
Reading PHP array
I thought to access the value of '1' here, I would need to the following $data['category'][0]; ["category"]=> array(1) { [0]=> string(1) "1" } But it doesn't return anything. How would I access the string(1) section to get the value 1? Here is the full var dump of the variable $data array array(18) { ["RET"]=> string(65) "/account/add-submission" ["URI"]=> string(22) "account/add-submission" ["XID"]=> string(40) "3ee1766dfdbe4684831021c99a9197beaede03be" ["return_url"]=> string(36) "account/submission-complete/ENTRY_ID" ["channel_id"]=> string(1) "4" ["entry_id"]=> string(1) "0" ["ACT"]=> string(1) "4" ["meta"]=> string(556) "pdKeUQVJTA6FeLnmeqtK0gGu2C1S2gKOvRrMDjjKMou7JAp2HVA48Gn+yXTjY4tKuBam5rlyszhe3rEF2eClOB5bRPEJ8NYeh/qPBSkDuhuk0j+XYrQ0R7dJhaHZPIr1b5sge8/kqmWj2qvrpO5pE/iC6X4scIO2HmOPjWb4Sea2VgGwgQ70j7Qr1QmHlQAIZ95DXMp3YkietUWLWaFKvr8XwSx+vUhKEaueVoAbP0Le3fu0rMqz2LuZIScGpwn4yPJbenkc0P5ME/nM9CsfnzYPmM1cwTHO1Xe/wtJ3HGbNcglfn+A9ubz1GBNULgUvxYAW6eFrhqfAJ2omfiwSzpQkISJaDZvZofjOCHjiS7VaUIDgWOrznOm7oWR3m5Ut4TOxmsX2jeKpUAvLJQppc1+1hormnRSA0mambV0uodflDaZEZbPKmjWxsZD3doNJzmIG29bQtBV+UWdQ4xkxyM6fhyMmUkKGAgE+Xegkp/zK7+AXc4s8bEBENPAa1UbCkh0XEq4IYIqWRzYL/T2bfyySCPzvrbFBErIwj3jUF+w=" ["return"]=> string(36) "account/submission-complete/ENTRY_ID" ["site_id"]=> string(1) "1" ["submission_file_hidden_file"]=> string(0) "" ["submission_file_hidden_dir"]=> string(1) "1" ["type"]=> string(3) "1.1" ["snap_FxlgTgCET"]=> string(13) "vyHdSjitmEUoV" ["submission_file"]=> string(37) "{filedir_1}Tharp_BIO_Pic300x20038.jpg" ["field_id_48"]=> string(37) "{filedir_1}Tharp_BIO_Pic300x20038.jpg" ["field_ft_48"]=> string(4) "none" ["revision_post"]=> array(26) { ["RET"]=> string(65) "/account/add-submission" ["URI"]=> string(22) "account/add-submission" ["XID"]=> string(40) "3ee1766dfdbe4684831021c99a9197beaede03be" ["return_url"]=> string(36) "account/submission-complete/ENTRY_ID" ["author_id"]=> string(1) "1" ["channel_id"]=> string(1) "4" ["entry_id"]=> string(1) "0" ["ACT"]=> string(1) "4" ["meta"]=> string(556) "pdKeUQVJTA6FeLnmeqtK0gGu2C1S2gKOvRrMDjjKMou7JAp2HVA48Gn+yXTjY4tKuBam5rlyszhe3rEF2eClOB5bRPEJ8NYeh/qPBSkDuhuk0j+XYrQ0R7dJhaHZPIr1b5sge8/kqmWj2qvrpO5pE/iC6X4scIO2HmOPjWb4Sea2VgGwgQ70j7Qr1QmHlQAIZ95DXMp3YkietUWLWaFKvr8XwSx+vUhKEaueVoAbP0Le3fu0rMqz2LuZIScGpwn4yPJbenkc0P5ME/nM9CsfnzYPmM1cwTHO1Xe/wtJ3HGbNcglfn+A9ubz1GBNULgUvxYAW6eFrhqfAJ2omfiwSzpQkISJaDZvZofjOCHjiS7VaUIDgWOrznOm7oWR3m5Ut4TOxmsX2jeKpUAvLJQppc1+1hormnRSA0mambV0uodflDaZEZbPKmjWxsZD3doNJzmIG29bQtBV+UWdQ4xkxyM6fhyMmUkKGAgE+Xegkp/zK7+AXc4s8bEBENPAa1UbCkh0XEq4IYIqWRzYL/T2bfyySCPzvrbFBErIwj3jUF+w=" ["return"]=> string(36) "account/submission-complete/ENTRY_ID" ["site_id"]=> string(1) "1" ["title"]=> string(3) "asd" ["submission_file_hidden_file"]=> string(0) "" ["submission_file_hidden_dir"]=> string(1) "1" ["type"]=> string(3) "1.1" ["category"]=> array(1) { [0]=> string(1) "1" } ["snap_FxlgTgCET"]=> string(13) "vyHdSjitmEUoV" ["submission_file"]=> string(24) "Tharp_BIO_Pic300x200.jpg" ["field_id_48_hidden_file"]=> string(0) "" ["field_id_48_hidden_dir"]=> string(1) "1" ["field_id_48"]=> string(24) "Tharp_BIO_Pic300x200.jpg" ["field_ft_48"]=> string(4) "none" ["allow_comments"]=> string(1) "y" ["entry_date"]=> string(10) "1380114180" ["status"]=> string(4) "open" ["previous_status"]=> bool(false) } }
To access that data you have to use $data['revision_post']['category'][0] because category array is in revision_post array.
The value of $data['category'][0] is an array. So you would access like this: $data['category'][0] = array('1'); echo $data['category'][0][0]; Try it for yourself by copying and pasting here http://writecodeonline.com/php/
how to get result from codeigniter model as object
i'm using codeigniter for create a web site. and i need to take result from mysql table as this object(mysqli_result)#2 (5) { ["current_field"]=> int(0) ["field_count"]=> int(4) ["lengths"]=> NULL ["num_rows"]=> int(12) ["type"]=> int(0) } but always i got as a result something efferent from this. when i'm using result_object() in codeigniter i'm getting something like this array(12) { [0]=> object(stdClass)#24 (4) { ["id"]=> string(1) "1" ["label"]=> string(15) "Web Development" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [1]=> object(stdClass)#25 (4) { ["id"]=> string(2) "10" ["label"]=> string(19) "Sales and Marketing" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [2]=> object(stdClass)#26 (4) { ["id"]=> string(1) "7" ["label"]=> string(18) "Design and Artwork" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [3]=> object(stdClass)#27 (4) { ["id"]=> string(1) "2" ["label"]=> string(16) "Content Creation" ["link_url"]=> string(0) "" ["parent_id"]=> string(1) "0" } [4]=> object(stdClass)#28 (4) { ["id"]=> string(1) "4" ["label"]=> string(19) "OSCommerce projects" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "1" } [5]=> object(stdClass)#29 (4) { ["id"]=> string(1) "3" ["label"]=> string(8) "PHP Jobs" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "1" } [6]=> object(stdClass)#30 (4) { ["id"]=> string(1) "5" ["label"]=> string(22) "Technical Writing Jobs" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "2" } [7]=> object(stdClass)#31 (4) { ["id"]=> string(1) "6" ["label"]=> string(13) "Forum Posting" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "2" } [8]=> object(stdClass)#32 (4) { ["id"]=> string(1) "8" ["label"]=> string(20) "Blog Design Projects" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "7" } [9]=> object(stdClass)#33 (4) { ["id"]=> string(1) "9" ["label"]=> string(24) "Freelance Website Design" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(1) "7" } [10]=> object(stdClass)#34 (4) { ["id"]=> string(2) "11" ["label"]=> string(29) "Internet Marketing Consulting" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(2) "10" } [11]=> object(stdClass)#35 (4) { ["id"]=> string(2) "12" ["label"]=> string(25) "Leads Generation Services" ["link_url"]=> string(29) "/php_web_development_jobs.php" ["parent_id"]=> string(2) "10" } } $this->db->order_by('parent_id','id','ASC'); $query = $this->db->get('dyn_menu'); if ($query->num_rows() > 0) { $data = $query->result_object(); return $data; } how can i get the result as i want?
try using just result(), like: ... $data = $query->result(); return $data; ...
try this if single record you want, make $is_single = true if($is_single) return $query ->row_array(); else return $query ->result_array();