• Top Members
    Reps
    Posts
  • 834 Replies
    2585 Replies
  • 716 Replies
    2025 Replies
  • 331 Replies
    1928 Replies

Doing Checks

User avatar
Mark
VIP - Donator
Posts: 370

Doing Checks

Sun Dec 27, 2015 1:28 am

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>
            ";
           }
        
        
?>

User avatar
Filip
Coding Guru
Posts: 833

Re: Doing Checks

Sun Dec 27, 2015 8:34 pm

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
Posts: 370

Re: Doing Checks

Tue Dec 29, 2015 5:47 pm

RESOLVED.

Thanks for your help guys.

Post Reply

Return to “Help & Support”