Pagination in view does not show last entry on codeigniter - codeigniter

I have this problem:
the links form codeigniter pagination class does not show last entry,
e.g. if the total number of rows returned is 2, it will display on one results and the links to the last entry would be greyed out.
Here is the Controller:
function productlisting () {
$ids=$this->uri->segment(3);
$this->load->library('pagination');
$config['base_url'] = base_url().'index.php/listing_category/productlisting/'.$ids;
$config['per_page'] = '1';
$this->load->model('product_model');
$config['total_rows'] =$this->load->model('product_model')->get_num_product();
$this->pagination->initialize($config);
//load the model and get results
$pages = $this->uri->segment(3);//? $this->uri->segment(4) : 0;
$query['products']=$this->load->model('product_model')->get_specific_product($config['per_page'],$pages);
$query['paginated']=$this->pagination->create_links();
// load the view
echo $config['base_url'].'<br/>';
echo 'total rows:'. $config['total_rows'];
$this->template->build('product_display',$query);
}
Here is my model
//query to get the total number of rows
function get_num_product(){
$listingcategory = $this->uri->segment(3);
$this->db->select('default_listings.listing_id_unique,manufacturer,imagename,item_location,thumbnail,default_listings.item_category_id,product_name,item_serial_number,item_description,size,accessories,othercharacteristics,product_age');
$this->db->where('default_listings.item_category_id',$listingcategory);
$this->db->from('default_listings');
$this->db->join('default_listings_pics', 'default_listings.listing_id_unique=default_listings_pics.listing_id_unique', 'left');
$this->db->distinct('listing_id_unique');
$this->db->group_by('default_listings.listing_id_unique');
$queried= $this->db->get();
$rowcount = $queried->num_rows();
return $rowcount;
}
// Query to get the actual entries
function get_specific_product($num, $offset){
$listingcategory = $this->uri->segment(3);
$this->db->select('default_listings.listing_id_unique,manufacturer,imagename,item_location,thumbnail,default_listings.item_category_id,product_name,item_serial_number,item_description,size,accessories,othercharacteristics,product_age');
$this->db->where('default_listings.item_category_id',$listingcategory);
$this->db->from('default_listings');
$this->db->join('default_listings_pics', 'default_listings.listing_id_unique=default_listings_pics.listing_id_unique', 'left');
$this->db->distinct('listing_id_unique');
$this->db->group_by('default_listings.listing_id_unique');
$this->db->limit($num, $offset);
$query= $this->db->get()->result();
return $query;
}
and finally my view
<div id="catetogorylisitngcover">
<h1>Products</h1>
<?php foreach ( $products as $productdetail):?>
<div class="eachproducts">
<div class="productimage">
<?php if($productdetail->thumbnail):?>
<img src="<?php echo base_url();?>pictures/<?php echo $productdetail->thumbnail;?>"/>
<?php else :?>
<img src="<?php echo base_url();?>img/noimage.png"/>
</div>
<div class="productcover">
<div><span >Category Id:</span><span class="producttext"><?php echo $productdetail->item_category_id ;?></span></div>
<div><span >Product Name:</span><span class="producttext"><?php echo $productdetail->product_name;?></pan></div>
<div><span >Manufacturer :</span><span class="producttext"><?php echo $productdetail->manufacturer;?></span></div>
<div><span >Location :</span><span class="producttext"><?php echo $productdetail->item_location;?></span></div>
<div><span >Listing Id :</span><span class="producttext"><?php echo $productdetail->listing_id_unique;?></span></div>
<div class="learmoreproduct"><img src="<?php echo base_url();?>img/prodreadmore.png"/></div>
</div>
</div>
<?php endforeach;?>
<?php echo $this->pagination->create_links(); ?>
</div>
Help needed!

use it as
$this->load->library('pagination');
$config['base_url'] = your base url without offset in your case // base_url().'index.php/listing_category/productlisting/';
$config['total_rows'] = your total number of rows;
$config['per_page'] = number of rows you want to display;
$config['uri_segment'] = uri segment which will be used as offset;
$this->pagination->initialize($config);

Related

How do i retrieve images from folder which is linked to an item id?

The main issue is with the model, i cant figure out how to join the two tables so that i can display an item with its image which are stored in different locations.
model
$this->db->select('bs_items.id, bs_items.description, bs_items.title,
bs_items.touch_count,bs_items.price');
$this->db->from('core_images');
$this->db->join('bs_items', 'core_images.img_parent_id =
bs_items.id');
$this->db->order_by('bs_items.touch_count', 'desc');
$this->db->from('bs_items');
Controller:
this->load->model('Popular_car');
$this->load->model('Recent_car');
$data['popular_cars']= $this->Popular_car->popular_car();
$data['recent_cars']=$this->Recent_car->get_listing();
$this->load->view('templates/header');
$this->load->view('pages/home', $data);
$this->load->view('pages/home_recent', $data);
$this->load->view('templates/footer');
Please update your question with some code you have done , or database structure. i'm giving you the answer based on what i understood using your given code snippet.
Model
function get_items()
{
$this->db->select('*');
$this->db->from('core_images');
$this->db->join('bs_items', 'core_images.img_parent_id =
bs_items.id');
$this->db->order_by('bs_items.touch_count', 'desc');
$query = $this->db->get();
return $query->result();
}
Controller
function get_allitems()
{
$this->load->model('model_name');
$data['items'] = $this->model_name->get_items();
$this->load->view('view_name', $data);
}
View
<?php foreach ($items as $row): ?>
<h1><?php echo $row->title;?></h1>
<p><?php echo $row->touch_count;?></p>
<p><?php echo $row->price;?></p>
<p><?php echo $row->description;?></p>
<img src="<?php echo base_url().'path_of_image/'.$row->image_from_db; ?>
<?php endforeach; ?>
$myString = $this->db->get_where('profile_table' , array('id' => $edit ) )->row()->file_name_galery;
// $json11 = '{ "1":"s1.jpg", "2":"s2.jpg", "3":"s4.jpg", "4":"s4.jpg", "5":"s5.jpg" }';
$array = json_decode($myString);
if (empty($array)) {
echo '<p class="tx-danger"> NO IMAGE..</p>';
}
foreach($array as $key => $photo) { <div class="column_galery text-center zoom_img_app">
<a onclick="selected_photo(' echo $photo; ')" data-toggle="modal" data-target="#edit_image_mod" >
<img class="" src="http://yourapp.com/uploads/profile_gallery/ echo $photo; " style="width:100%"> <span class="tx-danger">DELETE</span> </a>
</div> }

How can i get manufacturer image in manucarturer page in opencart2.0.2.0?

I am using opencart version 2.0.2.0 and now i am trying to get image or image url in manufacturer page.
I have added the code in catalog/controller/product/manufacturer.php
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($manufacturer_id);
if($manufacturer_image){
$this->data['manufacturers_img'] = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$this->data['manufacturers_img'] = false;
}
and call it in catalog/view/theme/default/template/product/manufacturer_list.tpl
<div class="row">
<?php foreach ($manufacturers as $manufacturer) { ?>
<div class="col-sm-3"><?php echo $manufacturer['name']; ?>
<?php echo ($manufacturers_img) ? '<img src="'.$manufacturers_img.'" alt="'.$manufacturers.'" />' : $manufacturers ;?><br />
</div>
<?php } ?>
</div>
But it's getting error in my /index.php?route=product/manufacturer page
Notice: Undefined variable: manufacturers_img in
/data1/opencart-2.0.2.0/catalog/view/theme/default/template/product/manufacturer_list.tpl
on line 32Array
lets be clear ControllerProductManufacturer index() shows list and info() shows detail of the mfg,
//catalog/controller/product/manufacturer.php:46
Replace
$data['categories'][$key]['manufacturer'][] = array(
with
$manufacturer_image = $this->model_catalog_manufacturer->getManufacturer($result['manufacturer_id']);
if($manufacturer_image){
$mfg_img = $this->model_tool_image->resize($manufacturer_image['image'], 120, 120);
}else{
$mfg_img = false;
}
$data['categories'][$key]['manufacturer'][] = array(
'image'=>$mfg_img,
And in catalog/view/theme/default/template/product/manufacturer_list.tpl:30
inside loop
<?php if($manufacturer['image']):?>
<img src="<?php echo $manufacturer['image']; ?>" alt="<?php echo $manufacturer['name'];?>">
<?php endif;?>

Very slow product list issue with magento

I have a category called new arrivals which has 5 subcategories. I created a custom view called new-arrivals.phtml. I created custom Static Block with the following code in magento
{{block type="core/template" template="custom/new-arrivals.phtml"}}
then from Category setting I changed the display setting>CMS Block to the this cms block that I created. And the display mode is static block only
This view bring all the subcategories of New Arrivals(Bags, Tops, Shoes etc..) with it's products.. Like on this website As you can see on this website it is very fast but on my website with my code it is not. Here it is...
How can I make this load faster. Cache and everything is enabled. I assume that there is something wrong with my code. thank you for your help.
and this is new-arrivals.phtml content:
Magento CE 1.8.1
<?php
//I load all the subcategories here
$category = Mage::getSingleton('catalog/layer')->getCurrentCategory();
$categories = $category->getCollection()
->addAttributeToSelect(array('name', 'thumbnail'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($category->getChildren())
?>
<?php foreach ($categories as $category): ?>
<div class="page-title category-title">
<h1>
<a href="<?php echo $category->getUrl() ?>">
<span><?php echo $category->getName() ?></span>
</a>
</h1>
<?php
// here I load all the products for each category
$_helper = $this->helper('catalog/output');
$category = Mage::getModel('catalog/category')->load($category->getId());
$_productCollection = $category->getProductCollection()->addCategoryFilter($category)
->addAttributeToSelect('*') // add all attributes - optional
->addAttributeToFilter('status', 1) // enabled
->addAttributeToFilter('visibility', 4) //visibility in catalog,search
->addAttributeToSort('date_added', 'ASC');
?>
<div class="product-count"><?php echo $count; ?> <?php echo $this->__('Products'); ?></div>
<?php if(!$_productCollection->count()): ?>
<p class="note-msg"><?php echo $this->__('There are no products matching the selection.') ?></p>
<?php else: ?>
<div class="category-products">
<?php // Grid Mode ?>
<?php
$_span = 'span3';
$_grid_pro = 4;
?>
<?php $_collectionSize = $_productCollection->count() ?>
<?php $_columnCount = $_grid_pro; //$this->getColumnCount(); ?>
<?php $i=0; foreach ($_productCollection as $_product): ?>
<?php if ($i++%$_columnCount==0): ?>
<?php // all the others stuff ....... ?>
Load this file using ajax or jquery.
Second one you run your code on footer and make one variable then using jquery or java script, you will show your all data in particular div, for example like this
if (count($_subcategories) > 0){
$top_menu .= '<ul>';
foreach($_subcategories as $_subcategory){
$prodCollection = Mage::getModel('catalog/category')- >load($_subcategory->getId())
->getProductCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('type_id', array('eq' => 'grouped'))
->addAttributeToFilter('no_to_show', array('F' => 78));
if($prodCollection->count() !=0){
$top_menu .= '<li'; if($current_category == $_subcategory->getId()){$top_menu .= ' id="activesub"';}$top_menu .= '>'.$_subcategory->getName().'';
$_subcategories = Mage::getModel('catalog/category')->load($_subcategory->getId());
$_childsub = $_subcategories->getChildrenCategories();
$CatTotalCount = count($_childsub);
if($cntr == 0){
$firstCount = $CatTotalCount;
}
if($firstCount >= 7){
$loopCount = ($firstCount-1);
}else{
$loopCount = 6;
}
if($CatTotalCount >0){
$top_menu .= '<ul>';
$secCntr = 0;
foreach($_childsub as $_child_subcat){
$prodCollection2 = Mage::getModel('catalog/category')->load($_child_subcat->getId())->getProductCollection()->addAttributeToSelect('*')->addAttributeToFilter('type_id', array('eq' => 'grouped'))->addAttributeToFilter('no_to_show', array('F' => 78));
if( $secCntr>$loopCount){
$secCntr = 0;
$top_menu .= '</ul><ul>';
}
$secCntr++;
if($prodCollection2->count() !=0):
$top_menu .= '<li'; if($current_category == $_child_subcat->getId()){$top_menu .= ' id="activesub"';}$top_menu .= '>'.$_child_subcat->getName().'</li>';
endif;
} }
}
$top_menu .= '</ul></li>';
$cntr++;
}
$top_menu .= '</ul>';
}
jQuery(document).ready(function() {
document.getElementById('top_menus').innerHTML = '';
jQuery('#mega-menu-8').dcMegaMenu({
rowItems: '3',
speed: 'fast',
effect: 'fade'
});
});

How to use pagination to display one item per page

I want to display one fact per page using pagination but it displays all facts in one page.
Here is the controller am using
$config = array();
$config["base_url"] = base_url() . "Admin/news/index";
$config["total_rows"] = $this->news_model->record_count();
$config["per_page"] = 2;
$config["uri_segment"] = 1;
$this->pagination->initialize($config);
$page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
$data["results"] = $this->news_model->fetch_countries($config["per_page"], $page);
$data["links"] = $this->pagination->create_links();
And this is model
public function record_count() {
return $this->db->count_all("knowbank");
}
public function fetch_countries($limit, $start) {
$this->db->limit($limit, $start);
$query = $this->db->get("knowbank");
if ($query->num_rows() > 0) {
foreach ($query->result() as $row) {
$data[] = $row;
}
return $data;
}
return false;
}
Finally my view
<?php foreach ($news as $news_item): ?>
<div class="col1"><?php echo $news_item['title'] ?></div>
<img src="<?php echo base_url('image/' .$news_item['picture']);?>" style="max-width:210px; max-height:180px;"><br />
<p><?php echo $news_item['body'] ?></p>
<p>Category: <?php echo $news_item['category']?><br /><br />
Posted on: <?php echo $news_item['date']?>
</p>
View article<br /><br />
<?php endforeach ?>
<?php echo $links; ?>
Change the following and try, your page offset is the last segment of the url, so its 4
$config["per_page"] = 1;
$config["uri_segment"] = 4;
$page = ($this->uri->segment(4)) ? $this->uri->segment(4) : 0;

Codeigniter nested foreach in slideshow?

I ask this https://stackoverflow.com/a/14277726/1670630 on other post but my problem still exist.
In codeigniter 2.1 I'm trying to display channels by category. So if i have a category called Film, i should see a list of Channels within Film. I tried a nested foreach loop to accomplish this but can't seem to get it to work in the slidshow and limit by number of row.
My model:
<?php
class Pages_model extends CI_Model {
function get_channels_by_categ_tv()
{
$this->db->select('categories.category_name, channels.channel_name');
$this->db->from('type_categ');
$this->db->join('categories', 'categories.category_id = type_categ.category_id');
$this->db->join('channels', 'channels.channel_id = type_categ.channel_id');
$this->db->order_by('categories.category_id');
//$this->db->group_by(array('categories.category_id'));
$query = $this->db->get();
if($query->num_rows() == 0)
{
#no channels
return false;
}
return $query->result_array();
}
}
I have this in the view:
<ul class="slides">
<li>
<?php $cat_shown = ''; ?>
<div class="programe-tv_link">
<?php $cat_show = ''; $cnl_show = '';?>
<?php foreach ($category_chaneels as $category): ?>
<?php
if ($cat_show != $category['category_name']) {
$cat_show = $category['category_name'];
echo '<p>' . $cat_show . '</p>';
}
$cnl_show = $category['channel_name'];
echo '<dd> >>' . $cnl_show . '</dd> ';
?>
<?php endforeach; ?>
</div>
</li>
<li>
<div class="programe-tv_link">
<p>Arte</p>
<dd> >> Acasa</dd>
<dd> >> Antena 1</dd>
<dd> >> Pro TV</dd>
</div>
<div class="programe-tv_link">
<p>Music Box</p>
<dd> >> Acasa</dd>
<dd> >> Antena 1</dd>
<dd> >> Pro TV</dd>
<dd> >> TLC</dd>
</div>
</li>
</ul>
I atache image with ilustration,
sorry for my english and if you don't understund me please write here. THX in advance.
My finale code is this.
<div id="programe-tv-slide" class="flexslider">
<strong>Programe TV</strong>
<div class="redLine"></div>
<?php $cat_cnl = array();
$list = array();
$i=1;
foreach ($category_chaneels as $option) {
$catname = $option['category_name'];
$chlname = $option['channel_name'];
$cat_cnl[$catname][$i] = $chlname;
$list[$i] = $catname;
$i++;
};
?>
<?php
$rows = array_chunk($cat_cnl, 4, TRUE);
foreach ($rows as $row) { //var_dump($rows);
?>
<ul class="slides">
<?php
echo ('<li>');
foreach ($row as $category => $channels) {
echo '<div class="programe-tv_link">';
echo '<p>' . $category . '</p>';
foreach ($channels as $channel) {
echo '<dd>' . $channel . '</dd> ';
};
echo '</div>';
};
echo ('</li>');
?>
</ul>
<?php }; ?>
</div>

Resources