php search help
5 posts
Page 1 of 1
hello,
can anyone help me with my search page please.
ive got it showing the search results all I need to do now if none is return display a message saying no posts here is my code.
can anyone help me with my search page please.
ive got it showing the search results all I need to do now if none is return display a message saying no posts here is my code.
Code: Select all
<?php require("./styles/top.php");?>
<h1>Here is your search result</h1>
<?php
include("includes/connect.php");
if(isset($_GET['search'])){
$search_id = $_GET['value'];
$search_query = "select * from posts where post_keywords like '$search_id'";
$run_query = mysql_query($search_query);
while ($search_row=mysql_fetch_array($run_query)){
$post_id = $search_row['post_id'];
$post_title = $search_row['post_title'];
$post_image = $search_row['post_image'];
$post_date = $search_row['post_date'];
$post_author = $search_row['post_author'];
$post_content = substr($search_row['post_content'],0,150);
?>
<div id="container">
<div id="image"><?php if($post_image != ""){ ?><img src="/cms/pics/<?php echo $post_image; ?>" /> <?php } ?></div>
<div id="title"><?php echo $post_title; ?></div>
<div id="posted_by">Published on: <?php echo $post_date ?> By <?php echo $post_author ?></div>
<hr style="width: 75%;" />
<div id="content"><?php echo $post_content; ?></div>
</div>
<?php } } ?>
<?php require("./styles/bottom.php");?>
You can use PHP's empty() function to make sure that $run_query isn't empty:
Code: Select all
if(!empty($run_query)){
//Display the results
}
#comathi, I won't recommend doing that! I've had BAD experiences with the empty() function before, and I believe that its a torture, that no one should bear.
A little "mysql-oriented" way, also, the perfect way would be to use the MySQL's num_row's function. Have a look below:
A little "mysql-oriented" way, also, the perfect way would be to use the MySQL's num_row's function. Have a look below:
Code: Select all
if (mysql_num_rows($run_query) != 0) {
// Do your mojo here!
}
visualtech wrote:#comathi, I won't recommend doing that! I've had BAD experiences with the empty() function before, and I believe that its a torture, that no one should bear.All mysql functions are deprecated. mysqli should be used in all instanced where PDO is not used.
A little "mysql-oriented" way, also, the perfect way would be to use the MySQL's num_row's function. Have a look below:
Code: Select allif (mysql_num_rows($run_query) != 0) { // Do your mojo here! }
Nailing my feet to the floor is easier than using my own muscles to balance, but you don't see me doing that 

THANK GOD SOMEONE IS THERE FOR MYSQLI!!! HI5!! #zachman61 And all I ever get is eyes looking at me, about to slaughter me! :\
5 posts
Page 1 of 1
Copyright Information
Copyright © Codenstuff.com 2020 - 2023