I've tried to implement code for multiple search with sorting in an SQL query.
SELECT *, COUNT(*) as `total_ingredients`
FROM opskrifter as k
, ingredienser as i
WHERE k.id = i.opskrifterid
AND i.ing_name IN ('salt', 'kommen', 'hakkede tomater', 'pasta', 'stødt chilli')
GROUP BY k.id
ORDER BY COUNT(*) DESC;
It works fine when I run the statement in Mysql, but when I try to implement into our php search field, it only uses the first argument that we type.
SELECT *, COUNT(*) as `total_ingredients`
FROM opskrifter as k
, ingredienser as i
WHERE k.id = i.opskrifterid
AND i.ing_name IN ($vals)
GROUP BY k.id
ORDER BY COUNT(*) DESC;
Where $vals = "'" . str_replace(",", "', '", $searchquery) . "'"; and $searchsquery = $_POST['search']; //From the searchfield
Hope you can help me finding whatever I am missing here..
Thanks!