tags:

views:

42

answers:

2

I have a table in mysql with a row called 'newrelease'. If the item is a new release my form posts it as 'yes' if no 'no'.

How would i display all items that contain the data 'yes'?

$query = "SELECT * FROM movielist ORDER BY newrelease DESC LIMIT 4";

+1  A: 

...

$query = "SELECT * FROM movielist where newrelease = 'yes' ORDER BY newrelease DESC LIMIT 4";
Sarfraz
+1  A: 

You could filter the data on the PHP side, but that would be a bad idea : it would mean load more data than you need, for nothing...

The best solution is to use a where clause in your SQL query, which would then look like this :

SELECT * 
FROM movielist 
WHERE newrelease = 'yes'
ORDER BY newrelease DESC 
LIMIT 4

Up to you to re-integrate this in your PHP code ;-)


And, as an example of page that could give you some additionnal informations : Where (SQL) on wikipedia.

Pascal MARTIN
This is correct but - because I'm OCD - I thought I would mention that the ORDER BY can be removed since we are only allowing a single value for newrelease. Actually the optimizer might remove it automatically - not quite sure - but I thought I would mention it anyway.
malonso
@malonso : true, it could be removed -- I didn't notice that the `order by` clause was on the same column as the `where` :-(
Pascal MARTIN