if(isset($_GET['cat'])) { $query = mysql_query("SELECT * FROM nb_posts WHERE category='".$_GET['cat']."'"); } else if(isset($_GET['user'])) { $query = mysql_query("SELECT * FROM nb_posts WHERE author='".$_GET['user']."'"); } else { $query = mysql_query("SELECT * FROM nb_posts"); }
Everything about it works, except for the ELSE part.
The script is supposed to display a list of posts. I've made a filter system, using Categories ('cat') or Users ('user'). If either of those is set, it returns the rows with the appropriate values, but if neither of them is set, it returns nothing.
I don't see anything "wrong". However, if by any chance you send an empty query string 'cat' or 'user' in the URL you would get nothing. To avoid that, you could check for !empty() instead of isset() on those variables.
"Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
~ Terry Pratchett in Nation
Bookmarks