Documentation

InitFromArray

CDBResult::InitFromArray(
 array values
 )

The mehtod initializes object of CDBResult class with values from an array. Non-static method.

Parameters

ParameterDescription
values Associative array with values of the CDBResult class object.


Examples of use

<?
$arr = array();
$arr[] = array("ID" => 1, "NAME" => "Title 1");
$arr[] = array("ID" => 2, "NAME" => "Title 2");
$arr[] = array("ID" => 3, "NAME" => "Title 3");
$arr[] = array("ID" => 4, "NAME" => "Title 4");

$rs = new CDBResult;
$rs->InitFromArray($arr);

$rs->NavStart(2);
if($rs->IsNavPrint())
{
     echo "<p>"; $rs->NavPrint("Elements"); echo "</p>";
}
?>
<?
// gets list of files and catalogues
CFileMan::GetDirList(Array($site_id, $path), $arDirs, $arFiles, $arFilter, Array($by=>$order), "DF");

// merge files and catalogues into single array
$arDirContent = array_merge($arDirs, $arFiles);

// create an object of CDBResult class
$rsDirContent = new CDBResult;

// initialise this object by the original array
$rsDirContent->InitFromArray($arDirContent);

// now in this object
// we can use all methods of CDBResult class
// for example, "Pagewise navigation":
$rsDirContent->NavStart(50);
if($rsDirContent->IsNavPrint()) echo "<p>"; $rs->NavPrint("Files"); echo "</p>";
while ($arElement = $rsDirContent->Fetch()):
    // if this catalog, then 
    if ($arElement["TYPE"]=="D"):
        // show catalog name
        echo $arElement["NAME"];
    else: // otherwise if this is a file, then
        // if this is a service file, then go to the next element 
        if ($arElement["NAME"]==".section.php") continue;
        // otherwise show it's name
        echo $arElement["NAME"];
    endif;
endwhile;
?>


© «Bitrix24», 2001-2024