Welcome Guest, Not a member yet? Register   Sign In
Help with CI, PHP & Javscript
#11

[eluser]the_unforgiven[/eluser]
Again thanks for the reply, I do understand but for some reason it;s not working not sure what i have done wrong, so here's all the code from each MVC.


Controller
Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Events extends Controller {
        
    function __construct() {
            parent::__construct();

            $this->load->helper('url');
            $this->load->model('Eventsmodel');
            $this->config->load('mcd');
    }

    function index() {
            
        $this->load->view('events');
    }
    
    public function getAll($id = null){
        
        if($id !=null){
            $data['contents'] = $this->Eventsmodel->getContents($id);
        }
        $this->load->view('events', $data);
        
    }
    
}

/* End of file events.php */
/* Location: ./application/controllers/events.php */


Model
Code:
<?php

class Eventsmodel extends Model {

    function __construct()
    {
        parent::__construct();
        // load database class and connect to MySQL
        $this->load->database();

    }
    
    function getLeftNav() {
        $qs = "SELECT id, creatd_on, title FROM mcd_events WHERE published='active'";
        
        if($qs->num_rows() > 0):
                    foreach($qs->result() as $row):
                        $data[] = $row;
                    endforeach;
                    return $data;
                else:
                    return false;
                endif;
        
    }
    
    function getRightDetails($id) {
        $qs = "SELECT description FROM mcd_events WHERE id='$id'";
    }
    
    function getDetails($id){
        
        if ($id) {
            $this->Eventsmodel->getRightDetails($id);
        }
    }
    
    
}
?>

View File
Code:
<!-- content left -->
<div id="content-left">
<div id="events">    
    
&lt;?php

    foreach $lhsList as $list){
               echo anchor('events/getAll/'.$id);
    }
?&gt;
            
</div>
</div>
&lt;!-- content left --&gt;

&lt;!-- content right --&gt;
<div id="content-right">
    
    <h2>Events/Rideouts</h2>
    
    <div id="display">

        &lt;?php
            if ($Contents) {
                echo $this->description;
                
            }
        ?&gt;

    </div>
    <div class="clear"></div>
</div>
&lt;!-- content right --&gt;
#12

[eluser]the_unforgiven[/eluser]
see attached file
#13

[eluser]the_unforgiven[/eluser]
Any replies??
#14

[eluser]the_unforgiven[/eluser]
Can someone please help me I really need to get this done asap
#15

[eluser]LuckyFella73[/eluser]
Do you have this code around line 77:
Code:
&lt;?php

    foreach $lhsList as $list){
               echo anchor('events/getAll/'.$id); // line 77 ?
    }
?&gt;
You should have something like
Code:
...
echo anchor('events/getAll/'.$list->id);
// or
echo anchor('events/getAll/'.$list['id']);
...
#16

[eluser]the_unforgiven[/eluser]
Yes I have something like that and changed to what you said and now I have this

A PHP Error was encountered

Severity: Notice

Message: Undefined variable: list

Filename: views/events.php

Line Number: 74
#17

[eluser]LuckyFella73[/eluser]
What output do you get when writing this in your view file?

Code:
// place where your foreach loop was before
echo "<pre>";
print_r($lhsList);
echo "</pre>";
#18

[eluser]the_unforgiven[/eluser]
Now I HAVE another error:
Severity: Notice

Message: Trying to get property of non-object

Filename: views/events.php

Line Number: 74

My view file:
Code:
<div id="events">    
&lt;?php echo "<pre>";
print_r($lhsList);
echo "</pre>";
?&gt;
&lt;?php foreach($events as $item) : ?&gt;
    <h3>&lt;?php echo anchor('events/getAll/'.$list->id); ?&gt;</h3>
&lt;?php endforeach; ?&gt;



</div>
</div>
&lt;!-- content left --&gt;

&lt;!-- content right --&gt;
<div id="content-right">
    
    <h2>Events/Rideouts</h2>
    
    <div id="display">
        &lt;?php foreach($events as $item) : ?&gt;
            &lt;?php echo $item['description']?&gt;
        &lt;?php endforeach; ?&gt;

    </div>
    <div class="clear"></div>
</div>
&lt;!-- content right --&gt;

Controller File:
Code:
&lt;?php if (!defined('BASEPATH')) exit('No direct script access allowed');

class Events extends Controller {
        
    function __construct() {
            parent::__construct();

            $this->load->helper('url');
            $this->load->model('Eventsmodel');
            $this->config->load('mcd');
    }

    function index() {
        
        // Get UL list for navigation
        $data['events'] = $this->Eventsmodel->getLeft();
        
        //$controller = $this->uri->segment(1);
        //$data['events'] = $this->Eventsmodel->getLeft($controller);        
        $this->load->view('events', $data);
    }
        
    function getDetails($id = null) {
            
        if($id != null){
            $data['mainContents'] = $this->Eventsmodel->getRightDetails($id);
        }
        $this->load->view('events', $data);
        
        $controller = $this->uri->segment(1);
        $data['events'] = $this->Eventsmodel->getRHSDetails(2);        
        $this->load->view($controller, $data);
    }
    
    
    
}

/* End of file events.php */
/* Location: ./application/controllers/events.php */

Model File
Code:
&lt;?php

class Eventsmodel extends Model {

    function __construct()
    {
        parent::__construct();
        // load database class and connect to MySQL
        $this->load->database();

    }
        
    function getLeft(){
       $query = $this->db->select('id', 'title', 'created_on');
       $query = $this->db->where('published', 'active');
       $query = $this->db->get('mcd_events');
       return $query->result();
    }
    
    function getRightDetails($id){
       $qs = "SELECT description FROM mcd_events WHERE id=$id";
       $this->load->view('events');
    }
    
    function getRHSDetails($id){
       if($id){
          $this->Eventsmodel->getRightDetails($id);
          $this->load->view('events');
       }
    }
    
    
}
?&gt;

I have followed through what has been said in previous posts but still struggling to find where I have gone wrong and why it's not doing what I logically think it should be doing.
#19

[eluser]LuckyFella73[/eluser]
In your previous post you had this loop:
Code:
&lt;?php

    foreach $lhsList as $list){
               echo anchor('events/getAll/'.$id);
    }
?&gt;
Thats why I asked you for debugging $lhsList

Now it seems you renamed it to $events - try with
$events then.
#20

[eluser]the_unforgiven[/eluser]
Ok with $events it outputs:
Code:
Array
(
    [0] => stdClass Object
        (
            [id] => 2
        )

    [1] => stdClass Object
        (
            [id] => 3
        )

)

Sorry my mistake i forgot to change it to $events




Theme © iAndrew 2016 - Forum software by © MyBB