I have a mysql table as below,
+---+-------+-----------+
|Sl | Name | Status |
+---+-------+-----------+
| 1 | Name1 | Active |
| 2 | Name2 | Inactive |
| 3 | Name3 | Pending |
| 4 | Name4 | Dont Know |
| 5 | Name5 | Active |
+---+-------+-----------+
I h开发者_StackOverflow中文版ave a sql query $query="select * from table ";
which fetch array and give me all records. But I want to display only specific rows with Status= Active or Inactive.
Add a WHERE
clause to your SQL so it becomes,
SELECT * FROM table WHERE Status='Active'
So in your PHP code it would be,
$query = "SELECT * FROM table WHERE Status='Active'";
Then replace "Active" with "Inactive" or "Pending", etc. depending on what you which rows you want to get.
Update 1: If you want rows that are both "Active" and "Inactive", you can add multiple expressions in the WHERE clause and combine them with "OR". For example,
SELECT * FROM table WHERE Status='Active' OR Status='Inactive'
Update 2: You can add your !='Trashed'
condition if you want, but it will have no effect on the outcome since you're only returning rows that are explicitly "Active" or "Inactive" anyway. But as this is just an example, add this to the end of the query,
AND Status!='Trashed'
use WHERE
clause with OR
operator
SELECT * FROM table WHERE Status='Active' OR Status='Inactive'
its simple add to the query
AND Status !='Trashed'
SELECT * FROM table WHERE Status IN ("Active", "Inactive");
You need to alter your SQL
SELECT * FROM table WHERE Status = 'Active' OR Status = 'Inactive'
精彩评论