Results 1 to 3 of 3

Thread: what's wrong with this?

Hybrid View

  1. #1
    Join Date
    Aug 2009

    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
    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.
    "Well done....Consciousness to sarcasm in five seconds!" ~ Terry Pratchett, Night Watch

    How to Ask Questions the Smart Way (not affiliated with this site, but well worth reading)

    My Blog
    cwrBlog: simple, no-database PHP blogging framework

  3. #3
    Join Date
    Aug 2009
    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