Doing Checks

3 posts Page 1 of 1
Contributors
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Doing Checks
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>
            ";
           }
        
        
?>
http://www.mbappz.com
Filip
Coding Guru
Coding Guru
Posts: 833
Joined: Wed Jan 05, 2011 3:59 pm

Re: Doing Checks
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
CodenStuff wrote:
Nope, it's just your sick and dirty mind. You sick twisted warped little pervo :D
User avatar
Mark
VIP - Donator
VIP - Donator
Posts: 372
Joined: Mon Aug 17, 2009 10:35 pm

Re: Doing Checks
Mark
RESOLVED.

Thanks for your help guys.
http://www.mbappz.com
3 posts Page 1 of 1
Return to “Help & Support”