Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/64.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 根据textarea值选择行_Php_Mysql_Select_Sql Like - Fatal编程技术网

Php 根据textarea值选择行

Php 根据textarea值选择行,php,mysql,select,sql-like,Php,Mysql,Select,Sql Like,根据搜索模式,我需要从服务器获取显示的数据 include("dbconfig.php"); $sql="select * from blog where title LIKE '{$title}%'"; $res=mysql_query($sql); while($row=mysql_fetch_array($res)) { echo"<tr>"; echo"<td><img src='uploads/".$row['file']."' h

根据搜索模式,我需要从服务器获取显示的数据

include("dbconfig.php");
$sql="select * from blog where title LIKE '{$title}%'";
$res=mysql_query($sql);
while($row=mysql_fetch_array($res))
{
    echo"<tr>";
        echo"<td><img src='uploads/".$row['file']."' height='150px' width='200px'</td>";
        echo"<td><h3>".$row['title']."</h3>".$row['description']."</td>";
    echo"</tr>";
}
include(“dbconfig.php”);
$sql=“从标题类似于“{$title}%”的博客中选择*”;
$res=mysql\u查询($sql);
while($row=mysql\u fetch\u数组($res))
{
回声“;
回声“;
回显“$row['title']”..$row['description']”;
回声“;
}

更改查询,如下所示:

$sql="select * from blog where title LIKE '".$title."%';

下面是一个完整的重写,它实现了问题下的mysqli。为了安全性和易用性,它使用带有和的

(另外请注意,我已经替换了SELECT中的
*
通配符。最好只向数据库询问您需要的内容。)

$db=newmysqli(“本地主机”、“用户名”、“密码”、“数据库”);//在你的包里做这个吗
如果($stmt=$db->prepare(“从`blog`中选择`file`、`title`、`description`,其中`title`LIKE?”)){
$search=“{$\u GET['title']}%”;//我假设这是通过$\u GET传递的
$stmt->bind_参数(“s”,$search);
$stmt->execute();
$stmt->bind_result($file、$title、$description);
而($stmt->fetch()){
回声“;
回声“;
回显“{$title}{$description}”;
回声“;
}
$stmt->close();
}

p、 通常,表搜索是通过在
LIKE
值的两侧使用
%
来完成的。您的搜索将只返回“以
标题开始
”的结果。请考虑在代码中更改这一点。您面临的问题是什么?swapnika的问题是什么?停止使用不推荐的
mysql.*
API。使用
mysqli.*
PDO
。mysql.*在PHP7中是不受欢迎的功能。尝试使用PDO或mysqli.*您希望
%
做什么?你的意思是把i放在“
”和“
”之间吗?(
…像“.$title.”%”
$db=new mysqli("localhost","username", "password","database");  // do this in your include
if($stmt=$db->prepare("SELECT `file`,`title`,`description` FROM `blog` WHERE `title` LIKE ?")){
    $search="{$_GET['title']}%";  // I assume this is passed with $_GET
    $stmt->bind_param("s",$search);
    $stmt->execute();
    $stmt->bind_result($file,$title,$description);
    while($stmt->fetch()){
        echo"<tr>";
            echo"<td><img src='uploads/{$file}' height='150px' width='200px'</td>";
            echo"<td><h3>{$title}</h3>{$description}</td>";
        echo"</tr>";
    }
    $stmt->close();
}