将超链接添加到回显结果的PHP搜索脚本中

时间:2013-11-27 14:36:38

标签: php

我有以下搜索脚本,我需要将结果的公司部分链接到每个公司网站(存储在我的数据库中的列WEBSITE中)。有人可以帮忙吗?

if(isset($_POST['completedsearch'])) {
    $term = $_POST['query'];
    $mysql = mysql_connect("ldb504.securepod.com","martindb","green11");
    mysql_select_db("hcsd");
    $qu = mysql_query("SELECT * FROM Sheet1 WHERE COMPANY LIKE '%".mysql_real_escape_string($term)."%' OR LOCATION LIKE '%".mysql_real_escape_string($term)."%' OR KEYWORDS LIKE '%".mysql_real_escape_string($term)."%' OR PRODUCTSSERVICES LIKE '%".mysql_real_escape_string($term)."%' "); //selects the row that contains ANYTHING like the submitted string
    echo "Searching for '$term'";
    echo "
        <table><tr style=\"border-bottom:1px dotted #305896;\"><th style=\"padding:0px 10px;text-align:left;border-bottom:1px dotted #305896;\">Company</th>
        <th style=\"padding:0px 10px;text-align:left;border-bottom:1px dotted #305896;\">Location</th>
        <th style=\"padding:0px 10px;text-align:left;border-bottom:1px dotted #305896;\">Products/Services</th></tr>";
    while($row = mysql_fetch_array($qu)) {
        echo"<tr style=\"border-bottom:1px dotted #305896;\"><td style=\"padding:0px 10px;text-align:left;border-bottom:1px dotted #305896;\">";  
        echo"<a href="'.urlencode($row['WEBSITE']).'">'.htmlspecialchars($row['COMPANY']).'</a>";
        echo "</td>";
        echo "<td style=\"padding:0px 10px;text-align:left;border-bottom:1px dotted #305896;\">";
        echo htmlspecialchars($row['LOCATION']);
        echo "</td>";
        echo "<td style=\"padding:0px 10px;text-align:left;border-bottom:1px dotted #305896;\">";
        echo htmlspecialchars($row['PRODUCTSSERVICES']);
        echo "</td></tr>";
    }
    echo "</table>";
}

1 个答案:

答案 0 :(得分:1)

你的php混合单引号和双引号时出错:

echo"<a href="'.urlencode($row['WEBSITE']).'">'.htmlspecialchars($row['COMPANY']).'</a>";

应该是这样的:

echo '<a href="'.urlencode($row['WEBSITE']).'">'.htmlspecialchars($row['COMPANY']).'</a>';