Welcome Guest, Not a member yet? Register   Sign In
counting for a reply
#11

[eluser]marjune[/eluser]
in my controller i did lyk this but it didn't work

Code:
function content(){
        $furomcontent['data'] = $this->furom->furomcontent();
    foreach($data as $field){
        $topic_id = $field->topic_id;
    }
    $furomcontent['data'] = $this->furom->countreply($topic_id); // counting reply here
    $this->load->vars($furomcontent);
    $this->load->view('viewfurom');
     }
#12

[eluser]InsiteFX[/eluser]
When using $this->load->vars(); you have to pass it a associative array.

Code:
$furomcontent = array('replies' => $this->furom->countreply($topic_id));
    $this->load->vars($furomcontent);

Enjoy
InsiteFX
#13

[eluser]Zeeshan Rasool[/eluser]
yeah its a good question. I also face this issue usually, i did as you are doing by calling model function directly in view inside foreach loop ;-)
i know its not good but how can we show total comments of each post?
One way is that we calculate this in controller and pass all counted values in assoc array. But it means we have to execute loop twice One in controller to calculate records and second in view to print postings or records.
Any other idea will be appreciated
#14

[eluser]Twisted1919[/eluser]
Why not create a "post_replies" field in your "posts" table, and update it everytime a new reply is made ?
I'm just saying...
#15

[eluser]clip[/eluser]
[quote author="marjune" date="1256821023"]in my controller i did lyk this but it didn't work

Code:
function content(){
        $furomcontent['data'] = $this->furom->furomcontent();
    foreach($data as $field){
        $topic_id = $field->topic_id;
    }
    $furomcontent['data'] = $this->furom->countreply($topic_id); // counting reply here
    $this->load->vars($furomcontent);
    $this->load->view('viewfurom');
     }
[/quote]

you are overiding your initial $furomcontent['data'] with the result from $this->furom->countreply($topic_id) maybe try changing it to:

Code:
$furomcontent['reply_count'] = $this->furom->countreply($topic_id); // counting reply here
$this->load->vars($furomcontent);
    $this->load->view('viewfurom');

Then in your view you can just echo:
Code:
<?php echo $reply_count; ?>
#16

[eluser]Zeeshan Rasool[/eluser]
[quote author="Twisted1919" date="1256842576"]Why not create a "post_replies" field in your "posts" table, and update it everytime a new reply is made ?
I'm just saying...[/quote]
Nice! i think this is a good idea Smile thanks
#17

[eluser]marjune[/eluser]
i'm aware of that, but why would we add another field in the database table which is not needed, although we can maneuver it in the sql query
#18

[eluser]InsiteFX[/eluser]
Here

MySQL COUNT

Enjoy
InsiteFX
#19

[eluser]marjune[/eluser]
i got it!! in the view were the foreach loop i made a query instead in the model
#20

[eluser]jhayghost[/eluser]
Code:
function furomcontent(){
    $sql = "SELECT a.fname, a.lname, topic_id, topic, views, lpost, (select count(topic2.acc_id) from forum_topic as topic2 where topic2.acc_id = forum_topic.acc_id) as countreply
        FROM account a JOIN forum_topic ON a.acc_id = forum_topic.acc_id
        ORDER BY topic_id DESC";
    $query = $this->db->query($sql);
    return $query->result();
                  
}




Theme © iAndrew 2016 - Forum software by © MyBB