如何从数据库中显示某些细节

时间:2013-07-24 08:30:03

标签: php

我有这个代码用于在mysql中搜索并且它正在工作但是当我运行并输入一个帐号时它显示我的数据库中的所有帐户 我只是想显示我查询的帐号的详细信息。

我应该更改或添加什么?我不知道

<?php

echo "<h2>Search Results:</h2><p>";

//If they did not enter a search term we give them an error
if ($find == "Account_Number")
{
echo "<p>You forgot to enter a search term!!!";
exit;
}

// Otherwise we connect to our Database
mysql_connect("localhost", "username", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());

// We perform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT Account_Number, Name, Balance FROM memaccounts WHERE ID    
LIKE'%$find%'");

//And we display the results
while($result = mysql_fetch_array( $data ))
{
echo $result['Account_Number'];
echo " ";
echo $result['Name'];
echo "<br>";
echo $result['Balance'];
echo "<br>";
echo "<br>";
}


$anymatches=mysql_num_rows($data);
if ($anymatches == 0)
{
echo "Sorry, but we can not find an entry to match your query...<br><br>";
}

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;
//} 
?>  

1 个答案:

答案 0 :(得分:0)

$data = mysql_query("SELECT Account_Number, Name, Balance FROM
 memaccounts WHERE Account_Number  = '" . trim($find) . "' ");

1.where with Ac no.

建议:使用mysqli_ *