-4
我想過濾使用PHP的MySQL表,我的目標是當URL是History.php?h_id = 1它只顯示有一個在h_id中的行(H_id是不是唯一的號碼)兩個很多記錄顯示何時識別h_id
我的代碼如下。
<html>
<head>
<title></title>
</head>
<body >
<?php
mysql_connect('localhost', 'root', 'matl0ck') or die(mysql_error());
mysql_select_db("kedb") or die(mysql_error());
$h_id = (int)$_GET['h_id'];
$query = mysql_query("SELECT * FROM Hist WHERE H_ID = '$h_id'") or die(mysql_error());
if(mysql_num_rows($query)=1){
while($row = mysql_fetch_array($query)) {
$id = $row['ID'];
$name = $row['Name'];
$datemod = $row['DateMod'];
$h_id = $row['H_ID'];
}
?>
<?php
$con=mysqli_connect("localhost","root","matl0ck","kedb");
// Check connection
if (mysqli_connect_errno()){
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM Hist");
echo "<table border='1'>
<tr>
<th>ID</th>
<th>Name</th>
<th>Date</th>
<th>H_ID</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['ID'] . "</td>";
echo "<td>" . $row['Name'] . "</td>";
echo "<td>" . $row['DateMod'] . "</td>";
echo "<td>" . $row['H_ID'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
?>
<?php
}else{
echo 'No entry found. <a href="javascript:history.back()">Go back</a>';
}
?>
</body>
</html>
當我嘗試使用這種它表明,在當我刪除此列中的數字也顯示了一個錯誤的h_id一些的所有記錄。
我的表格佈局如下。
謝謝
什麼錯誤不再存在
mysql_
的????? – 2016-11-12 04:02:13每次您使用[mysql_'](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) 數據庫擴展的新代碼 ** [一隻小貓被勒死在世界某個地方](http://2.bp.blogspot.com/-zCT6jizimfI/UjJ5UTb_BeI/AAAAAAAACgg/AS6XCd6aNdg/s1600/luna_getting_strangled.jpg)**它被棄用,並且已經存在了很多年,並且已經消失了永遠在PHP7中。 如果您只是學習PHP,請花些精力學習'PDO'或'mysqli'數據庫擴展。 [開始](http://php.net/manual/en/book.pdo.php) – RiggsFolly
**爲什麼你使用MYSQL_和MYSQLI_數據庫擴展??? ** – RiggsFolly