9
votes

I have a text for example

"The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog. The quick brown fox jumps

over the lazy dog."

When i click on word i must get data from XML or from mysql about this word.

How i can make every word active for click and send it to another script

for example: I click on dog, and in new window i get information about dog? on fox about fox? every word must be clickable

Any ideas, links or examples?

Using php, mysql, jquery, ajax

2
I don't think you want every word though. I'm sure you don't want "the" or "over" things like that ?mcgrailm

2 Answers

9
votes

Wrap each word in its own span, probably with a CSS class to differentiate them as "word spans". Add a hover handler for all spans with that class, that extracts the content and does an ajax request to get the data associated with that word. If you get some data back, pop up a DIV ("tip") containing the information that's tied to the mouse location and has a z-index that allows it to float over the rest of the content. When the mouse isn't over the span, remove the associated "tip".

There are a variety of "tip" plugins for jQuery that you could easily adapt to this requirement.

<span class="word">the</span> <span class="word">quick</span> ...

// use a ficticious tooltip plugin that uses gettip.php and passes
// the content of the DOM element as a parameter
$('span.word').tooltip({ url: '/gettip.php' });

NOTE: you probably only want to do this for words of interest, not every word on the page. That is, have a dictionary of words that need tooltips and only wrap those words on the page that exist in the dictionary. There's little point (unless it's a grammar application) to do this with every possible word.

1
votes

Too much questions in one. I'd answer to one from the title. Let's assume you defined a "word" as a space delimited group of characters. So, you can use explode() function and get an array of words

Now you can iterate over it's array and print it out any fashion you want:

$string = "The quick brown fox jumps over the lazy dog";
$array = explode(" ",$string);

foreach ($array as $word) {
  $eword=urlencode($word);
  echo "<a href=getinfo.php?word=$eword>$word</a> ";
}

So, you will have your links and now you have to get an php/mysql beginners book to learn how to write the rest