php - sqlsrv_query missing first result in while loop -


hi have following code

function dropdownmenumobile($parentid,$siteid,$root=false) {     $menu = "";     $sql = "exec spgeneratedropdownmenumobile ".$parentid.",".$siteid;     $stmt = sqlsrv_query($globals['conn'],$sql);     sqlsrv_fetch($stmt);     if($stmt && sqlsrv_has_rows($stmt) === true)     {         $menu .= "<ul>";             while($rs = sqlsrv_fetch_array($stmt, sqlsrv_fetch_numeric))             {                 $urllink = str_replace("<br />"," ",$rs[2]);                 $urllink = replaceillegalchars($urllink);                 $actuallink = (strlen($rs[7]) > 2) ? $rs[7] : $rs[0]."/".makeseurl($urllink);                 $liclass = ($rs["5"] > 0)?"expand":"";                 $menu .= "<li class=\"".$liclass."\">";                     $menu .= "<a href=\"/".$actuallink."\">".$rs[2]."</a>";                     $menu .= ($rs[5] > 0) ? dropdownmenumobile($rs[0],$siteid,"") : "";                 $menu .= "</li>";             }         $menu .= "</ul>";     }     return $menu; } 

it runs in numerous other places, reason in while loop seems missing first result every time called.

i think because run

sqlsrv_fetch($stmt); 

which fetches first result , after run

sqlsrv_fetch_array($stmt, sqlsrv_fetch_numeric) 

which continues fetching second result.

just remove first fetch.


Comments

Popular posts from this blog

html - Sizing a high-res image (~8MB) to display entirely in a small div (circular, diameter 100px) -

java - IntelliJ - No such instance method -

identifier - Is it possible for an html5 document to have two ids? -