使用以下脚本不会完全匹配我的结果。当我访问该链接时,它将拉取所有类似于2的记录。因此,它将显示ID中ID为2的所有记录。
即:2,21,22,23,24,25,102,202等
$id = $_GET['id'];
$query = "Select * from realestate WHERE Store_City_State LIKE '%" . $id .
"%' OR ID LIKE '%" . $id . "%' ";
URL:test.php?id = 2
$i_d = $_GET['id'];
<head>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<?php
include '../config/config.php';
?>
</head>
<?php
############## Make the mysql connection ###########
try {
$db = new PDO("mysql:host=$hostname;dbname=imrealestate", $username, $password);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
$i_d = $_GET['id'];
////////This is the main table for keywords//////////
$count = $db->exec($sql);
$sql = "Select * from realestate WHERE Store_City_State LIKE '%" . $i_d . "%' OR ID LIKE " . $i_d . " ";
$result = $db->query($sql);
echo "<table id='products' width='400px'>";
echo'<tr id="top"> ';
echo"<td>ID</td>";
echo"<td id='name'>Location</td>";
echo"<td>Image</td>";
//echo"<td>Retail Price</td>";
foreach ($result as $data) {
echo '
<tr>
<td id="key">'.$data["ID"].'</td>
<td id="name"><a target="_Self" href="test2.php?id='.$data["ID"].'">'.$data["Store_City_State"].'</td>
<td id="bl">
<img src="'.$data["photo"].'" width="50" height="65" class="image">
</td>
}
echo "</tr></table>";
//echo 'entry succesfull';
$db = null; // close the database connection
}
catch(PDOException $e) {
echo $e->getMessage();
}
///////// END MAIN TABLE/////////////////////////
?>