Welcome Guest, Not a member yet? Register   Sign In
Not displaying Summary
#1

[eluser]GamingFusion[/eluser]
I am trying to get the summary of a show that i add to the database to display when the 3rd segment is present.

for example

theatre/show

//Doesn't display the summary

theatre/show/3

//displays the summary

but its not displaying it at all if the segment is there or not.

controller
Code:
function show()
    {
        if ($this->uri->segment(3) === TRUE)
        {
            $data['single'] = $this->database->getShow($this->uri->segment(3));            
        }
        
        $data['title'] = 'Theater 311 | Shows';
        $data['query'] = $this->database->getShows();
        $data['content'] = 'show';
        $data['css'] = 'site';
        
        $this->load->view('includes/templates', $data);
    }

view
Code:
<div class="shows" style="width:95%; height:350px; margin-top:10px; overflow:auto;">
         &lt;?php if (isset($single)){?&gt;
                 &lt;?php foreach($single as $row): ?&gt;
                     <div class="show">
                            <div class="title">
                                &lt;?=anchor('theater/show/' . $row->id, 'Details')?&gt;
                                &lt;?php if ($this->session->userdata('isLoggedIn')) { ?&gt;
                                    &lt;?=anchor('members/editShow/' . $row->id, 'Edit')?&gt;
                            &lt;?php }?&gt;
                                 <h2><b>&lt;?=$row->title?&gt;</b></h2>
                             <small>Directed by: &lt;?=$row->director?&gt;</small>
                               </div>
                               <h3><b>Summary</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->desc)?&gt;</p>
                         <h3><b>Show Times</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->showtimes)?&gt;</p>
                         <h3><b>Cast</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->cast)?&gt;</p>
    
                         </div>
                &lt;?php endforeach; ?&gt;
             &lt;?php }else{ ?&gt;
                &lt;?php foreach($query as $row): ?&gt;
                     <div class="show">
                            <div class="title">
                                &lt;?=anchor('theater/show/' . $row->id, 'Details')?&gt;
                                &lt;?php if ($this->session->userdata('isLoggedIn')) { ?&gt;
                                    &lt;?=anchor('members/editShow/' . $row->id, 'Edit')?&gt;
                            &lt;?php }?&gt;
                                 <h2><b>&lt;?=$row->title?&gt;</b></h2>
                             <small>Directed by: &lt;?=$row->director?&gt;</small>
                
                               </div>
                         <h3><b>Show Times</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->showtimes)?&gt;</p>
                         <h3><b>Cast</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->cast)?&gt;</p>
    
                         </div>
                &lt;?php endforeach; ?&gt;
            &lt;?php } ?&gt;
    </div>
#2

[eluser]Ben Edmunds[/eluser]
Change

Code:
if ($this->uri->segment(3) === TRUE)

to

Code:
if ($this->uri->segment(3))
#3

[eluser]GamingFusion[/eluser]
ok thanx man but now its not getting the database info i have it run the function getShow($this->uri->segment(3)) which should get lets says the 3rd row form the databse but it doesnt heres the error there are multiple but they all link to the same thing

Quote:A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/show.php

Line Number: 6

view
Code:
<div class="shows" style="width:95%; height:350px; margin-top:10px; overflow:auto;">
         &lt;?php if (isset($single)){?&gt;
                 &lt;?php foreach($single as $row): ?&gt;
                     <div class="show">
                            <div class="title">
                                &lt;?=anchor('theater/show/' . $row->id, 'Details')?&gt;
                                &lt;?php if ($this->session->userdata('isLoggedIn')) { ?&gt;
                                    &lt;?=anchor('members/editShow/' . $row->id, 'Edit')?&gt;
                            &lt;?php }?&gt;
                                 <h2><b>&lt;?=$row->title?&gt;</b></h2>
                             <small>Directed by: &lt;?=$row->director?&gt;</small>
                               </div>
                               <h3><b>Summary</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->desc)?&gt;</p>
                         <h3><b>Show Times</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->showtimes)?&gt;</p>
                         <h3><b>Cast</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->cast)?&gt;</p>
    
                         </div>
                &lt;?php endforeach; ?&gt;
             &lt;?php }else{ ?&gt;
                &lt;?php foreach($query as $row): ?&gt;
                     <div class="show">
                            <div class="title">
                                &lt;?=anchor('theater/show/' . $row->id, 'Details')?&gt;
                                &lt;?php if ($this->session->userdata('isLoggedIn')) { ?&gt;
                                    &lt;?=anchor('members/editShow/' . $row->id, 'Edit')?&gt;
                            &lt;?php }?&gt;
                                 <h2><b>&lt;?=$row->title?&gt;</b></h2>
                             <small>Directed by: &lt;?=$row->director?&gt;</small>
                
                               </div>
                         <h3><b>Show Times</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->showtimes)?&gt;</p>
                         <h3><b>Cast</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->cast)?&gt;</p>
    
                         </div>
                &lt;?php endforeach; ?&gt;
            &lt;?php } ?&gt;
    </div>

controller
Code:
function show()
    {
        if ($this->uri->segment(3))
        {
            $data['single'] = $this->database->getShow($this->uri->segment(3));            
        }
        
        $data['title'] = 'Theater 311 | Shows';
        $data['query'] = $this->database->getShows();
        $data['content'] = 'show';
        $data['css'] = 'site';
        
        $this->load->view('includes/templates', $data);
    }

model
Code:
//getShow Function
    function getShow($id)
    {
        //Get Shows Data
        $this->db->where('id', $id);
        $query = $this->db->get('shows');
        
        return $query->row();
    }
#4

[eluser]Rahul Anand[/eluser]
please check your queries. there must be a "Where" statement. is it there? if yes then when the 3rd segment is not present then it return "0". convert it to normal query without "where": statement if the 3rd segment is not there. then it will return


Thanks
Rahul Anand
#5

[eluser]GamingFusion[/eluser]
Ok i switched up the code a bit and now i get a new error.

error
Quote:Fatal error: Call to undefined method stdClass::num_rows() in /home/theatre2/public_html/system/application/views/show.php on line 2

code
Code:
<div class="shows" style="width:95%; height:350px; margin-top:10px; overflow:auto;">
         &lt;?php if ($single->num_rows() > 0)
                {
                   $row = $single->row();?&gt;
                  
                     <div class="show">
                            <div class="title">
                                &lt;?=anchor('theater/show/' . $row->id, 'Details')?&gt;
                                &lt;?php if ($this->session->userdata('isLoggedIn')) { ?&gt;
                                    &lt;?=anchor('members/editShow/' . $row->id, 'Edit')?&gt;
                            &lt;?php }?&gt;
                                 <h2><b>&lt;?=$row->title?&gt;</b></h2>
                             <small>Directed by: &lt;?=$row->director?&gt;</small>
                               </div>
                               <h3><b>Summary</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->desc)?&gt;</p>
                         <h3><b>Show Times</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->showtimes)?&gt;</p>
                         <h3><b>Cast</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->cast)?&gt;</p>
                        
                         </div>
                     &lt;?=$single;?&gt;
                
             &lt;?php }else{ ?&gt;
                &lt;?php foreach($query as $row): ?&gt;
                     <div class="show">
                            <div class="title">
                                &lt;?=anchor('theater/show/' . $row->id, 'Details')?&gt;
                                &lt;?php if ($this->session->userdata('isLoggedIn')) { ?&gt;
                                    &lt;?=anchor('members/editShow/' . $row->id, 'Edit')?&gt;
                            &lt;?php }?&gt;
                                 <h2><b>&lt;?=$row->title?&gt;</b></h2>
                             <small>Directed by: &lt;?=$row->director?&gt;</small>
                
                               </div>
                         <h3><b>Show Times</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->showtimes)?&gt;</p>
                         <h3><b>Cast</b></h3>
                         <p>&lt;?=$this->typography->nl2br_except_pre($row->cast)?&gt;</p>
    
                         </div>
                &lt;?php endforeach; ?&gt;
            &lt;?php } ?&gt;
    </div>
#6

[eluser]Rahul Anand[/eluser]
Hi,
had a look at your code. could you please mail me the file at [email protected]? Let me check it once. and please check out the "$single"......I am sure you are having some query binding problem. that's why it is showing num_rows as a undefined method.


Thanks
Rahul




Theme © iAndrew 2016 - Forum software by © MyBB