我正在从数据库生成网页。现在我的问题是:sql从表中检索数据并将它们链接
我有1000个记录(名称)在我的数据库(MySql)。 我在一个页面中做了一个搜索框,当我输入任何名字或在我的数据库名称的一部分,所有的名字应该出现。 EG-
SELECT * FROM table where name like '%$find%'
现在我想显示选定的名称(通过查询获取)的新页面上,这样,当我在任何一个新的页面应该开拓名称的点击和所有相关的数据该选定的名称(出现在属于数据库的表格中)将显示在该页面上,并带有导航按钮,我应该使用什么查询来执行它。
总之我想让我的页面像Google搜索页面一样。
我的第一个页面是这样的
<html>
<body >
<h2>Search</h2>
<form name="search" method="post" action="second.php">
Search Name: <input type="text" name="find" id="find" />
<input type="submit" name="search" value="search" />
</form>
</body>
</html>
第二页是有点像这个
<html>
<head>
<script>
function favBrowser()
{
var mylist=document.getElementById("opt");
document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;
}
</script>
</head>
<body>
<form method="get">
<?php
$find = $_REQUEST['find'];
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("data", $con);
$result = mysql_query("SELECT * FROM table where name like '%$find%'");
$result_rows = mysql_num_rows($result);
while($row = mysql_fetch_array($result))
{
// $names[] = $row['name'];
// echo $names[0];
// echo "$row[name]. $row[id] <a href='data.php?edit=$row[name]'>edit</a><br />";
$_name = $row['name'];
echo "Name : <input type='text' name='name' value='$_name' size='30'>";
echo "<br />";
}
}
mysql_close($con);
?>
<!--</select>
<input type ="submit" value="submit">
<p>Your selected name is: <input type="hidden" name="fun" id="favorite" size="30">
</p>
-->
</body>
</html>
你所要求的听起来不像谷歌搜索页面。点击Google结果会将您带到一个网站。你已经说过你想打开一个新的页面,其中包含与所选名称相关的数据。你能用HTML提供你想要列表出现的方式,以及第二页应该如何? – Popnoodles
你想达到什么目的?你现在的代码有什么问题?如果你想显示它们,只需要从结果中回显其他变量?对于链接使用'a href'而不是'input' – MrKiane
我已经完成了直到this.now我想要任何名称/名称出现在页面上我希望他们成为url的,所以,只要我们点击所选的名称,它应该显示所有与新数据库中的名称相关的数据。 – nikesh