PDA

View Full Version : Split returned results into hrefs


Dalsor
05-15-2003, 02:57 PM
Kind of at a loss here and was wondering if someone wouldn't mind posting an example how to accomplish this.

I'm searching through a mysql db and returning 'help file' entries as well as keywords related to the search. I'd like to make the related keywords clickable so a new search is performs using those results.

This is what I'm using to display the results of the search.

while ($row= mysql_fetch_array($result))
{
$title = $row["hkeyword"];
$texto = $row["helptext"];
$hrelated = $row["related"];
$hdate = $row["created"];

echo "<strong>$count.) $title </strong><br>";
echo "$texto <br>";
echo "<i>See Also:</i><strong> $hrelated </strong><br>";
echo "<i>Help entry created on $hdate.</i><br>";
$count++ ;
}


What I'd like to do is something like:

echo "<i>See Also:</i><strong> <a href="help.php?q=$hrelated">$hrelated</a> </strong><br>";


This is what it looks like on a search now.

You searched for: "help"

Results of Your Search:
1.) Help
If you dont get help at Charter, get help somewhere.
See Also: Summary Startup Newbie
Help entry created on 2003-05-13.


Showing results 1 to 1 of 1


The problem with this method is there will be multiple related keywords for each search term, so hkeyword would need to be I guess split up into seperate hrefs if there's a space in there. I've seen this done before but can't find it to save me. If someone could post an example or point me to a thread where it's explained, I'd be most appreciative.

I hope this makes sense. :)

Thanks!

Eric

Dylan Leblanc
05-15-2003, 07:21 PM
$hrelated = explode(' ', $hrelated);

That will give you an array of the words, as long as they are separated by spaces.

implode() and explode() are very usefull functions
http://php.net/implode
http://php.net/explode

Dalsor
05-15-2003, 11:43 PM
Explode, that was it. Thanks! Got it working now.

:D