× Please submit new Bug Reports on GitHub: github.com/Jensen-Technologies/component-creator-issues/issues

Select row where field contains certain values

il y a 10 ans 1 semaine #460 par Jan van de Laar
Select row where field contains certain values a été créé par 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:
$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?

Connexion ou Créer un compte pour participer à la conversation.

il y a 10 ans 1 semaine #461 par Jan van de Laar
Réponse de Jan van de Laar sur le sujet 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.
$cat = '%' . $db->escape( $cat, true ) . '%' ;

// Construct the SQL query
$query = 'SELECT * FROM #__table WHERE `categorie` LIKE ' . $db->quote( $db->escape( $cat ), false );

Connexion ou Créer un compte pour participer à la conversation.

Temps de génération de la page : 0.049 secondes
Propulsé par Kunena

We use cookies so that you can place orders and we can provide a better service. You can control the use of cookies at the individual browser level. If you reject cookies, you may still use our website, but your ability to use some features or areas of our website may be limited.