next_record called with no query pending
<p>I want to call a <code>PHP</code> function :</p>

<pre><code>$rights =  $user-&gt;recupererDroitCreateur($_SESSION[CODE_USER]);
</code></pre>

<p>Code of recupererDroitCreateur is :</p>

<pre><code>function recupererDroitCreateur($user_id) {
    $ret = array();
    $sSQL = "SELECT cm.class_menu_code
                 FROM menu m
                 LEFT JOIN classe_menu cm
                 ON m.class_menu_code = cm.class_menu_code
                 WHERE m.menu_deleted = 0 AND m.menu_visible = 1 AND cm.class_menu_parent IS NULL AND cm.class_menu_deleted = 0 
                 ORDER BY cm.class_menu_lib, m.menu_titre";
    $this-&gt;db-&gt;query($sSQL);
    while ( $this-&gt;db-&gt;next_record() ) {
        $code = $this-&gt;db-&gt;f('class_menu_code');
        $strMenus = $code.";";
        $this-&gt;recupererMenus($code, $code, $user_id, $strMenus);
    }
    return (explode(";", $strMenus));
}
</code></pre>

<p>Code of recupererMenus is :</p>

<pre><code>function recupererMenus($classRoot, $classParentDirect, $user_id, &amp;$menus)
{
    $sSQL1 = "SELECT class_menu_code FROM classe_menu WHERE class_menu_parent = '$classParentDirect' AND class_menu_deleted = 0";
    $this-&gt;db-&gt;query($sSQL1);
    while ( $this-&gt;db-&gt;next_record() ) {
        $this-&gt;recupererMenus($classRoot, $this-&gt;db-&gt;f('class_menu_code'), $user_id, $menus);
    }

    $sSQL = "SELECT m.menu_code
             FROM menu m
             LEFT JOIN classe_menu cm
             ON m.class_menu_code = cm.class_menu_code
             WHERE m.menu_deleted = 0 AND m.menu_visible = 1 AND cm.class_menu_parent = '$classParentDirect' AND cm.class_menu_deleted = 0 
             ORDER BY cm.class_menu_lib, m.menu_titre";

    $this-&gt;db-&gt;query($sSQL);
    while ( $this-&gt;db-&gt;next_record() ) 
    {
        $menus .= $this-&gt;db-&gt;f('menu_code').";";
    }
}
</code></pre>

<p>In runtime there is the error <code>next_record called with no query pending</code> : the error output tells the lines which cause the error and it says the line corresponding to this statement : <code>while ( $this-&gt;db-&gt;next_record() ) {</code> , there is also line pointing to the statement <code>$this-&gt;recupererMenus($code, $code, $user_id, $strMenus);</code></p>

<p>So what is wrong in my codes ?</p>
