English 中文(简体)
搜索 显示链接的条件
原标题:Database Search Query to show as Links

我对营地来说很陌生,我正在开发一个有搜索条的网站。

我已使用一些代码进行查询,以从我的数据库中寻找产品。 搜查令进行罚款,显示需要展示的所有所需产品。

然而,我希望这些物品与产品详细页有链接,显示有关这一具体产品的更多信息。 然而,我没有你如何把这一点作为使用html的链接。

My search code is as follows:

<?php

error_reporting(E_ALL);
ini_set( display_errors ,  1 );
$search_output = "";
if(isset($_POST[ searchquery ]) && $_POST[ searchquery ] != ""){
    $searchquery = preg_replace( #[^a-z 0-9?]#i ,   , $_POST[ searchquery ]);
    if($_POST[ filter1 ] == "Food"){
        $sqlCommand = "SELECT * FROM tbl_product WHERE pd_name LIKE  %$searchquery% ";
    }
    include_once("config.php");


    //Database connections below


     mysql_connect($dbHost, $dbUser, $dbPass) or die(mysql_error()); 
 mysql_select_db($dbName) or die(mysql_error());

    $query = mysql_query($sqlCommand) or die(mysql_error());
    $count = mysql_num_rows($query);
    if($count >= 1){
        $search_output .= "<hr />$count results for <strong>$searchquery</strong><hr />";
        while($row = mysql_fetch_array($query))
        {
            $pd_name = $row["pd_name"];
        $search_output .= "$pd_name<br />";
        } // close while
    } else {
        $search_output = "<hr />0 results for <strong>$searchquery</strong><hr />";
    }
}
?>
<html>
<head>
</head>
<body>
<form action="<?php echo $_SERVER[ PHP_SELF ]; ?>" method="post">
Search for dishes : 
  <input name="searchquery" type="text" size="30" maxlength="100"> 
In: 
<select name="filter1">
<option value="Food">Food</option>

</select>
<input name="myBtn" type="submit" value="Search">

<br />
</form>
<div>
<?php echo $search_output; ?>
</div>
</body>
</html>

我想提及的是:

<a href="" . $_SERVER[ PHP_SELF ] . "?c=$catId&p=$pd_id" . "">$pd_name</a>

However, when adding this reference, it does not seem to work. Any help would be appreciated. Thanks in advance.

问题回答

转而:

$pd_name = $row["pd_name"];
$search_output .= "$pd_name<br />";

为此:

$pd_name = $row["pd_name"];
$pd_id   = $row["pd_id"];
$search_output .=  <a href="  . $_SERVER[ PHP_SELF ] .  "?c=$catId&p=  . $pd_id .  ">  . $pd_name .  </a><br> ;

顺便说一句,在将用户投入数据传送到数据库之前,你需要读到Kum射中。 至少改变这一点:

$sqlCommand = "SELECT * FROM tbl_product WHERE pd_name LIKE  %$searchquery% ";

为此:

$sqlCommand = "SELECT * FROM tbl_product WHERE pd_name LIKE  %".mysql_real_escape_string($searchquery)."% ";




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

难以执行 REGEXP_SUBSTR

I m 查询Oracle 10g。 我有两张表格(样本数据见下文)。 i m 试图提取一些领域

SQL Query Shortcuts

What are some cool SQL shorthands that you know of? For example, something I learned today is you can specify to group by an index: SELECT col1, col2 FROM table GROUP BY 2 This will group by col2

PHP array callback functions for cleaning output

I have an array of output from a database. I am wondering what the cleanest way to filter the values is example array Array ( [0] => Array ( [title] => title 1 ...

OracleParameter and DBNull.Value

we have a table in an Oracle Database which contains a column with the type Char(3 Byte). Now we use a parameterized sql to select some rows with a DBNull.Value and it doesn t work: OracleCommand ...

Running numbers in SQL

I have a SQL-statement like this: SELECT name FROM users WHERE deleted = 0; How can i create a result set with a running number in the first row? So the result would look like this: 1 Name_1 2 ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...

热门标签