• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 257
  • Last Modified:

Dynamic Hyperlink

Hello,

I am stuck on a hyperlink problem.  This is driving me nuts and should be a really simple fix.  I need to display some search results with a hyperlink at the end so users can click to the area of text within the results.  Here's my script to help explain:

This displays a hyperlink to the the enitre full_body result, and is working:

        <p align="center" class="style9"><span class="style3">Search result</span><strong>:</strong></p>
                        <p align="left" class="style9"><br>
                          <span class="style10"><a href="displayInt.php?recordID=<?php echo $row_rsMatch['mytable_title']; ?>" class="style1"><?php echo htmlentities($row_rsMatch['mytable_caption']); ?>
                          </a></span></p>
                        <p align="left" class="style9"><span class="style10"><a href="displayInt.php?recordID=<?php echo $row_rsMatch['mytable_title']; ?>" class="style1">

This part displays the hit word with a few words before and after.  The hit word is in bold and it works also:

 $search_key = $_GET['search'];
  $text = $row_rsMatch['mytable_full_body'];
 
  preg_match("/(^|\W)\w.{0,50}.{$search_key}.{0,50}\w($|\W)/i", $text, $subtext);
  $subtext[0] = preg_replace('/('.preg_quote($search_key).')/i','<b>\1</b>', $subtext[0]);
 
  ?>

Here's where I am stuck, I am trying to add a "read on" hyperlink to appear after the text results, such as:

 $urlvar =  $row_rsMatch['mytable_title']; echo htmlentities("Read On");
 echo $subtext[0]; echo "... <a src=\"$urlvar\"></a>";

But it appears before, not after the subtext echo (i.e.  Read on Here are your results ...)  I want it to go after such as (Here are your results ... Read on), and when the person clicks "Read on" it should take them to area on the results page where the $search_key hit is found....

Do-able?
 
0
south_paw
Asked:
south_paw
  • 8
  • 7
1 Solution
 
CtrlAltDlCommented:
Try this out:

$urlvar =  $row_rsMatch['mytable_title'];
echo $subtext[0];
echo "... <a src=\"$urlvar\">" . htmlentities("Read On") . "</a>";
0
 
CtrlAltDlCommented:
Or you could do this:

$urlvar =  $row_rsMatch['mytable_title'];
echo $subtext[0] . "... <a src=\"$urlvar\">Read On</a>";
0
 
south_pawAuthor Commented:
CtrlAltDl,

I had tried both of those already, they return (This is your result ... Read on) where "read on" does not equal a hyperlink, rather it is just text.
0
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
CtrlAltDlCommented:
Oops, it's missing the href:

$urlvar =  $row_rsMatch['mytable_title'];
echo $subtext[0] . "... <a href src=\"$urlvar\">Read On</a>";
0
 
south_pawAuthor Commented:

Tried that too.  It highlights the text as a link, as in the color chosen to identify hyperlinks, but the text is still not linking.  It cannot be clicked on....
0
 
south_pawAuthor Commented:
I got it working using echo "<a src=\"$urlvar\">$urlname</a>"; but the link was before not after the text results.
0
 
CtrlAltDlCommented:
So is everything working now?
0
 
south_pawAuthor Commented:
It has to be something like:

<?php

$urlvar =  $row_rsMatch['mytable_title'];
$urlname = 'Read On';
echo $subtext[0] . "... <a src=\"$urlvar\">$urlname</a>";

?>

But I still cannot get it to work !! Frustrating !! I thought creating a link would have been PHP 101  !
0
 
south_pawAuthor Commented:
"So is everything working now?"  Not yet....
0
 
CtrlAltDlCommented:
Try this and show me the HTML that is produces:
    echo $subtext[0] . "... <a href src=\"$urlvar\">$urlname</a>";
0
 
CtrlAltDlCommented:
Oops, it should be:
    echo $subtext[0] . "... <a href=\"$urlvar\">$urlname</a>";
0
 
CtrlAltDlCommented:
src is for img tags!
0
 
south_pawAuthor Commented:
O.K.  managed to fix it and pass the variable such as:

$subtext[0] . "... <a href= \"displayInt.php?recordID=$urlvar\">$urlname</a>";

Thanks for helping solve this part, the other part is arriving at the right area of text on the landing page.  Or is this outside the scope of the question?  I can open another question if you think so.
0
 
CtrlAltDlCommented:
Go ahead and ask, if it doesn't have anything to do with the original question then you should start a new question.
0
 
south_pawAuthor Commented:
Fair call, it's a bit of a stretch.

Thanks again for your assistance and prompt responses.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now