Search the Community
Showing results for tags 'while loop'.
-
I've got a lot of questions today, it seems. I can't see where the problem is in this method, it seemed very simple when I started <?php public function recent() { $rule = "ORDER BY RAND()"; $field = "type"; $type = "recent"; $query = $this->_db->get(self::$_table, array($field, "=", $type), $rule); $this->_data = $query->all(); $counter = 0; while($counter <= 7) { foreach($this->data() as $obj) { if(strlen($obj->title) > 25) { $obj->title = substr($obj->title, 0, 25) . "..."; } $data = array("id" => $obj->id, "title" => $obj->title, "content" => $obj->content, "author" => $obj->author, "add_by" => $obj->add_by, "category" => $obj->post_category, "image" => $obj->post_image, "num_likes" => $obj->num_likes, "num_comments" => $obj->num_comments, "num_views" => $obj->num_views, "post_cat_id" => $obj->post_cat_id, "date_added" => $obj->date_added ); echo $this->html($type, $data); $counter ++; } // $counter ++; } } It's pretty self explanatory. retrieve all items within the criteria and display the first 8. Problem is it displays all of the items that fit the criteria. It works fine other than that and I can't see the problem. What am I overlooking?