PHP搜索查询MYSQL

标签 php mysql search

我有一个数据库,其中存储不同传感器导出的数据。在数据库中搜索时,我知道一行中的一列中的内容,但我需要打印该行中以已知字符开头的不同列。我正在尝试这样做:

for($i = 1; $i < 301; $i++)
{
    $result = mysql_query("SELECT * FROM full_dump WHERE file_name='J7091-01.TXT' AND ".$row['field_'.$i.'']." LIKE 'OS' ")or die(mysql_error());
    while($row = mysql_fetch_array($result))
    {
        echo $row['field_'.$i.''];
    }
}

我得到这个结果:

Notice: Undefined variable: row in C:\xampp\htdocs\t1.php on line 11
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'LIKE 'OS'' at line 1

我尝试使用以下方式进行搜索:

... and LIKE '%OS%'

没有运气。 我做错了什么?

我的mysql版本是5.6.16

最佳答案

我认为您不能在查询中使用变量$row,而是应该这样做-

$result = mysql_query("SELECT .....AND field_".$i." LIKE 'OS' ")or die(mysql_error());

关于PHP搜索查询MYSQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22401212/

相关文章:

javascript - 表搜索 - 添加 'no results' 消息

ruby-on-rails - 如何使用 'where'的 'ActiveRecord::QueryMethods'方法来限制搜索?

PHPMailer 在我的服务器上不起作用

php - 无法连接到 'server' 上的 MySQL 服务器

php - 如何根据当前日期从 phpmyadmin 服务器检索数据?

使用 mysql 的书籍数据库的 php 搜索脚本

php - 我使用哪个用户名/密码连接到 mySQL

mysql - 如何保持 sequelize 与 AWS Lambda 函数的连接(或加速初始连接)?

php - 如何让 PHPMyAdmin 显示 MySQL 警告?

mysql - 无法启动 uwAmpp Mysql 服务器