function that return query result
<p>assume that i have a table named <em>mytable</em> with columns:</p>

<pre><code>------------------------
| id | field1 | field2 |
------------------------
</code></pre>

<p>and assume i have a html files:</p>

<pre><code>&lt;body&gt;
&lt;?php 
    include ('connect-db.php');
    include ('function.php');
?&gt;

&lt;ul&gt;
    &lt;?php 
        myfunction();

        while($row  = $result-&gt;fetch_assoc()){
            echo "&lt;li&gt;".$row['field1']." and ". $row[field2]."&lt;/li&gt;";
        }
    ?&gt;
&lt;/ul&gt;
&lt;/body&gt;
</code></pre>

<p>this is my <code>connect-db.php</code> file:</p>

<pre><code>&lt;?php
$servername = "localhost";
$username   = "root";
$password   = "root";
$dbname     = "dbname";

$conn=new mysqli($servername, $username, $password, $dbname);
?&gt;
</code></pre>

<p>and this is my <code>function.php</code> file:</p>

<pre><code>&lt;?php
    function myfunction(){
        $sql    = "SELECT * FROM mytable";
        $result = $conn-&gt;query($sql);
    }
?&gt;
</code></pre>

<p>How to echo the field1 and field 2? because i have and error</p>