加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > PHP教程 > 正文

php数据访问之查询关键字

发布时间:2020-12-12 21:29:59 所属栏目:PHP教程 来源:网络整理
导读:本文实例为大家分享了php查询操作的实现代码,供大家参考,具体内容如下 一、一个关键字查询 主页面: 汽车查询页面 汽车查询页面 form action="QiChe.php" method="post" 请输入查询内容: "/ table width="100%" border="1" cellpadding="0" cellspacing="

本文实例为大家分享了php查询操作的实现代码,供大家参考,具体内容如下

一、一个关键字查询

主页面:

汽车查询页面

汽车查询页面



<form action="QiChe.php" method="post">

请输入查询内容:

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>汽车名称</td>
<td>油耗</td>
<td>功率</td>
<td>价格</td>
</tr>

<?php
  $sql="select * from Car".$cx;
  $attr=$db->query($sql);
  foreach ($attr as $v)
  {
//使输入查询的关键字变色,处理name
//$rp="{$value}";
$rp="{$value}";
$arr=str_replace($value,$rp,$v[1]);

echo "<tr>
<td>{$v[0]}</td>
<td>{$arr}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
<td>{$v[7]}</td>
</tr>";
  }
?>

</table>

封装类: 

localhost,$this->uid,$this->password,$db); !mysqli_connect_error() or die("连接失败 !"); $result=$dbconnect->query($sql);
if($type==0)
{
  return $result->fetch_all();
}
else
{
  return $result;
}

}
}

运行结果:

二、多个关键字查询

主页面:

汽车查询页面

汽车查询页面


}
if(!empty($_POST["brand"]))
{
$name1=$_POST["brand"];
$tj2="brand= '{$_POST['brand']}'";
$value1=$name1;
}
$cx=" where $tj1 and $tj2";//查询字符串
?>

<form action="ChaXun1.php" method="post">

请输入名称:

<table width="100%" border="1" cellpadding="0" cellspacing="0">
<tr>
<td>代号</td>
<td>汽车名称</td>
<td>系列</td>
<td>价格</td>
<td>油耗</td>
<td>功率</td>
</tr>

<?php
$sql="select * from Car".$cx;
$attr=$db->Query($sql);
foreach ($attr as $v)
{

//处理name
//$rp="{$value}";
$rp="{$value}";
$str=str_replace($value,$v[1]);
echo "<tr>
<td>{$v[0]}</td>
<td>{$str}</td>
<td>{$v[2]}</td>
<td>{$v[7]}</td>
<td>{$v[4]}</td>
<td>{$v[5]}</td>
</tr>";
}
?>
</table>

以上就是本文的全部内容,希望对大家学习php程序设计有所帮助。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读