title: how to generate dynamic tooltips with data from MYSQL using PHP
body: <p>I have a PHP script that retrieves a number of random fields from one column in MYSQL and echos them to a page. What I want to be able to do is hover mouse over any of the echoed results and display a tooltip which shows additional information from my databse- such as info from two relevant fields in two separate columns in MYSQL database </p>
  
  <p>Would I have to include these extra colums in my SQL select statement and some how pass these to javascript to display tooltip or is there a way to do it with PHP alone? </p>
  
  <p>I'm fairly new to PHP and my javascript knowledge is thin. The idea sounds simple but I have a feeling it's going to be very difficult to do. </p>
  
  <p>Anyway, here is my code which has been helped out by mmmshuddup (cheers for that). I realise that I haven't protected against SQL injections yet. But I will! 
  Thanks.</p>
  
  <pre><code>&lt;?php 
  $host="localhost"; // Host name  
  $username=""; // Mysql username  
  $password=""; // Mysql password  
  $db_name="db"; // Database name  
  $tbl_name="sentence"; // Table name  
  
  // Connect to server and select databse. 
  mysql_connect("$host", "$username", "$password")or die("cannot connect");  
  mysql_select_db("$db_name")or die("cannot select DB"); 
  
  $sn=$_POST['numberofsentences']; 
  
  
  $query="SELECT line FROM `sentence` ORDER BY rand() LIMIT $sn"; 
  $result = mysql_query($query); 
  
  $count = 0;  
  while ($row = mysql_fetch_array($result)) {  
      // do something with $row. The following echos the results and adds a space after each sentence.  
      echo $row['line'], "&amp;nbsp";  
      if ($count &gt;= 4) {  
          echo '&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;';  
          $count = 0;  
      } else {  
          $count++;  
      }  
  } 
  // Close the database connection 
  mysql_close(); 
  
   ?&gt; 
  </code></pre>