Check if row is empty

Discussion in 'PHP' started by zaay, Aug 15, 2009.

  1. #1
    Hello Everyone ;)

    Again, i have big problem ...

        $query = "SELECT * FROM news_comments WHERE news_id=$id";
        $result = mysql_query ($query);
        echo "Comments:";
        
        /* display the all the comments */
        while ($row = mysql_fetch_assoc ($result)) {
            
            $name = htmlentities ($row['name']);
            
        
            $comment = ($row['comment']);
            $comment = nl2br ($comment);
            $website = ($row['website']);
            echo "<div class='clear'></div>";        
            
            
                echo"<ol class='commentlist'>";
                echo"<a href='".$website."'>".$name."</a> Says:";
                            echo "<br />";
                echo"<p>".$comment."</p>";
    PHP:
    This is my comment script.. Now you can see where we select website.. If there is website in "website" field, it show it, but if there isn't it gives link to page where comments are. Ok it's good, but i want something else. If want to check if there is something in website field. If there is something it do as i have now, but if user didn't entered URL, then it delete url from
    echo"<a href='".$website."'>".$name."</a> Says:";
                            echo "<br />";
    PHP:
    So what i want is:

    If there is a record in website field it's like that:
    echo"<a href='".$website."'>".$name."</a> Says:";
                            echo "<br />";
    PHP:
    If there is no record in website field it's that:
    
    echo"".$name." Says:";
                            echo "<br />";
    PHP:
     
    zaay, Aug 15, 2009 IP
  2. premiumscripts

    premiumscripts Peon

    Messages:
    1,062
    Likes Received:
    48
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo (!empty($website) ? "<a href='".$website."'>".$name."</a>" : $name) . " Says:";
    PHP:
     
    premiumscripts, Aug 15, 2009 IP
  3. zaay

    zaay Member

    Messages:
    269
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    30
    #3

    Thaaank you very very much ! That worked ! Thanx!!!
     
    zaay, Aug 15, 2009 IP