I have a database and i want to sort results like this:
$query1 = "SELECT * FROM pictures LIMIT 0,10 ";
$result = mysql_query($query1);
while($row = mysql_fetch_array($result))
echo $row['picture_rating'];
and
$query1 = "SELECT * FROM pictures WHERE column_name = 'column_text' ";
$result = mysql_query($query1);
while($row = mysql_fetch_array($result))
echo $row['picture_rating'];
Both of the codes above are working properly, but when i want to use both condition at one time like this:
$query1 = "SELECT * FROM pictures LIMIT 0,10 WHERE column_name = 'column_text' ";
it doesnt work. Any ideas how to make it work? Thanx!
SOLVED: Information that LIMIT should be after WHERE was exactly what i needed. Thanx to all.
Try:
"SELECT * FROM pictures WHERE column_name = 'column_text' LIMIT 0,10";
If you have a look at the MySQL documentation on SELECT
, you will see, that the WHERE
clause has to come before the LIMIT
clause.
SELECT * FROM `pictures`
WHERE `column_name` = 'column_text'
LIMIT 0,10
the SQL syntax for SELECT defines that LIMIT should be after WHERE