title: How to put mysql inside a php function?
body: <p>I have problem about putting mysql into a function showMsg(). The mysql is working fine if it is not wrapped by function showMsg(), but when I wrap it with function showMsg(), it gives error message "Warning: mysql_query(): supplied argument is not a valid". How to put mysql inside a php function? Below is my codes : </p>
  
  <pre><code>&lt;?php    
  function showMsg(){   
          $query2 = "SELECT id, message, username, datetime FROM messageslive ORDER BY id DESC LIMIT 20";
          $result2 = mysql_query($query2,$connection) or die (mysql_error());
          confirm_query($result2);
          $num = mysql_num_rows($result2); 
          while($msginfo = mysql_fetch_array($result2)){
              echo $msginfo['message'];
              echo $msginfo['username'];
          }
  }
  
  &lt;div&gt;
     &lt;?php showMsg(); ?&gt;
  &lt;/div&gt;
  ?&gt;
  </code></pre>