【发布时间】:2014-06-07 15:30:28
【问题描述】:
我创建了一个搜索来填充输入文本的列表。
一切正常,但是我想将输出的名称变成一个链接,该链接转到包含该产品所有详细信息的 id 页面。
例如,当输入测试时,会显示“测试 1”。我希望 1 或 Test 可以点击到 product.php?id=1。
<?php
$text = $_REQUEST['text'];
$text = preg_replace('#[^a-z0-9]#i', '', $text);
$query = "SELECT * FROM products WHERE product_name LIKE '%" . $text . "%'";
$action = mysql_query($query);
$result = mysql_num_rows($action);
while ($res = mysql_fetch_array($action)) {
$output = $res['product_name'].' '.$res['id'].'<br />'; //this is the line to add the link to.
echo $output;
}
?>
【问题讨论】: