Page 1 of 1

Doing Checks

Posted: Sun Dec 27, 2015 12:28 am
by Mark
Hey Guys,

This is my code so far was wondering if you can help me please im trying to get the below code to display no records available if there is none and if there is it will go ahead and display them?
Code: Select all
<?php
         
        $get_posts = "select * from posts order by 1 DESC LIMIT 0,2";
        $numrows = mysql_num_rows($get_posts);
        $run_posts = mysql_query($get_posts);
        
        while ($row_posts = mysql_fetch_array($run_posts)){
            
            $post_id = $row_posts['post_id'];
            $post_title = $row_posts['post_title'];
            $post_image = $row_posts['post_image'];
            
            echo "<center>
       
            <h4><a href='details.php?post=$post_id'>$post_title</a></h4> 
            
            <img src='admin/news_images/$post_image' width='100' height='100'/></img>
            
            </center>
            ";
           }
        
        
?>

Re: Doing Checks

Posted: Sun Dec 27, 2015 7:34 pm
by Filip
Hello,

first of all, you shouldn't use mysql_* functions as they are deprecated as of PHP 5.5.0 and functions were removed in PHP 7.0 altogether. So if your host ever tries to update PHP on your server, your script won't work.

As of question you're asking, putting a simple if statement checking how many rows there are should do the trick..

KR,
-Filip

Re: Doing Checks

Posted: Tue Dec 29, 2015 4:47 pm
by Mark
RESOLVED.

Thanks for your help guys.