Reputation: 3166
I have a database, which when queried, can return results that sometimes contain a web address. If there is an address in the results, it will always be located in the "Location" field of the database.
Currently, when the results return, it returns as a line of text (which the user would have to copy/paste into a browser window).
How do I make it return a hyperlink, instead of just a line of text?
Here's my 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;
}
?>
I did some research and found this, but I don't see how to apply it to my situation.
Upvotes: 0
Views: 1743
Reputation: 3757
Assuming that your field name from DB is Location:
echo "<p><strong>Location:</strong> <a href='".$results['Location']."' target='_blank'>".$results['SchoolLocation']."</a>".$results['text']."</p><br />";
Upvotes: 1