首頁  >  文章  >  php教程  >  简单的数据库搜索功能

简单的数据库搜索功能

WBOY
WBOY原創
2016-06-21 09:02:401055瀏覽

 

//// filename = search.php3





>
?>

//// 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
?>

 



陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn