MySQL Query Results question...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Jonathan
    Senior Member
    • Mar 2004
    • 1229

    #1

    MySQL Query Results question...

    Okay I'm working on a blog system and *Finally* (big yey)
    got the stupid comments to work; well okay it was tons
    different (and easy) than I thought it'd be, etc etc.

    Now ~ I'm using num_row I think it is, to count how many rows
    based on where the field 'news_id' equals the variable $id (set in a query above that).

    This is on the index page; what I want to know is, on the comments page
    how do I make it so that if there are no results in the news_id field
    that equal the same as $id (which is passed via URL, like comments.php?id=xx)
    that it'll say "Go away blah blah no comments here"?

    I tried to use like if (empty($nid)) { echo "blah blah"; } else { *shows results* }
    but that didn't work; any ideas?
    "How can someone be so distracted yet so focused?"
    - C
  • Jonathan
    Senior Member
    • Mar 2004
    • 1229

    #2
    Never mind; used a simple if() and works like a charm.
    "How can someone be so distracted yet so focused?"
    - C

    Comment

    • sdjl
      Senior Member
      • Mar 2004
      • 502

      #3
      As you found out, a simple if statement works wonders.
      Just so others can get a grasp, something like so works normally:

      PHP Code:
      <?php
      // $query is done above this code

      if(mysql_num_rows($query) <= 0) {

      echo 
      'This post has no comments!';

      } else {

      // code to show your comments

      }
      ?>
      David
      -----
      Do you fear the obsolescence of the metanarrative apparatus of legitimation?

      Comment

      Working...