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

php - regexp cyrillic filename not matches -

c# - OpenXML hanging while writing elements -

sql - Select Query has unexpected multiple records (MS Access) -