Welcome Guest, Not a member yet? Register   Sign In
(Easy) Message if tag not found
#1

[eluser]Jesse2303[/eluser]
Hi again Smile

I am stuck with some code

Normally he should give a message when no blogs were found with this tag, if i use a tag that some blogs have, the rights blogs appears but if i use a tag that no blog have nothing appears except my layout………

Somebody can help me ?

View: blogtag_view
Code:
<?php
        if($ctag->num_rows() == 0) {
?>
<div class="post">

    <div class="post_top">
        <div class="post_title"><h2>Oeps!</h2></div>
    </div>

    <div class="post_body">

        <p>Er zijn geen blogs met deze tag gevonden.</p>

    </div>

</div>
&lt;?php
} else {
foreach($query->result() as $row):
?&gt;
    
        <div class="post">

            <div class="post_top">
                <div class="post_title"><h2>&lt;?=anchor('blog/item/'.$row->id, $row->titel)?&gt;</h2></div>
                <div class="post_date">Gepost op &lt;?=date('D - M - Y, H:i:s', $row->datum)?&gt;, door <b>&lt;?=$row->poster?&gt;</b></div>
                <div class="post_date">Deze blog heeft <b>&lt;?=$row->tag?&gt;</b> als tag</div>
            </div>

            <div class="post_body">

                <p>&lt;?=nl2br($row->bericht)?&gt;</p>

            </div>

            <div class="post_metadata">
                <div class="content">
                    <span class="comment"><a href="#">0 Reacties</a></span>
                </div>
            </div>

        </div>
    

&lt;?php endforeach; ?&gt;
&lt;?php } ?&gt;

Class blog, function tag:
Code:
function tag() {
        
    //Blogitem gegevens laden
    $this->load->model('Show');
    
    $gegevens['query']         =     $this->Show->blog_tag();
    
    $this->load->model('Count');
    
    $gegevens['ctag']        =     $this->Count->tag_count();
    
    //Stuur naar view file
    $this->load->view('blogtag_view', $gegevens);
        
    }

Model: Count.php
Code:
&lt;?php

class Count extends Model {
    
    function Count() {
        
        parent::Model();
        
    }
    
    function tag_count() {
        
        $this->db->where('tag', $this->uri->segment(3));
        Return         $this->db->query('SELECT * FROM blogs ');
        
    }
    
}

?&gt;
#2

[eluser]thinkigniter[/eluser]
Does this help ?

Code:
&lt;?php
function tag() {
        
    //Blogitem gegevens laden
    $this->load->model('Show');
    $gegevens['query'] = $this->Show->blog_tag();
    // what does this first model do?
    // Does it retrieve your blogs
    
    
    $this->load->model('Count');
    
   $gegevens['ctag'] = $this->Count->tag_count();

   $this->load->view('blogtag_view', $gegevens);
     //Stuur naar view file
          
    }

Code:
&lt;?php
        if($ctag == NULL) {
?&gt;
<div class="post">

    <div class="post_top">
        <div class="post_title"><h2>Oeps!</h2></div>
    </div>

    <div class="post_body">

        <p>Er zijn geen blogs met deze tag gevonden.</p>

    </div>

</div>
&lt;?php
} else {
foreach($query as $row):
?&gt;
    
        <div class="post">

            <div class="post_top">
                <div class="post_title"><h2>&lt;?php echo anchor('blog/item/'.$row['id'], $row['titel']);?&gt;</h2></div>
                <div class="post_date">Gepost op &lt;?php echo date('D - M - Y, H:i:s', $row['datum']);?&gt;, door <b>&lt;?php echo $row['poster'];?&gt;</b></div>
                <div class="post_date">Deze blog heeft <b>&lt;?php echo $row['tag'];?&gt;</b> als tag</div>
            </div>

            <div class="post_body">

                <p>&lt;?=nl2br($row['bericht']);?&gt;</p>

            </div>

            <div class="post_metadata">
                <div class="content">
                    <span class="comment"><a href="#">0 Reacties</a></span>
                </div>
            </div>

        </div>
  
&lt;?php endforeach;
                } ?&gt;

Code:
&lt;?php

class Count extends Model {
    
    function Count() {
        
        parent::Model();
        
    }
    
    function tag_count() {
        
        $this->db->where('tag', $this->uri->segment(3) );
        $results = $this->db->query('SELECT * FROM blogs ');
        Return  $results;
        
    }
    
}

?&gt;

Let me know of any error messages you get
#3

[eluser]Sumon[/eluser]
Your model code is....
Code:
function tag_count() {

$this->db->where('tag', $this->uri->segment(3) );
$results = $this->db->query('SELECT * FROM blogs ');
Return  $results;

}

Change it by

Code:
function tag_count() {

$this->db->from('blogs');
$Condition=array('tag'=>$this->uri->segment(3));
$this->db->where($Condition);
return $this->db->get();

}
Hope it will help you.
#4

[eluser]Jesse2303[/eluser]
[quote author="Sumon" date="1216051709"]Your model code is....
Code:
function tag_count() {

$this->db->where('tag', $this->uri->segment(3) );
$results = $this->db->query('SELECT * FROM blogs ');
Return  $results;

}

is it be like this

Code:
function tag_count() {

$this->db->from('blogs');
$Condition=array('tag'=>$this->uri->segment(3));
$this->db->where($Condition);
return $this->db->get();

}
Hope it will help you.[/quote]

Wierd, al my other code with that model worksSmile

But it worked thanks anyway Wink




Theme © iAndrew 2016 - Forum software by © MyBB