0

I've been working on that for a while, and google didn't help me that much on that one,

Basically, I am creating different divs, when you hover on them, you get more information. I managed to do that in a way that when you hover the div, the text changes.

Now, I would like to make it dynamic with a MySQL database, my different divs (already created) will get the text and change it with javascript.

UPDATE : The following code kinda works but doesn't show the iteration. My concern would be that the first div gets the first result (ID = 1), the second div gets the second result... and so on! I am fairly new to php/MySQL, and I didn't find a way to do it.

<script>
var n = 0;
$("div.enterleave").mouseenter(function() {
 n += 1;
 $(this).find("span").text( "<?php

        $reponse = $bdd->query('SELECT possesseur FROM jeux_video LIMIT 0, 4');
        while ($donnees = $reponse->fetch()) {
            echo $donnees['possesseur'] ; }
            $reponse->closeCursor(); 
    ?>");
}).mouseleave(function() {
 $(this).find("span").text("<?php

            $reponse = $bdd->query('SELECT nom FROM jeux_video LIMIT 0, 1');
            while ($donnees = $reponse->fetch()) {
                echo $donnees['nom'] ; }
                $reponse->closeCursor(); 
    ?>");
});

</script>

Thanks in advance!

2 Answers 2

2

You have concoct before and after this MySQL-related code. You should put semicolon after [...]text('" and write echo before "'); (after closeCursor).

 <?php

echo "<script>
var n = 0;
$('div.enterleave').mouseenter(function() {
 n += 1;
 $(this).find('span').text('";
            $reponse = $bdd->query('SELECT nom FROM jeux_video LIMIT 0, 10');
            while ($donnees = $reponse->fetch()) {
                echo $donnees['nom'] ; 
                }
                $reponse->closeCursor();
echo "');
}).mouseleave(function() {
 $(this).find('span').text('What does Patrick likes?');
});

</script>";

?>
Sign up to request clarification or add additional context in comments.

Comments

1

You can't concatenate there.

echo "<script>
var n = 0;
$('div.enterleave').mouseenter(function() {
 n += 1;
 $(this).find('span').text('";


        $reponse = $bdd->query('SELECT nom FROM jeux_video LIMIT 0, 10');
        while ($donnees = $reponse->fetch()) {
            echo $donnees['nom'] ; 
            }
            $reponse->closeCursor();

 echo "');
}).mouseleave(function() {
 $(this).find('span').text('What does Patrick likes?');
});

</script>";

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.