我有一个数据库,在查询时,可以返回有时包含网址的结果。如果结果中有地址,它将始终位于数据库的“位置”字段中。
目前,当结果返回时,它将返回为一行文本(用户必须将其复制/粘贴到浏览器窗口中)。
如何让它返回超链接,而不仅仅是一行文字?
这是我的PHP ...
if(mysql_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<p><strong><u><h2>".$results['SchoolName']."</h2></u></strong>".$results['text']."</p>";
echo "<p><strong>Location:</strong> ".$results['SchoolLocation']."".$results['text']."</p><br />";
echo "<p><strong>Notes:</strong> ".$results['SchoolNotes']."".$results['text']."</p><br /><br /><br />";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
echo "<br /><br /><br /><strong><h2>"."This is great news! The school you searched for is NOT on our Illegitimate High School List..."."</h2></strong>";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
我做了一些研究并找到this,但我不知道如何将它应用到我的情况中。
答案 0 :(得分:1)
假设您的数据库中的字段名称是位置:
echo "<p><strong>Location:</strong> <a href='".$results['Location']."' target='_blank'>".$results['SchoolLocation']."</a>".$results['text']."</p><br />";