×
Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues
Select row where field contains certain values
Jan van de Laar
Navegador Iniciado
Posts: 5
10 años 1 semana antes #460
por Jan van de Laar
Select row where field contains certain values Publicado por Jan van de Laar
Hi All
I've built a component with two tables, one of them is named 'categorie'. I can select more than one. In the database there is a field "categorie" and it contains " 1, 3 ". So this row matches with categories 1 and 3.
Now I want to select the proper rows in my frontend view and I want to use this where clause:
But this only works with value 1, when I try value 3 there are no database results. I tried using LIKE but that doen't work either. Can someone please help me with this?
I've built a component with two tables, one of them is named 'categorie'. I can select more than one. In the database there is a field "categorie" and it contains " 1, 3 ". So this row matches with categories 1 and 3.
Now I want to select the proper rows in my frontend view and I want to use this where clause:
$query->where($db->quoteName('categorie') . ' = 1 ');
But this only works with value 1, when I try value 3 there are no database results. I tried using LIKE but that doen't work either. Can someone please help me with this?
Por favor, Identificarse o Crear cuenta para unirse a la conversación.
Jan van de Laar
Navegador Iniciado
Posts: 5
10 años 1 semana antes #461
por Jan van de Laar
Respuesta de Jan van de Laar sobre el tema Select row where field contains certain values
Just found the solution:
// Construct the search term by escaping the user-supplied string and, if required, adding the % wildcard characters manually.
// Construct the SQL query
// Construct the search term by escaping the user-supplied string and, if required, adding the % wildcard characters manually.
$cat = '%' . $db->escape( $cat, true ) . '%' ;
// Construct the SQL query
$query = 'SELECT * FROM #__table WHERE `categorie` LIKE ' . $db->quote( $db->escape( $cat ), false );
Por favor, Identificarse o Crear cuenta para unirse a la conversación.
Tiempo de carga de la página: 0.048 segundos