Jump to content


This topic is now archived and is closed to further replies.


Adding Hyperlinks To Search Results

Recommended Posts


I have a search on my website which returns results based on the keywords row in my database. The problem is that the results are not clickable. The results returned are links to other websites and need to have hyperlinks attached to link_text and url. There is also a new_window row in the database which is used to determine whether a link will be opened in the current or a new window; 0 = current, 1 = new. I am not sure how to implement any of these things so I would appreciate any advice.

Here is the database table:

[code]CREATE TABLE `links` (
  `link_id` int(11) NOT NULL auto_increment,
  `category_code` varchar(10) NOT NULL default '0',
  `link_text` varchar(254) NOT NULL default '',
  `url` varchar(254) NOT NULL default '',
  `description` text NOT NULL,
  `keywords` text NOT NULL,
  `time_added` timestamp(14) NOT NULL,
  `new_window` tinyint(4) NOT NULL default '0',
  PRIMARY KEY  (`link_id`)

Here is the search results processing and display:

//This is only displayed if they have submitted the form
if ($searching =="yes")

//If they did not enter a search term we give them an error
if ($find == "")
echo "<p>You forgot to enter a search term";

// Otherwise we connect to our Database
mysql_connect("localhost", "linkadmin", "jup1terCl41re") or die(mysql_error());
mysql_select_db("pagelinks") or die(mysql_error());

// We preform a bit of filtering
$find = strtoupper($find);
$find = strip_tags($find);
$find = trim ($find);

//Now we search for our search term, in the field the user specified
$data = mysql_query("SELECT * FROM links WHERE keywords LIKE '%$find%'");

//And we display the results
while($result = mysql_fetch_array( $data ))
echo "<hr /><br />";
echo $result['link_text'];
echo "<br />";
echo $result['description'];
echo "<br />";
echo $result['url'];
echo "<br /><br />";  

echo "<hr /><br />";

//This counts the number or results - and if there wasn't any it gives them a little message explaining that
if ($anymatches == 0)
echo "Sorry, but we can not find an entry to match your query<br><br>";

//And we remind them what they searched for
echo "<b>Searched For:</b> " .$find;



Share this post

Link to post
Share on other sites
[code]echo "<a href=\"".$result['url']."\">".$result['url']."</a>";
echo "<br /><br />";  

Share this post

Link to post
Share on other sites
Thanks, your a legend

Any idea how I can make them open in a new window based on the new_window row? 0 = open in current window,  1 = open in new window.


Share this post

Link to post
Share on other sites


Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.