3

I wanna show tooltip with query data in php.

My php code is,

echo "<div class='tooltip' id='".$row['id']."' title='title1'>".$row['name']."</div>";

My Script is,

$(function() {
  $('.tooltip').tooltip({
    content:function()
    {
      var id =$(this)[0].id;
       <?php    
        $qry3 = "SELECT phone_no FROM history WHERE id='?>id<?php' GROUP BY name";
        $exc3   = mysql_query ($qry3,$con);
        $num3   = mysql_num_rows($exc3);
          while($rows3 = mysql_fetch_array($exc3))
          {
             array_push($name,'"'.$rows3[0].'"');
          }
        echo "return ".$name;
      ?>        
   }});
});

Where is my problem?

KarSho
  • 5,699
  • 13
  • 45
  • 78

1 Answers1

3

I think you are mixing up Javascript and PHP here. Your current PHP code get's executed only once when the server sends the Javascript to your browser. This cannot work. You can either store the tooltip for each HTML element e.g. in the title tag or you should load it dynamically whenever the tooltip should be shown. You would do this via an AJAX call to a PHP file (and not by putting the PHP code in the JS file).

florian h
  • 1,162
  • 1
  • 10
  • 24
  • i know that way, but i need use in the same page without ajax call. is there? – KarSho Jan 05 '13 at 14:27
  • 2
    Yes, you can store the tooltip data in each HTML element (like `` and read out that title value in the `bodyHandler()` function in JS. Or you could keep an array in JS for each element and populate it with the tooltip content via PHP. – florian h Jan 05 '13 at 14:33