The Joomla! Forum ™



Forum rules


Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting, this means YOU.
Forum Post Assistant - If you are serious about wanting help, you will use this tool to help you post.



Post new topic Reply to topic  [ 2 posts ] 
Author Message
PostPosted: Wed May 02, 2012 7:54 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 08, 2008 9:00 am
Posts: 8
Location: Indonesia
please help me, I'm making a simple component to display a query from a table in the database. on these components I add a dropdown list that serves as a filter query on the table to be displayed and use the pagination. The problem is when the table show the pagination, and we choose the pagination numbers "1,2,3" characterized by "limitstart = 5 or 10 or more" followed by the selection of dropdownlist filter on the query results are not as expected because of problems in the variable "limitstart = 5/10 / other" can not be reset to "limitstart = 0". for more details please see my website at:
http://lamandaukab.bps.go.id/index.php/publikasi/advance-release-calendar-arc-beta

I show the following Class Arc Model, View, and tpl
Code:
class ArcsModelArcs extends JModel
{
   /**
    * Hellos data array
    *
    * @var array
    */
   var $_data;

    /**
   * Items total
   * @var integer
   */
  var $_total = null;
 
  /**
   * Pagination object
   * @var object
   */
  var $_pagination = null;

  function __construct()
  {
   global $mainframe;
    parent::__construct();
   
      $config = JFactory::getConfig();

      // Get the pagination request variables
      $this->setState('limit', $mainframe->getUserStateFromRequest('com_arc.limit', 'limit', $config->getValue('config.list_limit'), 'int'));
      $this->setState('limitstart', JRequest::getVar('limitstart', 0, '', 'int'));
      
      //$this->setState('years', JRequest::getWord('years'));
      //$this->setState('terbitan', JRequest::getWord('terbitan'));

   }


   /**
    * Returns the query
    * @return string The query to be used to retrieve the rows from the database
    */
   function _buildQuery()
   {
      // Get the WHERE and ORDER BY clauses for the query
      $where      = $this->_buildContentWhere();
      $query = ' SELECT a.* FROM #__arc AS a '
             .$where
             .' ORDER BY a.terbit_tanggal'
             ;
      return $query;
   }
   
   
   
   function _buildContentWhere()
   {
      global $mainframe, $option;
      $db                  =& JFactory::getDBO();
      $years               = $mainframe->getUserStateFromRequest( 'com_arc.years',   'years',   '',      'string' );
      $terbitan            = $mainframe->getUserStateFromRequest( 'com_arc.terbitan',   'terbitan',   '',   'string' );
   
      $where = array();
      if  ($years) {
         $where[] = 'LOWER(a.terbit_tanggal) LIKE '.$db->Quote( '%'.$db->getEscaped( $years, true ).'%', false );
      }
      if  ($terbitan) {
         $where[] = 'LOWER(a.periode) LIKE '.$db->Quote( '%'.$db->getEscaped( $terbitan, true ).'%', false );
      }
      $where       = ( count( $where ) ? ' WHERE '. implode( ' AND ', $where ) : '' );
      return $where;
   }
   
   /*
      return total rows..
   */
   function getTotal()
     {
    // Load the content if it doesn't already exist
       if (empty($this->_total)) {
           $query = $this->_buildQuery();
           $this->_total = $this->_getListCount($query);   
       }
       return $this->_total;
     }
   
   
   function getPagination()
     {
        // Lets load the content if it doesn't already exist
      if (empty($this->_pagination))
      {
         jimport('joomla.html.pagination');
         $this->_pagination = new JPagination( $this->getTotal(), $this->getState('limitstart'), $this->getState('limit') );
                         
      }
         return $this->_pagination;
   }
   
   /**
    * Retrieves the data
    * @return array Array of objects containing the data from the database
    */
   function getData()
   {
      // Lets load the data if it doesn't already exist
      if (empty( $this->_data ))
      {
         $query = $this->_buildQuery();
         $this->_data = $this->_getList( $query, $this->getState('limitstart'), $this->getState('limit') );
      }

      return $this->_data;
   }
   
}


View Class
Code:

class ArcsViewArcs extends JView
{
   /**
    * Hellos view display method
    * @return void
    **/
   function display()
   {
      global $mainframe, $option;
      $lists = array();
      
      // Get data from the model n throw it to template (default.php)
      $items      = & $this->get('Data');
      // get pagination from the model
           $pagination = & $this->get('Pagination');
      
      $filter_years = $mainframe->getUserStateFromRequest( $option.'years',   'years');
      $filter_terbitan = $mainframe->getUserStateFromRequest( $option.'terbitan','terbitan');
      
      $years[] = JHTML::_('select.option','',JText::_('---pilih tahun--'));
      for ($i=2011; $i<= date('Y'); $i++) {
         $years[] = JHTML::_('select.option',$i,JText::_($i));
      }
      $terbitan[] = JHTML::_('select.option','',JText::_('---pilih periode---'));
      $terbitan[] = JHTML::_('select.option','Tahunan',JText::_('Tahunan'));
      $terbitan[] = JHTML::_('select.option','Bulanan',JText::_('Bulanan'));
      $terbitan[] = JHTML::_('select.option','Mingguan',JText::_('Mingguan'));
      
      $lists['years']       = JHTML::_('select.genericlist',     $years, 'years', 'class="inputbox"', 'value', 'text',$filter_years);
      $lists['terbitan']    = JHTML::_('select.genericlist', $terbitan, 'terbitan','class="inputbox"','value','text',$filter_terbitan);
            
      $this->assignRef('pagination', $pagination);
      $this->assignRef('items',      $items);
      $this->assignRef('lists', $lists);
            
      parent::display();
   }
   
   
   
   
}


template default.php

Code:
<?php defined('_JEXEC') or die('Restricted access'); ?>
<form action="<?php echo JRoute::_( 'index.php?option=com_arc' );?>" method="get" name="userForm">
<div id="editcell">
   <table >
    <tr>
         <th align="left"><?php echo JText::_( 'Pilih Tahun' ); ?>:
         <?php echo $this->lists['years']; ?></th>         
            <th align="left"><?php echo JText::_( 'Pilih Periode Terbit' ); ?>:
         <?php echo $this->lists['terbitan']; ?></th>         
         
         <th> <button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button></th>
         
      </tr>
      
    </table>
    <table class="userlist" width="100%">
   <thead>
       <tr>
         <th width="5">
            <?php echo JText::_( 'No' ); ?>
         </th>
         <th>
            <?php echo JText::_( 'Judul' ); ?>
         </th>
            <th>
            <?php echo JText::_( 'Periode Terbit' ); ?>
         </th>         
         <th>
            <?php echo JText::_( 'Tanggal Terbit' ); ?>
         </th>
            <th>
            <?php echo JText::_( 'Status' ); ?>
         </th>
           
      </tr>
   </thead>
   <?php
   $k = 0;
   for ($i=0, $n=count( $this->items ); $i < $n; $i++)   {
      $row = &$this->items[$i];
      ?>
      <tr class="<?php echo "row$k"; ?>">
         <td>
            <?php echo $this->pagination->getRowOffset( $i ); ?>
         </td>
         <td>
               <?php echo JHTML::_('link',$row->link_judul, $row->judul); ?> </a>         
             </td>
            <td>
            <?php echo $row->periode; ?>
         </td>
            <td>
            <?php echo $row->terbit_tanggal; ?>
         </td>
            <td>
            <?php echo $row->status; ?>
         </td>
           
      </tr>
      <?php
      $k = 1 - $k;
   }
   ?>
    <tfoot>
            <tr>
               <td colspan="13">
                  <?php echo $this->pagination->getListFooter(); ?>
               </td>
            </tr>
         </tfoot>
         
   </table>
   
</div>

<input type="hidden" name="task" value="arc" />
<?php echo JHTML::_( 'form.token' ); ?>
</form>



I've tried to imitate the weblinks component and search but to no avail. please for the joomla master to help me how to make limitstart to "0" when making the request a new page so that the query can be generated accordingly.

thanks,. sory if my english is bad.. i'm from indonesia.. tks..

_________________
thanks..
free programming ebook (indonesian and us) , free hosting and domain :
please visit : www.nanofreesite.co.cc


Last edited by imanickam on Thu May 03, 2012 1:24 am, edited 1 time in total.
Your other post with the text "please someone.. help my problem.." created by 4:58AM IST on May3rd has been deleted. Please be aware that bumping is not allowed as per the forun rules.


Top
 Profile  
 
PostPosted: Thu May 03, 2012 2:59 am 
Joomla! Apprentice
Joomla! Apprentice

Joined: Sat Nov 08, 2008 9:00 am
Posts: 8
Location: Indonesia
so when i go to the page 2,3,.. and using the dropdownlist for making the filter of the query,. there is no result ,. actually i know there will be a result from the query... it's because the limitstart value is still in the earlier state,. this means the value of the limitstart variable doesnt change back to "0" when there is filtering on the query. the question is how can i set back the limitstart value to "0" when there is filtering on the query using drowpdownlist?? please give me a solution.. I've been trying for four days to solve this problem but it still does not work .. please help me .. tks...

_________________
thanks..
free programming ebook (indonesian and us) , free hosting and domain :
please visit : www.nanofreesite.co.cc


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 



Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group