[英]how to get id in mysql
這顯示了建築物的所有樓層,我想顯示選定的建築物樓層,我該怎么做?我使用此鏈接floor.php?id = Building1但它不起作用,請幫助我
如果我在building1那里寫的話, where buildingname='building1'
工作正常
如果我where buildingname='$id'
它,那將無法正常工作
我該怎么用
floor.php?id = Building1
如果我輸入此鏈接,它將顯示所有選定的建築結果
<?php
$max_results = 8;
$from = (($page * $max_results) - $max_results);
if(empty($_POST)) {
$query = "SELECT * FROM floors where buildingname='$id' ORDER BY floorno ASC LIMIT $from, $max_results ";
}
$result = mysql_query("SET NAMES utf8"); //the main trick
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
$count=0;
while($row = mysql_fetch_array($result))
{
if($count%4==0)
{
echo "<tr/>";
echo "<tr>";
}
echo "<td><div align='center'><img src='images/floor.gif' width='60' height='90'></a><p>" . $row['floorno'] . "</p><div></td>";
$count++;
}
echo "</tr>";
echo "</table>";
echo '</div>';
?>
if(empty($_POST)) {
$query = "SELECT * FROM floors where buildingname='$id' ORDER BY floorno ASC LIMIT $from, $max_results ";
}
右邊是:
if (isset($_GET['id'])) {
$id = filter_input(INPUT_GET, 'id');
$query = "SELECT * FROM floors where buildingname='$id' ORDER BY floorno ASC LIMIT $from, $max_results ";
}
可能對您有幫助。
<?php
$id =isset($_GET['id'])?$_GET['id']:null; // here you put value in $id only if it has some value.
$max_results = 8;
$from = (($page * $max_results) - $max_results);
if($id != null) {
$query = sprintf("SELECT * FROM floors WHERE buildingname='%s' ORDER BY floorno ASC LIMIT $from, $max_results", mysql_real_escape_string($id)); // safe from sql injection
$result = mysql_query("SET NAMES utf8"); //the main trick
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
$count=0;
while($row = mysql_fetch_array($result))
{
if($count%4==0)
{
echo "<tr/>";
echo "<tr>";
}
echo "<td><div align='center'><img src='images/floor.gif' width='60' height='90'></a><p>" . $row['floorno'] . "</p><div></td>";
$count++;
}
}
echo "</tr>";
echo "</table>";
echo '</div>';
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.