我想在“div”中将搜索页面显示在数据库中搜索的数据中? [英] I want to make search page where I want to display my searched data from database in a "div"?

查看:139
本文介绍了我想在“div”中将搜索页面显示在数据库中搜索的数据中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在搜索页面(php)中显示我在数据库中搜索到的数据在div中?我建立了与数据库的连接并在一个phppage中搜索数据,并在另一个phppage中创建了一个div标签。如何显示搜索到的一个PHP页面的数据,以显示在另一个PHP页面的div中



Search.php:

 <?php 
include'Searchdata.php';
包含'connect.php';
if(isset($ _ POST ['submit'])){
$ searchkey = $ _POST ['search'];
$ searchkey = preg_replace(#[^ 0-9a-z] #i,,$ searchkey);
$ query = mysqli_query($ conn,SELECT * FROM newentry WHERE Date LIKE'%$ searchkey%')or die(Could not search!);
$ count = mysqli_num_rows($ query);
if(!($ count == 0)){
while($ row = mysqli_fetch_array($ query)){
$ Date = $ row ['Date'];
$ Entry = $ row ['Entry'];
echo'< div>'。$ Date。'< br>'。$ Entry。'< / div>';
}
} else {echo没有搜索结果!;}
}?> b


Searchdata.php: > < DIV>
< form action =Search.phpmethod =post>
< input type =textname =searchplaceholder =Search>
< input type =submitvalue =Search/>
< / form>


解决方案

只需创建一个变量来存储结果,在这种情况下它的$数据。将您的include searchdata.php移动到代码的底部,以便重新调整$数据。
然后在您的html页面上回显它。



html page

 < DIV> 
< form action =Searchdata.phpmethod =post>
< input type =textname =searchplaceholder =Search>
< input type =submitvalue =搜索>
< / form>
< div><?php echo $ data?>< / div>
< / div>

PHP代码。

 <?php 
include'connect.php';
$ data ='';
if(isset($ _ POST ['submit'])){
$ searchkey = $ _POST ['search'];
$ searchkey = preg_replace(#[^ 0-9a-z] #i,,$ searchkey);
$ query = mysqli_query($ conn,SELECT * FROM newentry WHERE Date LIKE'%$ searchkey%')or die(Could not search!);
$ count = mysqli_num_rows($ query);
if(!($ count == 0)){
while($ row = mysqli_fetch_array($ query)){
$ Date = $ row ['Date'];
$ Entry = $ row ['Entry'];
$ data ='< div>'。$ Date。'< br>'。$ Entry。'< / div>';
}
} else {
$ data =没有搜索结果!;}}
包含'Search.php';
?>


I want to make search page(php) where I want to display my searched data from database in a "div"?I made a connection with database and searched for data in one phppage and created a div tag in another phppage.how can i display the searched data of one php page to be displayed in another php page's "div"

Search.php:

<?php 
include 'Searchdata.php';
include 'connect.php';
if(isset($_POST['submit'])){
   $searchkey= $_POST['search'];    
   $searchkey=preg_replace("#[^0-9a-z]#i", "", $searchkey); 
   $query = mysqli_query($conn, "SELECT * FROM newentry WHERE Date LIKE '%$searchkey%'")or die("Could not search!");
   $count = mysqli_num_rows($query); 
   if(!($count == 0)) {    
      while($row=mysqli_fetch_array($query)){
         $Date=$row['Date'];
         $Entry=$row['Entry'];
         echo'<div>'.$Date.'<br>'.$Entry.'</div>';
       }
    } else {echo "There was no search result!";} 
}?>

Searchdata.php:

<div>
<form action="Search.php" method="post">  
   <input type="text" name="search" placeholder="Search"> 
   <input type="submit" value="Search" />
</form>

解决方案

Just create a variable to store the results in this case its $data. Move your include searchdata.php to the bottom of the code so it can reconize $data. Then echo it on your html page.

html page

<div>
<form action="Searchdata.php" method="post">  
<input type="text" name="search" placeholder="Search"> 
<input type="submit" value="Search">
</form>
<div><?php echo $data ?></div>
</div>

The PHP code.

<?php
include 'connect.php';
$data = '';
if(isset($_POST['submit'])){
$searchkey= $_POST['search'];   
$searchkey=preg_replace("#[^0-9a-z]#i", "", $searchkey); 
$query = mysqli_query($conn, "SELECT * FROM newentry WHERE Date LIKE '%$searchkey%'")or die("Could not search!");
$count = mysqli_num_rows($query); 
if(!($count == 0)) {    
while($row=mysqli_fetch_array($query)){ 
$Date=$row['Date'];
$Entry=$row['Entry'];
$data = '<div>'.$Date.'<br>'.$Entry.'</div>';
}
} else {
$data = "There was no search result!";}}
include 'Search.php';
?>

这篇关于我想在“div”中将搜索页面显示在数据库中搜索的数据中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆