我想在mysql数据库中使用PHP进行搜索,并搜索结果以进行编辑或删除,但是直到现在我都可以进行搜索,并且一切正常,或者“编辑/删除”和“搜索”不再起作用。.
我想将两者合并在同一个php文件中,但不起作用。知道有人怎么结合吗?
如何在同一个php中添加两者??
搜索PHP
<?php
include_once("db_W3.php");
$result = mysqli_query($mysqli, "SELECT * FROM centralhub_lagerbestand");
//load database connection
include_once("db_W3.php");
$host = "$servername";
$user = "$username";
$password = "$password";
$database_name = "$db";
$pdo = new PDO("mysql:host=$host;dbname=$database_name", $user, $password, array(
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
));
// Search from MySQL database table
$search=$_POST['search'];
$query = $pdo->prepare("select * from centralhub_lagerbestand where KundenNr LIKE '%$search%' LIMIT 0 , 50");
$query->bindValue(1, "%$search%", PDO::PARAM_STR);
$query->execute();
// Display search result
if (!$query->rowCount() == 0) {
echo "<table style=\"font-family:arial;color:#333333;\">";
echo "<tr>
<td align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;background:#FFFFFF;\">Kunden Nr.:</td>
<td align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;background:#FFFFFF;\">Regal:</td>
<td align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;background:#FFFFFF;\">Regal Ebene:</td>
<td align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;background:#FFFFFF;\"> Edit </td>
</tr>";
while ($results = $query->fetch()) {
echo "<tr> <td width='500px' align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;\">";
echo $results['KundenNr'];
echo "</td><td width='230px' align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;\">";
echo $results['Regal'];
echo "</td><td width='230px' align='center' style=\"border-style:solid;border-width:1px;border-color:#A4A4A4;\">";
echo "".$results['RegalEbene'];
echo "</td> </tr>";
}
echo "</table>";
} else {
echo 'Für die aktuellen Filter wurden keine Ergebnisse gefunden';
}
?>
编辑/删除PHP
<?php
//including the database connection file
include_once("db_W3.php");
//fetching data in descending order (lastest entry first)
//$result = mysql_query("SELECT * FROM users ORDER BY id DESC"); // mysql_query is deprecated
$result = mysqli_query($mysqli, "SELECT * FROM centralhub_lagerbestand ORDER BY id DESC"); // using mysqli_query instead
?>
<html>
<head>
<title>Homepage</title>
</head>
<body>
<table width='100%' border=0>
<tr bgcolor='#CCCCCC'>
<td>KundenNr</td>
<td>Regal</td>
<td>RegalEbene</td>
<td>Update</td>
</tr>
<?php
//while($res = mysql_fetch_array($result)) { // mysql_fetch_array is deprecated, we need to use mysqli_fetch_array
while($res = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>".$res['KundenNr']."</td>";
echo "<td>".$res['Regal']."</td>";
echo "<td>".$res['RegalEbene']."</td>";
}
?>
</table>
</body>
</html>