Doing Checks
3 posts
Page 1 of 1
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?
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>
";
}
?>
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
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
3 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023