Build content where - filtro de busca

  • jonnsl
  • Avatar de jonnsl Autor do Tópico
  • Offline
  • JCB! Estagiário
  • JCB! Estagiário
Mais
14 anos 7 meses atrás #13977 por jonnsl
jonnsl created the topic: Build content where - filtro de busca
estou desenvolvendo um componente, e na parte administrativa eu coloquei um filtro para que se possa ser feita buscas, igual aos componentes contente, weblinks etc...
eu fiz baseado no componente Weblinks, coloquei exatamente igual, mas não esta querendo funcionar
Modelo
	function _fazQuery()
    {
        // Get the WHERE and ORDER BY clauses for the query
		$where		= $this->_buildContentWhere();
		$orderby    = $this->_buildContentOrderBy();
		
    	$query = 'SELECT * '
            . 'FROM #__games '
			.$orderby
			.$where
        ;
        return $query;
    }	

function _buildContentWhere()
	{
		global $mainframe, $option;
		$db =& JFactory::getDBO();
		$search = $mainframe->getUserStateFromRequest( $option.'search', 'search', '', 'string' );
		$search = JString::strtolower( $search );

		$where = array();

		if ($search) {
			$where[] = $db->nameQuote('title').' LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
		}

		if(count($where) > 1){
			$finalwhere = ' WHERE '.implode('AND',$where);
		}
		if(count($where) == 1){
			$finalwhere = ' WHERE '.$where;
		}
		if(count($where) == 0){
			$finalwhere = '';
		}

		return $finalwhere;
	}
Visão
    function display($tpl = null)
	{
		global $mainframe, $option;
		$search = $mainframe->getUserStateFromRequest($option.'search', 'search', '', 'string' );
		$search = JString::strtolower( $search );
	// search filter
	$lists['search']= $search;
	$this->assignRef('lists', $lists);
no Template
	<td align="left" width="100%">
		<?php echo JText::_( 'Filter' ); ?>:
		<input type="text" name="search" id="search" value="<?php echo $this->lists&#91;'search'&#93;;?>" class="text_area" onchange="document.adminForm.submit();" />
		<button onclick="this.form.submit();"><?php echo JText::_( 'Go' ); ?></button>
		<button onclick="document.getElementById('search').value='';this.adminForm.submit();"><?php echo JText::_( 'Reset' ); ?></button>
	</td>
se não colocar nada no campo de busca aparece os itens normalmente, mas quando coloca qualquer coisa da erro e mesmo se clicar no botão zerar continua dando erro: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in
O que eu estou fazendo de errado?

Please Entrar ou Registrar to join the conversation.


Mais
14 anos 7 meses atrás #13981 por elvisvinicius
elvisvinicius replied the topic: Re: Build content where - filtro de busca
A mensagem de erro refere-se ao MySQL não ter obtido nehnum resultado na consulta.

if ($search) {
$where[] = $db->nameQuote('title').' LIKE '.$db->Quote( '%'.$db->getEscaped( $search, true ).'%', false );
}

Amigo, experimenta do jeito tradicional.
Bati muita cabeça com isso até me tocar onde era o problema. No meu caso, eu faria assim:

$where[] = "`title` LIKE '%" . $db->getEscaped($search, true) . "%'";

O problema são essas função do Joomla! junto com a parte do LIKE. Por algum motivo atrapalha o funcionamento da query.

( ^ ^)

Please Entrar ou Registrar to join the conversation.

  • jonnsl
  • Avatar de jonnsl Autor do Tópico
  • Offline
  • JCB! Estagiário
  • JCB! Estagiário
Mais
14 anos 7 meses atrás #13982 por jonnsl
jonnsl replied the topic: Re: Build content where - filtro de busca
Muito Obrigado elvisvinicius. Funcionou Perfeitamente. <!-- s:P --><img src="{SMILIES_PATH}/icon_razz.gif" alt=":P" title="Legal" /><!-- s:P --> <!-- s:ugeek: --><img src="{SMILIES_PATH}/icon_e_ugeek.gif" alt=":ugeek:" title="Uber Geek" /><!-- s:ugeek: -->

Please Entrar ou Registrar to join the conversation.