Question

I have the following code which gets all news:

private function get_news()
    {   
        $news = array();

        $query  = $this->database->query("SELECT * FROM `news` ORDER BY `news_id` DESC");
        while($row = mysql_fetch_array($query))
        {
            $news[] = $row;
        }

        return $news;
    }

In the same class I have a bbedit() function. I want to get the value of $news[int]['news_content'] and pass it to that function bbedit().

Was it helpful?

Solution

Use $this to call a function within class:

private function bbedit(){
    $news = $this->get_news(); // news will have all your array
    foreach($news as $key => $val){
        // do something with $val['news_content'];
    }
}

or

while($row = mysql_fetch_array($query)){
    $news[] = $this->bbedit($row['news_content']);
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top