查看一下代码:
php
//?获取表单提交值
$student_id?=?intval(trim($_POST['student_id']));
//?页面表单?可以放单独的html文件中,如果放单独的html页面中?form?的action的地址要改成下面的PHP文件名
echo?'form?action=""?method="post"
input?type="text"?name="student_id"?value="{$student_id}"/
input?type="submit"?name="submit"?value="查询"/
/form';
//?当有数据提交时
if?($student_id)
{
$con=?mysql_connect("localhost","root","111")?or?die("连接错误");
mysql_select_db("examination",$con);
//?查询
$sql?=?"SELECT?*?FROM?tablename?WHERE?student_id?=?$student_id?";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
//?输出
echo?'学号:'.$row['student_id'].'br姓名:'.$row['name'].'br性别:'.$row['gender'].'br分数:'.$row['score'];
}
①.、首先,创建一个方法function来供调用.
PHP文本数据库的搜索方法
searchstr=("/".preg_quote($searchstr)."/");
//$searchstr是查找的关键字
$records=file($file);//获取所有的记录数
//$file是查找的数据文件
$search_reocrds=preg_grep
($searchstr,
$records);//开始查找记录
//$search_reocrds为查找到的记录数
unset($records);
if($search_records){
//开始显示记录,写下你自己的处理程序********************
while
(list
($key,
$val)
=
each
(
$search_records))
echo
"$val
";
//****************************************************
①action 后面的页面没有指定
以上就是土嘎嘎小编为大家整理的php搜索数据库数据相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!