php/mysql实现搜索功能

来源:互联网 发布:淘宝怎么用余额宝分期 编辑:程序博客网 时间:2024/05/22 12:49
<table width="50%"><tr><td>id</td><td>name</td></tr><?php$name=$_POST[name];//$sql=mysql_query("select * from message");$sql=mysql_query("select * from message where name like '%".$name."%'");//$row=@mysql_fetch_array($sql);$row=@mysql_fetch_object($sql);if($row==false){echo "您搜索的信息不存在,请使用类似的关键字进行检索!!!";}do{?><tr><td><?php echo $row->id?></td><td><?php echo $row->name?></td></tr><?php}while($row=@mysql_fetch_object($sql));mysql_free_result($sql);mysql_close();?></table>
大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭大哭
<title>搜索</title><?php require "conn.php";$name=$_POST["name"];$sql=mysql_query("select * from patient_8 where name like '%".$name."%'");$info=@mysql_fetch_array($sql);//$info=@mysql_fetch_object($result);//$info=@mysql_fetch_row($result);if($info==false){echo '<script>alert("检索到!!!");location.href="./"</script>';}?><form name="myform" method="post" action=""><table width="50%"><tr><td>name:<input type="text" size="25" name="name" /></td><td><input type="submit" name="submit" value="查询" /></td></tr></form><?phpdo {?><tr><td><?php echo $info[id]?></td><td><?php echo $info[name]?></td></tr><?php}while(@$info=mysql_fetch_array($sql))//函数从数组结果集中获取数据信息//while(@$info=mysql_fetch_object($sql))函数从结果集中获取一行作为对象 返回的是对象而不是数组//while(@$info=mysql_fetch_row($sql))函数逐行获取结果集中的每条记录?><tr><td><?php echo mysql_num_rows($sql)?></td></tr></table><meta charset="gb2312" />


0 0
原创粉丝点击