List of Images - 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: List of Images (/showthread.php?tid=64899) Pages:
1
2
|
List of Images - davy_yg - 04-09-2016 I simply trying to show LIST OF IMAGES on my website: <b>Latest Projects:</b><br><br> <img src="<?php echo base_url();?>images/large pic.jpg" width="200px">  <img src="<?php echo base_url();?>images/large pic3.jpg" width="200px">  <img src="<?php echo base_url();?>images/large pic4.jpg" width="200px">  <img src="<?php echo base_url();?>images/large pic5.jpg" width="200px" height="165px"> views/cms/index.php PHP Code: <?php A PHP Error was encountered Severity: Notice Message: Undefined property: CI_Loader::$db Filename: cms/index.php Line Number: 121 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\views\cms\index.php Line: 121 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\controllers\Welcome.php Line: 24 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\index.php Line: 315 Function: require_once Fatal error: Call to a member function query() on null in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\views\cms\index.php on line 121 A PHP Error was encountered Severity: Error Message: Call to a member function query() on null Filename: cms/index.php Line Number: 121 Backtrace: How to fix the above error? RE: List of Images - pb.sajjad - 04-09-2016 (04-09-2016, 03:38 AM)davy_yg Wrote: I simply trying to show LIST OF IMAGES on my website: Do you load database library in your Controller? ($this->load->database()) It seems you do not do that! RE: List of Images - Wouter60 - 04-09-2016 It's not good practice to perform a database query inside a view. The program's logic should be in your controller. PHP Code: //controller: PHP Code: //view: RE: List of Images - davy_yg - 04-17-2016 I have revised the controllers and views: This is the controllers : controllers/Site.php PHP Code: views/cms/index.php PHP Code: <b>Latest Projects:</b><br><br> This is the result: Latest Projects: A PHP Error was encountered Severity: Notice Message: Undefined variable: images Filename: cms/index.php Line Number: 123 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\views\cms\index.php Line: 123 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\controllers\Welcome.php Line: 24 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\index.php Line: 315 Function: require_once A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: cms/index.php Line Number: 123 Backtrace: File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\views\cms\index.php Line: 123 Function: _error_handler File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\controllers\Welcome.php Line: 24 Function: view File: C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\index.php Line: 315 Function: require_once What should I do to fix the program? RE: List of Images - PaulD - 04-18-2016 Your error is saying $images is not found, Before using a foreach loop you should at least check the item is set. PHP Code: <?php if($images) ?> So the query you are using to define images does not seem to be working. Hope that helps, Best wishes, Paul. RE: List of Images - JayAdra - 04-18-2016 (04-18-2016, 01:57 AM)PaulD Wrote: Your error is saying $images is not found, Probably best to check using: PHP Code: if(isset($images)) { Or the warning will still show up. RE: List of Images - davy_yg - 04-18-2016 Parse error: syntax error, unexpected '<' in C:\Program Files (x86)\EasyPHP-Devserver-16.1\eds-www\innovationci3\application\views\cms\index.php on line 139 A PHP Error was encountered Severity: Parsing Error Message: syntax error, unexpected '<' Filename: cms/index.php Line Number: 139 Backtrace: ------------------------------------------------------------------ <b>Latest Projects:</b><br><br> <img src="<?php echo base_url('images/large pic.jpg');?>" width="200px">  <img src="<?php echo base_url();?>images/large pic3.jpg" width="200px">  <img src="<?php echo base_url();?>images/large pic4.jpg" width="200px">  <img src="<?php echo base_url();?>images/large pic5.jpg" width="200px" height="165px"> views/cms/index.php PHP Code: <?php Line 139: <?php if($images) { ?> How to fix the error? Thanks in advance. RE: List of Images - InsiteFX - 04-18-2016 It's could be because you are using a space in the image name some servers do not like spaces in a file name. Try chataking the space out of the file name. RE: List of Images - Wouter60 - 04-18-2016 PHP Code: <?php Php can't handle this. Before using a <?php opening tag, the previous one should be closed with ?> So delete the first <?php opening tag! And a tip to make your code better to read: PHP Code: <?php if ($images) : ?> RE: List of Images - PaulD - 04-18-2016 Quote:Probably best to check using: True, I assumed that if his controller was trying to get images then it would return false if none found. However, if you are checking everything you should also check it is an array before the foreach too |