www.webdeveloper.com
Results 1 to 3 of 3

Thread: what's wrong with this?

  1. #1
    Join Date
    Aug 2009
    Posts
    53

    what's wrong with this?

    What's wrong with this script?

    PHP Code:
    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.

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,537
    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

    eBookworm.us

  3. #3
    Join Date
    Aug 2009
    Posts
    53
    Thank you, it works now.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles