<?php
require("includes/check_auth_user.php");
require("includes/dbconnect.php");
include ('includes/function.php');

$array = '';
$zdb = $_SESSION["zdbyear_" . $dbname];
$myyear = $_SESSION[$myyear];

$mlen = strlen($zdb);
$alen = $mlen - 4;

$prevflag = 0;
$getyear = mysqli_query($conn, "SELECT * from compyear where finyear != '$myyear' order by lastdate desc limit 0,1") or die(mysqli_error($conn));
if (mysqli_num_rows($getyear) > 0) {
    $prevflag = 1;

    $fetyear = mysqli_fetch_array($getyear);
    $prevyear = $fetyear['finyear'];
    $prevdbf = substr($zdb, 0, $alen) . "$prevyear";
}
mysqli_select_db($conn, $zdb);

$searchTerm = $_REQUEST["ssearch"];
$searchcond = "";
if (!empty($searchTerm)){
    $searchcond = "and branch LIKE '%$searchTerm%'";
}

$drawbank = mysqli_query($conn, "SELECT branch FROM $prevdbf.`bankrecp` WHERE vouchno !='' $searchcond 
                         UNION
                         SELECT branch FROM `bankrecp` WHERE vouchno !='' $searchcond group by branch order by branch ") or die(mysqli_error($conn));

while ($r = mysqli_fetch_assoc($drawbank)) {

    $branch = $r['branch'];

    echo "<tr>";
    echo "<td class = 'tdbranch'>$branch</td>";
    echo "</tr>";
}

?>