Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mysql AND WHERE selection

Tags:

php

mysql

i have te make a slection but cannot get it to work with the WHERE LIKE function. What is wrong with the line below?

$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' AND ORDER BY id DESC");

It worked until i added

AND platform LIKE '%wiiu%'

The platform column contains cells with multiple values that come from a selection box form. So it writes, wiiu, ps4, xbox360, pc etc....Must be simple but i tried like a million times...

like image 253
Kenny Bloem Avatar asked Dec 01 '22 18:12

Kenny Bloem


2 Answers

Remove the AND before ORDER BY

$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' AND ORDER BY id DESC");

should be

$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' ORDER BY id DESC");
like image 194
karthikr Avatar answered Dec 10 '22 04:12

karthikr


There is an extra AND, it should be:

$result = mysql_query("SELECT * FROM games WHERE soort='nieuws' AND gamenaam='$spelnaam' AND platform LIKE '%wiiu%' ORDER BY id DESC");
like image 35
Cobra_Fast Avatar answered Dec 10 '22 03:12

Cobra_Fast