我如何在PHP中搜索数据库中的文本字符串 [英] how do i search text string in database in php

查看:54
本文介绍了我如何在PHP中搜索数据库中的文本字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个问题,我需要搜索任何字符串数据。在我的代码下面。当我点击,没有结果也没有错误



Index.php

 <?  php       include_once    '.. / templete /header.php';   > ;  

< html xmlns = http ://www.w3.org/1999/xhtml >
< head >
< meta http-equiv = Content-Type content = text / html的; charset = utf-8 / > ;
< title > 搜索< / title > ;
< link href = style.css rel = stylesheet type = text / css / >
< / head >
< 正文 >
< 表单 action = search.php 方法 = 获取 >
< table border = 0 cellpadding = 0 cellspacing = 0 >
< tr >
< td > < 输入 type = text 名称 = 查询 id = text / > & nbsp; < / td >
< td > < 输入 type = 提交 < span class =code-attribute> name = submit id = 搜索 value = 搜索 / < span class =code-keyword>> < / td >
< / form < span class =code-keyword>>
< / body >
< / html >

Search.php





 <?  php   

include_once '../ templete / header.php';

include_once '../inc / connection.inc.php';

>
< html >
< head >
< meta http -equiv = 内容类型 content = text / html; charset = utf-8 / > ;
< title > 搜索< / title > ;
< link href = style.css rel = stylesheet type = text / css / >
< / head >
< 正文 >
< 表格 >
< tr >
< < span class =code-leadattribute> td > 名称< / td >
< < span class =code-leadattribute> td > 地址< / td >
< / tr >
<? php

< span class =code-summarycomment> $ query = $ _ GET [' query'];



/ / $ stmt = $ dbh- > prepare(SELECT * FROM CompanyInfo WHERE(Name LIKE'%。$ query。%')OR(Address LIKE'%。$查询 %'))。
$ stmt = $ dbh-> prepare(SELECT * FROM CompanyInfo WHERE(Name LIKE'%。$ query。%'或Address LIKE'%。$ query。%'));
$ stmt-> setFetchMode(PDO :: FETCH_ASSOC);
// $ stmt-> execute();
if(isset($ stmt))
{
while($ row = $ stmt-> fetch()); ?>
< tr >
< td > <? php echo $ row ['Name'];? > < / td >
< td < span class =code-keyword>> <? php echo $ row ['Address'];? > < / td >
< / tr >
<? php

}

>
< / table >
< / body >
< / html >





请帮帮我



Maideen

解决方案

查询 =


_GET [' < span class =code-summarycomment> query'];

< /跨度>

< span class =code-summarycomment> //


stmt =

Hi
I have one problem , I need to search any string data . Below my code. When I click, no results as well as no error

Index.php

<?php  include_once '../templete/header.php'; ?>

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<form action="search.php" method="get" >
<table border="0" cellpadding="0" cellspacing="0">
<tr>
    <td><input type="text" name="query" id="text"  />&nbsp;</td>
    <td><input type="submit" name="submit" id="search" value="Search" /></td>
</form>
</body>
</html>

Search.php



<?php

 include_once '../templete/header.php';

 include_once '../inc/connection.inc.php';

?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Search</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table>
<tr>
  <td>Name</td>
  <td>Address</td>
  </tr>
<?php

    $query = $_GET['query'];



    //$stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%') OR (Address LIKE '%".$query."%')");
    $stmt = $dbh->prepare("SELECT * FROM CompanyInfo WHERE (Name LIKE '%".$query."%' OR Address LIKE '%".$query."%')");
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    //$stmt->execute();
    if(isset($stmt))
        {
            while($row = $stmt->fetch()); ?>
              <tr>
              <td><?php echo $row['Name'];?></td>
              <td><?php echo $row['Address'];?></td>
              </tr>
        <?php

        }

?>
</table>
</body>
</html>



Pls Help me

Maideen

解决方案

query =


_GET['query']; //


stmt =


这篇关于我如何在PHP中搜索数据库中的文本字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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