【发布时间】:2015-07-14 02:26:11
【问题描述】:
我有一个网站,用户在其中输入电影名称,在 SQL 数据库上进行搜索,所有具有相似名称的电影都以表格格式显示。
每部电影的名称也是指向第二页的链接,该页面显示有关这部电影的更多详细信息。
但是,为了获得更多详细信息,我需要在第二页对这部电影进行另一次查询,所以理想情况下,当用户点击第一页上的电影名称时,链接也应该发布该电影的名称电影到第二页作为变量。
然后我可以获取该变量并在第二页的查询中使用它。
我不想添加不可见的表单,因为这仍然会向表格添加按钮,我需要表格保持原样。
<?php
$username = "root";
$password = "";
$hostname = "localhost";
$db_handle = mysql_connect($hostname, $username, $password) or die ("Could not connect to database");
$selected= mysql_select_db("login", $db_handle);
$output='';
$output1='';
$tablehead='';
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$query = mysql_query("SELECT * FROM PHP_Item WHERE Name LIKE '%$searchq%'") or die ("Could not search");
$count = mysql_num_rows($query);
if($count == 0){
$output = 'there were no search results';
}else{
$tablehead.= "<table id='searchtable'>
<tr>
<th>
Name
</th>
<th>
Price
</th>
</tr>
</table>";
while($row = mysql_fetch_array($query)){
$mName = $row['Name'];
$price = $row['Price'];
$id= $row['ItemID'];
$output1.=
"<table id='searchtable'>
<tr>
<td>
<a href='searchresult.php'>$mName</a>
</td>
<td>
£$price
</td>
</tr>
</table>";
}
}
}
?>
【问题讨论】:
-
请stop using
mysql_*functions。它们不再被维护并且是officially deprecated。改为了解prepared statements,并使用PDO。