![]() |
Why this error appears stdClass::$pic_item? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5) +--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24) +--- Thread: Why this error appears stdClass::$pic_item? (/showthread.php?tid=67155) |
Why this error appears stdClass::$pic_item? - davy_yg - 01-22-2017 site/views/index.php <?php foreach($pic as $pic_item): ?> <img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>"> <?php endforeach;?> controllers/Cspages.php
How to handle this error message? A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$pic_item Filename: views/index.php Line Number: 214 Backtrace: File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php Line: 214 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\controllers\Cspages.php Line: 31 Function: view File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\index.php Line: 315 Function: require_once http://localhost/masterlinkci2/assets1/images/slider/"> } views/index.php Line Number: 214 <img src="<?php echo base_url('assets1/images/slider/'.$pic_item->pic_item );?>"> RE: Why this error appears stdClass::$pic_item? - ciadmin - 01-22-2017 READ the error message! You are looping through a query result, assigning each to $pic_item. Then, in your view, you attempt to reference the pic_item property of $pic_item, and you are being told that $pic_item is not an object. Do a var_dump of $pic_item to see what it is. RE: Why this error appears stdClass::$pic_item? - InsiteFX - 01-23-2017 You would think by now he would know how to use the CODE tags! RE: Why this error appears stdClass::$pic_item? - davy_yg - 02-27-2017 I try to do the var_dump, the error remains the same as if nothing happens: <?php foreach($pic as $pic_item): ?> <img src="<?php echo base_url('assets1/images/slider/'.$pic->pic_item );?>"> <?php var_dump($pic_item); ?> <?php endforeach;?> A PHP Error was encountered Severity: Notice Message: Undefined property: stdClass::$pic_item Filename: views/index.php Line Number: 214 RE: Why this error appears stdClass::$pic_item? - ciadmin - 02-27-2017 READ the error message! You are looping through a query result, assigning each to $pic_item. Then, in your view, you attempt to reference the pic_item property of $pic_item, and you are being told that $pic_item is not an object. Do a var_dump of $pic_item to see what it is. You'll need to do the var_dump before referencing $pic_item->pic_item. Your var_dump is not reached beecause of the error message. RE: Why this error appears stdClass::$pic_item? - davy_yg - 02-27-2017 var_dump is string(2) "18" RE: Why this error appears stdClass::$pic_item? - ciadmin - 02-27-2017 Annnnnnnd ... there's your answer. $pic_item is a string, not an object with a nested pic_item property. The code inside your loop only needs to be Code: <img src="<?php echo base_url('assets1/images/slider/'.$pic_item);?>"> RE: Why this error appears stdClass::$pic_item? - davy_yg - 02-27-2017 A PHP Error was encountered Severity: 4096 Message: Object of class stdClass could not be converted to string Filename: views/index.php Line Number: 213 Backtrace: File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\views\index.php Line: 213 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\application\site\controllers\Cspages.php Line: 32 Function: view File: C:\Program Files (x86)\EasyPHP-DevServer-14.1VC9\data\localweb\masterlinkci2\index.php Line: 315 Function: require_once Line 213: <img src="<?php echo base_url('assets1/images/slider/'.$pic_item);?>"> TABLE galleries_pictures 1 picture_unique_id int(11) 2 gallery_id int(3) 3 galleries_picture_name varchar(30) RE: Why this error appears stdClass::$pic_item? - davy_yg - 03-02-2017 I finally get the answer but still cannot explain my own answer if anyone can help me explain this codes out: <?php foreach($pic as $pic_item): ?> <img src="<?php echo base_url('assets1/images/slider/'.$pic_item->galleries_picture_name);?>"> <?php endforeach;?> First, do I really need the foreach loop? Second, why $pic_item->galleries_picture_name works? RE: Why this error appears stdClass::$pic_item? - wolfgang1983 - 03-09-2017 When you ask question on here if you have code you can use the buttons in the editor one is call php and code ![]() Also might be best to watch some tutorials on you tube might learn some more stuff about codeigniter that way. |