首页 > 开发 > PHP > 正文

简单的数据库搜索功能

2024-05-04 23:02:06
字体:
来源:转载
供稿:网友
中国最大的web开发资源网站及技术社区,

 

<?

//// filename = search.php3
<form method="post" action="result.php3">
<select name="metode" size="1">
<option value="row_name1">metode1</option>
<option value="row_name2">metode2</option>
</select>
<input type="text" name="search" size="25">
<input type="submit" value="begin searching!!">
</form>
?>

//// filename = result.php3
<?
$hostname = "127.0.0.1"; // usually localhost.
$username = "username_for_mysql"; // if you have no username, leave this space empty.
$password = "your_password"; // the same applies here.
$usertable = "table_name"; // this is the table you made.
$dbname = "database_name"; // this is the main database you connect to.
mysql_connect($hostname, $username, $password) or die("unable to connect to database");
@mysql_select_db( "$dbname") or die( "unable to select database");
?>
<?
//error message (not found message)
$xx = "no record found";
$query = mysql_query("select * from $usertable where $metode like '%$search%' limit 0, 30 ");
while ($row = mysql_fetch_array($query))
{
$variable1=$row["row_name1"];
$variable2=$row["row_name2"];
$variable3=$row["row_name3"];
print ("this is for $variable1, and this print the variable2 end so on...");
}

//below this is the function for no record!!
if (!$variable1)
{
print ("$xx");
}
//end
?>

 

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表