D:\host\scoreman.in\highrange2026\functions_working.php

<?php
 
require_once 'PHPMailer/PHPMailer.php';
require_once 'PHPMailer/SMTP.php';
require_once 'PHPMailer/Exception.php';

use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;

/**
 * Serpentine ACROSS HEATS (like your screenshot), grouped by (agegroup, gender).
 * Compatible with PHP 7.1+ and 8.1+ (no MySQL user variables).
 *
 * Filters:
 *  - event column truthy (not ''/'0'/'No')
 *  - chno <> ''
 *  - order_status = 'Success'
 *  - optional repdistrict = ?
 *
 * Ordering:
 *  - agorder (NULLs last), then agegroup, gender, numeric chno
 *
 * Returns rows: agegroup, gender, heat_no, lane_no, chno, sname, club/clubname, repdistrict, etc.
 */
function scoresheet($db, $event, $maxPerHeat, $repdistrict = null) {
    // ---- validate
    $allowed = [
        'rink1','rink2','rink3','rink4','rink5','rink6','rink7',
        'road1','road2','road3','road4','road5',
        'p2p','elim','relay','mixedrelay','p2prd','elimrd',
        'marathon','figure','free','pair','solodance','pairdance',
        'quartet','precisionskating','showgroup','quadhockey','inlinehockey',
        'mixedrollerhockey','speedslalom','pairslalom','classicslalom',
        'inlinefree','alpine','downhill','rollerderby','rollerfreestyle',
        'skateboarding','scooter'
    ];
    if (!in_array($event, $allowed, true)) {
        throw new InvalidArgumentException("Invalid event column: ".$event);
    }
    $W = (int)$maxPerHeat;
    if ($W <= 0) throw new InvalidArgumentException("maxPerHeat must be > 0");

    // ---- build query (no MySQL user variables)
    $where = "COALESCE($event, '') <> '' AND $event NOT IN ('0','No')
              AND COALESCE(chno, '') <> ''
              AND order_status = 'Success'";

    $bindTypes = '';
    $bindVals  = [];

    if ($repdistrict !== null && $repdistrict !== '') {
        $where     .= " AND repdistrict = ?";
        $bindTypes .= 's';
        $bindVals[] = $repdistrict;
    }

    $sql = "
        SELECT
            appno, chno, sname, club, clubname, repdistrict,
            skaterid, dob, age, agegroup, gender,
            IFNULL(agorder, 999999) AS agorder
        FROM applications
        WHERE $where
        ORDER BY
            IFNULL(agorder, 999999),
            agegroup, gender,
            CAST(chno AS UNSIGNED), chno
    ";

    $stmt = mysqli_prepare($db, $sql);
    if (!$stmt) {
        throw new RuntimeException('Prepare failed: '.mysqli_error($db));
    }
    if ($bindTypes !== '') {
        // PHP 7/8: bind by reference
        $refs = [ &$bindTypes ];
        foreach ($bindVals as $i => $v) { $refs[] = &$bindVals[$i]; }
        call_user_func_array('mysqli_stmt_bind_param', array_merge([$stmt], $refs));
    }
    if (!mysqli_stmt_execute($stmt)) {
        throw new RuntimeException('Execute failed: '.mysqli_stmt_error($stmt));
    }

    // fetch all base rows
    $base = [];
    if (function_exists('mysqli_stmt_get_result')) {
        $res = mysqli_stmt_get_result($stmt);
        while ($row = mysqli_fetch_assoc($res)) $base[] = $row;
        mysqli_free_result($res);
    } else {
        mysqli_stmt_store_result($stmt);
        mysqli_stmt_bind_result(
            $stmt, $appno, $chno, $sname, $club, $clubname, $repdistrictOut,
            $skaterid, $dob, $age, $agegroup, $gender, $agorder
        );
        while (mysqli_stmt_fetch($stmt)) {
            $base[] = compact(
                'appno','chno','sname','club','clubname','repdistrictOut',
                'skaterid','dob','age','agegroup','gender','agorder'
            );
        }
    }
    mysqli_stmt_close($stmt);

    // ---- group by (agegroup, gender) in the order they appear
    $out = [];
    $currKey = null;
    $group   = [];

    $flushGroup = function() use (&$out, &$group, $W) {
        $n = count($group);
        if ($n === 0) return;

        // number of heats
        $H = (int)ceil($n / $W);
        // assign serpentine across heats (column-wise snake):
        // index i = 0..n-1; col = intdiv(i, H), row = i % H
        // heat = (col even) ? row+1 : (H - row); lane = col+1
        $assigned = [];
        for ($i = 0; $i < $n; $i++) {
            $col  = intdiv($i, $H);
            $row  = $i % $H;
            $heat = ($col % 2 === 0) ? ($row + 1) : ($H - $row);
            $lane = $col + 1;

            $r = $group[$i];
            $assigned[] = [
                'agegroup'    => $r['agegroup'],
                'gender'      => $r['gender'],
                'heat_no'     => $heat,
                'lane_no'     => $lane,
                'appno'       => $r['appno'],
                'chno'        => $r['chno'],
                'sname'       => $r['sname'],
                'club'        => $r['club'],
                'clubname'    => $r['clubname'],
                'repdistrict' => isset($r['repdistrictOut']) ? $r['repdistrictOut'] : $r['repdistrict'],
                'skaterid'    => $r['skaterid'],
                'dob'         => $r['dob'],
                'age'         => $r['age'],
            ];
        }

        // sort inside group: heat ASC, lane ASC
        usort($assigned, function($a, $b) {
            if ($a['heat_no'] === $b['heat_no']) {
                return $a['lane_no'] <=> $b['lane_no'];
            }
            return $a['heat_no'] <=> $b['heat_no'];
        });

        // append to global output
        foreach ($assigned as $row) $out[] = $row;

        // reset group
        $group = [];
    };

    foreach ($base as $row) {
        $key = $row['agegroup'].'|'.$row['gender'].'|'.$row['agorder'];
        if ($currKey !== null && $key !== $currKey) {
            $flushGroup();
        }
        $group[] = $row;
        $currKey = $key;
    }
    // flush last group
    $flushGroup();

    return $out;
}

function renderScoresheet(array $rows, $eventTitle = 'Start List', $raceName = '', $repdistrict = '') {
    if (!$rows) return "<p>No entries.</p>";

    // Map DB gender values to display labels
    $mapGender = function($g) {
        $gl = strtolower(trim((string)$g));
        if (in_array($gl, ['f','female','girl','girls','women','woman'], true)) return 'Girls';
        if (in_array($gl, ['m','male','boy','boys','men','man'], true))       return 'Boys';
        return $g ?: '';
    };

    // Printed timestamp (IST) used in every page footer
    date_default_timezone_set('Asia/Kolkata');
    $printedOn = 'Printed On : ' . date('d-m-Y h:i:sa');

    // Safe file name for logo
    $logoSafe = preg_replace('/[^A-Za-z0-9_-]/', '_', (string)$repdistrict);
    $logoHtml = '';
    if ($logoSafe !== '') {
        $src = "districtlogos/" . $logoSafe . ".png";
        // Will be hidden on screen via CSS, visible in print
        $logoHtml = "<div class='logo'><img src=\"".htmlspecialchars($src)."\" alt=\"\" style=\"width:75%;height:auto;\" onerror=\"this.style.display='none'\" /></div>";
    }

    $css = <<<CSS
<style>
  body { font-family: Arial, sans-serif; font-size: 12pt; }
  h2, h3, h4, h5 { margin: 6px 0; }
  table { border-collapse: collapse; width: 100%; margin: 8px 0 14px; table-layout: fixed; }
  th, td { border: 1px solid #444; padding: 6px 8px; text-align: left; vertical-align: top; overflow: hidden; }
  th, td { white-space: nowrap; }
  .cell-name, .cell-remarks { white-space: normal; word-break: break-word; }
  .cell-club { text-overflow: ellipsis; }
  .cell-chno { font-weight: bold; }
  th.th-chno { font-weight: bold; }

  /* Fixed column widths (sum = 100%) */
  .col-lane    { width: 8%;  }
  .col-chno    { width: 12%; }
  .col-name    { width: 34%; }
  .col-club    { width: 22%; }
  .col-remarks { width: 14%; }
  .col-pos     { width: 10%; }

  .page {
    page-break-after: always;
    min-height: 96vh;
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
  }
  @media print { .page { page-break-after: always; } }

  .header  { text-align: center; margin-bottom: 6px; }
  .header .logo { display: none; }              /* hide logo on screen */
  @media print {
    .header .logo { display: block; margin: 0 auto 6px; }  /* show only in print */
  }

  .content { flex: 1 1 auto; }
  .heatTitle { margin: 4px 0; font-size: 11.5pt; }

  .footer {
    display: flex;
    flex-direction: column;
    color: #000;
    font-size: 11pt;
    margin-top: 12px;
  }
  .sigrow { display: flex; justify-content: space-between; }
  .printed { margin-top: 4px; font-size: 9pt; }
</style>
CSS;

    $out = $css;

    $currKey  = null;   // "agegroup|gender"
    $currHeat = null;
    $openTable = false;
    $openPage  = false;

    foreach ($rows as $r) {
        $ag   = $r['agegroup'];
        $gRaw = $r['gender'];
        $gLbl = $mapGender($gRaw);
        $heat = (int)$r['heat_no'];
        $key  = $ag . '|' . $gRaw;

        /* ==== New PAGE for each (agegroup, gender) ==== */
        if ($currKey !== $key) {
            if ($openTable) { $out .= "</tbody></table>\n"; $openTable = false; }
            if ($openPage)  {
                $out .= "</div><!-- .content -->\n";
                $out .= "<div class='footer'>"
                      .   "<div class='sigrow'><span>Sign.</span><span>Chief.</span></div>"
                      .   "<div class='printed'>".htmlspecialchars($printedOn)."</div>"
                      . "</div>\n";
                $out .= "</div><!-- .page -->\n";
                $openPage = false;
            }

            $currKey  = $key;
            $currHeat = null;

            $out .= "<div class='page'>\n";
            $out .= "<div class='header'>"
                  . $logoHtml
                  . "<center><h3>".htmlspecialchars($eventTitle)."</h3></center>"
                  . "<center><h5>".htmlspecialchars($raceName)." RACE CHART</h5></center>"
                  . "</div>\n";
            $out .= "<div class='content'>\n";
            $out .= "<h3>".htmlspecialchars($ag)." - ".htmlspecialchars($gLbl)."</h3>\n";
            $openPage = true;
        }

        /* ==== New heat table (no extra page break) ==== */
        if ($currHeat !== $heat) {
            if ($openTable) { $out .= "</tbody></table>\n"; }
            $currHeat = $heat;
            $out .= "<div class='heatTitle'>Heat {$heat}</div>\n";
            $out .= "<table>"
                  . "<colgroup>"
                  . "<col class='col-lane'>"
                  . "<col class='col-chno'>"
                  . "<col class='col-name'>"
                  . "<col class='col-club'>"
                  . "<col class='col-remarks'>"
                  . "<col class='col-pos'>"
                  . "</colgroup>"
                  . "<thead><tr>"
                  . "<th>Lane</th><th class='th-chno'>Ch.No.</th><th>Name</th>"
                  . "<th>Team</th><th>Timing/Remarks</th><th>Position</th>"
                  . "</tr></thead><tbody>\n";
            $openTable = true;
        }

        $team = ($r['clubname'] !== '' ? $r['clubname'] : $r['club']);
        $out .= "<tr>"
              . "<td>".(int)$r['lane_no']."</td>"
              . "<td class='cell-chno'>".htmlspecialchars($r['chno'])."</td>"
              . "<td class='cell-name'>".htmlspecialchars($r['sname'])."</td>"
              . "<td class='cell-club' title=\"".htmlspecialchars($team)."\">".htmlspecialchars($team)."</td>"
              . "<td class='cell-remarks'></td>"
              . "<td></td>"
              . "</tr>\n";
    }

    // Close last table/page + footer
    if ($openTable) { $out .= "</tbody></table>\n"; }
    if ($openPage)  {
        $out .= "</div><!-- .content -->\n";
        $out .= "<div class='footer'>"
              .   "<div class='sigrow'><span>Sign.</span><span>Chief.</span></div>"
              .   "<div class='printed'>".htmlspecialchars($printedOn)."</div>"
              . "</div>\n";
        $out .= "</div><!-- .page -->\n";
    }

    return $out;
}

function assignchestno()
{
include('dbconnect.php');
set_time_limit (1200);
	/*$databaseQuery = 'UPDATE applications AS t
JOIN
(
    SELECT @rownum:=@rownum+1 rownum,appno,club,skatertype,CONVERT(agorder,UNSIGNED INTEGER),gender,CONVERT(appno,UNSIGNED INTEGER) 
    FROM applications
    CROSS JOIN (select @rownum := 0) rn
  where status != "delete" AND skatertype LIKE "Speed%%" order by club,skatertype,CONVERT(agorder,UNSIGNED INTEGER),gender desc,CONVERT(appno,UNSIGNED INTEGER) 
) AS r ON t.appno = r.appno
SET t.skaterid =r.rownum';*/
$dt=$_SESSION['teamf'];

$dbqs='SELECT @rownum:=@rownum+1 rownum,appno,club,skatertype,CONVERT(agorder,UNSIGNED INTEGER),gender,CONVERT(appno,UNSIGNED INTEGER) 
    FROM applications
    CROSS JOIN (select @rownum := 100) rn
  where repdistrict="'.$dt.'" AND status != "Delete" AND status != "Rejected" AND (order_status="Success") AND ((skatertype LIKE "Speed%%") OR (skatertype LIKE "Tenacity")) order by club,skatertype desc,CONVERT(agorder,UNSIGNED INTEGER),gender desc,CONVERT(appno,UNSIGNED INTEGER) ';
  
  $selectresult = mysqli_query($con,$dbqs) or die('Query failed: ' . mysqli_error());
 // echo $dbqs;
  while($row = mysqli_fetch_array($selectresult))
  {
	  $chno=$row['rownum'];
	  $appno=$row['appno'];
	  
	  $updateq ='update applications set chno='.$chno.' where appno='.$appno.' and (chno="" or chno is NULL)';

	$updateresult = mysqli_query($con,$updateq) or die('Query failed: ' . mysqli_error());
	echo $chno." ".$appno." ".$con -> affected_rows."<br/>";
	  
  }


echo mysqli_num_rows($selectresult);

	

}

function sendform($appno)
{


    include('dbconnect.php');

    $databaseQuery = 'SELECT appno, sname, email, hashcode FROM applications WHERE appno = "' . mysqli_real_escape_string($con, $appno) . '"';
    $result = mysqli_query($con, $databaseQuery) or die('Query failed - Send Form: ' . mysqli_error($con));

    if ($result && $row = mysqli_fetch_array($result)) {
        $appno = $row["appno"];
        $sname = $row["sname"];
        $email = $row["email"];
        $key   = $row["hashcode"];

        $content = '<html><body><b>Dear Skater '.$sname.',<br/><br/></b><br/>
Your registration is complete.<br/><br/>

You can download your <b>TAMILNADU DISTRICT CHAMPIONSHIPS – 2025 - Entry Form </b> in the following link.<br/>

<a href="https://tamilnaduskate.com/tndistricts2025/application.php?appno='.$appno.'&k='.$key.'">Click Here to Print / Download Application Form</a>
<br/></b><br/>
Please contact your District / State Unit for further details and approval.
Thanks & Regards<br/><br/>
TNRSA<br/>
tamilnaduskate.com
</body></html>';

        $mail = new PHPMailer(true);
        try {
            // SMTP settings
            $mail->isSMTP();
            $mail->Host       = 'mail.tamilnaduskate.com';
            $mail->SMTPAuth   = true;
            $mail->Username   = 'office@tamilnaduskate.com';
            $mail->Password   = 'priority1@1';
            $mail->SMTPSecure = ''; // no encryption
            $mail->Port       = 25;

            // $mail->SMTPDebug = 2; // optional debug
            // $mail->Debugoutput = 'html';

            // Recipients
            $mail->setFrom('office@tamilnaduskate.com', 'TNRSA');
            $mail->addAddress($email, $sname);
         //   $mail->addBCC('jeganonly@gmail.com');

            // Content
            $mail->isHTML(true);
            $mail->Subject = $sname." |Entry Form ".$appno." | TAMILNADU DISTRICT CHAMPIONSHIPS - 2025";
            $mail->Body    = $content;

            $mail->send();
            $mailres = "Success";
        } catch (Exception $e) {
            $mailres = "Mailer Error: " . $mail->ErrorInfo;
        }

        $qtext = 'UPDATE applications SET emailstatus="' . mysqli_real_escape_string($con, $mailres) . '" WHERE appno = "' . $appno . '"';
        mysqli_query($con, $qtext);
    }
}

function sendformold($appno)
{
include('dbconnect.php');
$databaseQuery = 'SELECT appno,sname,email,hashcode FROM applications where (appno= "'.$appno.'")';
$result = mysqli_query($con,$databaseQuery) or die('Query failed: ' . mysqli_error());
if($result)
{

	$row = mysqli_fetch_array($result);

$appno=$row["appno"];
$sname=$row["sname"];
$email=$row["email"];
$key=$row["hashcode"];

$content='<html><body><b>Dear Skater '.$sname.',<br/><br/></b><br/>
Your registration is complete.<br/><br/>

You can download your <b>TAMILNADU DISTRICT CHAMPIONSHIPS – 2025 - Entry Form </b> in the following link.<br/>

<a href="https://tamilnaduskate.com/tndistricts2025/application.php?appno='.$appno.'&k='.$key.'">Click Here to Print / Download Application Form</a>
<br/></b><br/>
Please contact your District / State Unit for further details and approval.
Thanks & Regards<br/><br/>
TNRSA<br/>
tamilnaduskate.com
</body></html>';


//$to = "jeganonly@gmail.com,krishnamani_k@yahoo.com,vishnuamalraj@yahoo.com";
$to =$email;
//$to =$email.",jeganonly@gmail.com";
//$to ="jeganonly@gmail.com";
$subject = $sname." |Entry Form ".$appno." | TAMILNADU DISTRICT CHAMPIONSHIPS – 2025";

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= "From: office@tamilnaduskate.com" . "\r\n" ;
//$headers .= "Bcc: jeganonly@gmail.com"; //disable later

$mailres=mail($to,$subject,$content,$headers);


$qtext='UPDATE applications SET emailstatus="'.$mailres.'" WHERE appno = "'.$appno.'"';
	//	echo $qtext;
		 mysqli_query($con,$qtext) or mysqli_error();
			

			

}



}


function listskaterbase()
{

	include('dbconnect.php');
	
	$dt=$_SESSION['username'];
	if($dt=="secretary")
	{
		$dt=$_SESSION['teamf'];
	//	$dt="Chennai";
	}
	//$qtext='SELECT appno, sname, dob, agegroup, gender, club from skaterbase_'.strtolower($_SESSION['username']).' where status != "delete"';

	$qtext='SELECT appno, sname, dob, agegroup, gender, clubname as club from tdrsc2021 where status != "delete"';

	//where clubname="'.strtolower($_SESSION['username']).'" AND

//	echo $qtext;
$result3 = mysqli_query($con,$qtext) or die('Query failed: ' . mysqli_error());
				while($row = mysqli_fetch_array($result3))
  {
	  
	    $appno=trim($row["appno"]);
 $sname=trim($row["sname"]);
$dob=trim($row["dob"]);
$ag=trim($row["agegroup"])." ".trim($row["gender"]);
$club=trim($row["club"]);
//$photo="http://".$_SERVER[HTTP_HOST]."/oldpics/".trim($row["Photo"]);
$gender=trim($row["gender"]);
echo '<li><a href="#" onclick="loadprof(\''.$appno.'\');">'.$sname." | ".$dob." | ".$club.' </a></li>';

  }
}

function listentries($stypesel,$teamfilter=NULL,$del=NULL)
{	

	include('dbconnect.php');
	
$delstatus="";
if($del=="hidedelete")
{
	$delstatus='AND status != "delete" ';
}

$stype=$stypesel;
$dt="";
	$club=$_SESSION["username"];
	if($club=="secretary")
	{
	//	$team=$_SESSION['team'];
	//$team=$teamfilter;
	$team="%";
	$dt=$teamfilter;

	}
	else
	{
		if($club=="")
		{
			loginbox();
			return;
		}
		$team=$club;
	}
	//echo $team;
	
	/////echo "THANK YOU. Registrations Closed";
	////return;

$usertype=$_SESSION["usertype"];



if($usertype=="District")
{
$team="%";
	$dt=$_SESSION["currentdistrict"];


}
else if($usertype=="Club")
{
	$team=$_SESSION["username"];
	$dt=$_SESSION["currentdistrict"];
}





		if($stype!="Other")
		{
	$databaseQuery = 'SELECT * FROM applications WHERE (skatertype like "%'.$stype.'%") and (club like "%'.$con->real_escape_string($team).'%")and (repdistrict like "%'.$con->real_escape_string($dt).'%") '.$delstatus.' AND (order_status="Success")  order by agorder+0,gender desc,skatertype,club,CONVERT(appno,UNSIGNED INTEGER)';


		}
		else
		{
				$databaseQuery = 'SELECT * FROM applications WHERE (otherdiscipline <> "") and (club like "%'.$con->real_escape_string($team).'%") and (repdistrict like "%'.$con->real_escape_string($dt).'%")'.$delstatus.' AND (order_status="Success")   order by skatertype,agorder+0,gender desc,club,CONVERT(appno,UNSIGNED INTEGER)';
		}

	//echo $databaseQuery;
	$result3 = mysqli_query($con,$databaseQuery) or die('Query failed: ' . mysqli_error());
	date_default_timezone_set('Asia/Kolkata');

	echo '<p class="font2"> ' .mysqli_num_rows($result3) . ' Results found for "'.$dt."-".$team.'-'.$stype.'" as on '.date("d-m-Y h:i:sa").' </p>';
	
	echo '<title>'.$team.'-'.$stype.'</title>';
	IF($_SESSION['usertype']=="Club")
	{
			echo '<a href="print.php?stype='.$stype.'" target="_blank" class="noprint ui-btn ui-btn-raised  ui-btn ui-btn-inline waves-effect waves-button waves-effect waves-button" ><i class="zmdi zmdi-print zmd-2x"></i> Print Entry Form</a>';
	}
	else if($_SESSION['username']=="secretary" || $_SESSION['usertype']=="District")
	{
			echo '<a href="print-list.php?stype='.$stype.'" target="_blank" class="noprint ui-btn ui-btn-raised  ui-btn ui-btn-inline waves-effect waves-button waves-effect waves-button" ><i class="zmdi zmdi-print zmd-2x"></i> Print List</a>';
	}


echo '<table id="listtable" data-role="table" data-mode="columntoggle" style="overflow-x: auto; width:90%;"    class="ui-responsive table-stroke">';
echo '<thead>';

                if($stype=="all" )
			{
                
 echo '<tr class="th-groups" >
            
            <th colspan="4" data-priority="1" style="height:auto !important; text-align:center;">Skater Details</th>
            <th colspan="2" data-priority="5" style="height:auto !important; text-align:center;" >DOB & Age</th>
            <th colspan="2" data-priority="2" style="height:auto !important; text-align:center;">Age Group</th>
            <th colspan="1" data-priority="6" style="height:auto !important; text-align:center;">Representing Team</th>
            <!--<th colspan="1" data-priority="6" style="height:auto !important; text-align:center;">Residential Address</th>-->
            <th colspan="2" data-priority="1" style="height:auto !important; text-align:center;">Tenacity</th>
            <th colspan="2" data-priority="1" style="height:auto !important; text-align:center;">Under 5 Quad</th>
			<th colspan="2" data-priority="1" style="height:auto !important; text-align:center;">Under 5 Inline</th>
			 <th colspan="4" data-priority="1" style="height:auto !important; text-align:center;">Quad Events</th>
            <th colspan="10" data-priority="1" style="height:auto !important; text-align:center;">Inline Events</th>
			<th colspan="1" data-priority="4" style="height:auto !important; text-align:center;">Comments</th>
        </tr>';
			}
		
echo '<tr>
<th><div class="verticalText">Sl.No.</div></th>';

// if($_SESSION['username']=="secretary")
// {
 if($stype=="Speed-Quad"|| $stype=="Speed-Inline" || $stype=="Tenacity" || $stype=="Under5-Quad" || $stype=="Under5-Inline" )
			{
			echo '<th><div>Race No.</div></th>';
			}
// }		
echo '<th><div class="verticalText">AppNo</div></th>



<th><div>Status</div></th>
			<th><div>RSFI App.no.</div></th>
				<th ><div style=" width:120px;">Skater Name</div></th>
                <th><div>Date_of_Birth</div></th>
                <th><div>Age</div></th>
                <th><div>AgeGroup</div></th>
                <th><div>Gender</div></th>
                <th><div>Representing Team</div></th> 
          <!--         <th><div>Residential Address</div></th>

             <th class="noprint"><div class="noprint">View Doc.</div></th>
<th class="noprint"><div class="noprint">Doc Password</div></th>

<!--<th class="noprint"><div class="noprint">Approve</div></th>
<th class="noprint"><div class="noprint">Reject</div></th> -->';

 if($_SESSION['username']=="secretary" || $_SESSION['usertype']=="District" || $_SESSION['usertype']=="Club")
//if($_SESSION['username']=="secretary")
{
echo '<th class="noprint"><div class="noprint">Edit</div></th>';
}

 echo '
 <!--<th class="noprint"><div class="noprint">Print</div></th>-->
<th class="noprint"><div class="noprint">Delete</div></th>


                ';
            
                if($stype=="Tenacity" || $stype=="all")
			{
             
              echo'  <th><div class="verticalText">Race 1</div></th>
                <th><div class="verticalText">Race 2</div></th> 
             <!--   <th><div class="verticalText">Adj-Rink IIA</div></th> -->';
             
			}
               
               
                if($stype=="Under5-Quad" || $stype=="all")
			{
               
               echo '<th><div class="verticalText">Under 5- Quad Race 1</div></th>
                <th><div class="verticalText">Under 5-Quad Race 2</div></th> 
             <!--   <th><div class="verticalText">Adj-Rink IIA</div></th> -->';
             
			}
			if($stype=="Under5-Inline" || $stype=="all")
			{
               
               echo '<th><div class="verticalText">Under 5- Inline Race 1</div></th>
                <th><div class="verticalText">Under 5- Inline Race 2</div></th> ';
            
             
			}
               
                if($stype=="Speed-Quad"|| $stype=="all" )
			{
                echo '<th><div class="verticalText">Rink - I<br/>(1 Lap  [200M])</div></th>
                <th><div class="verticalText">Rink - II<br/>(2 Lap / 500+D)</div></th>
                 <th><div class="verticalText">Rink - III<br/>(3 Lap / 4 Lap / 1000 M)</div></th>
				  <th><div class="verticalText">Road - I<br/>(1 Lap)</div></th>
                			 <th><div class="verticalText">Road - II<br/>(1500 / 3000 M)</div></th>  ';               
                   
			}
               
                if($stype=="Speed-Inline"|| $stype=="all" )
			{
              
                 echo ' <th><div class="verticalText">Rink - IV<br/>(1 Lap [200M])</div></th>
                <th><div class="verticalText">Rink - V<br/>(500+D)</div></th>
                <th><div class="verticalText">Rink - VI<br/>(1000 M)</div></th>
                   <th><div class="verticalText">Rink - VII<br/>DUAL TT(200 M)</div></th>

                 <th><div class="verticalText">Points Track (5000 M)</div></th>
                <th><div class="verticalText">Elimination - Rink (10000 M)</div></th> 
                   <th><div class="verticalText">Road - III (100 M)</div></th>
                    <th><div class="verticalText">Road - IV (1 Lap)</div></th>
                     <th><div class="verticalText">Road - V (3000 M)</div></th>

                 <th><div class="verticalText">Point to Point - Road (10000 M)</div></th>
              <th><div class="verticalText">Elimination - Road (15000 M)</div></th>

    <th><div class="verticalText">Relay (3000M)</div></th>
              <th><div class="verticalText">Mixed Relay (4000M)</div></th>
	
               ';
                
                  
			}
             
                if($stype=="Artistic" )
			{
                echo '<th><div class="verticalText">Figure</div></th>
                <th><div class="verticalText">Free</div></th>
            
                <th><div class="verticalText">Pair</div></th>
				<th><div class="verticalText">Partner Name</div></th>
                              <th><div class="verticalText">Solodance</div></th>
                <th><div class="verticalText">Coupledance</div></th>
				<th><div class="verticalText">Partner Name</div></th>
				  <th><div class="verticalText">Inlinefree</div></th>
				  <th><div class="verticalText">Quartet</div></th>
                       <th><div class="verticalText">ShowGroup</div></th> 
                           	  <th><div class="verticalText">Precision</div></th>';
                              
			}
              
                if($stype=="Roller-Hockey" || $stype=="Inline-Hockey")
			{
               
             echo ' <th><div class="verticalText">Roller Hockey</div></th>
           <th><div class="verticalText">Inline Hockey</div></th> ';
                 echo ' <th><div class="verticalText">Position</div></th> <th><div class="verticalText">Jersey No.</div></th> ';
                   
			}
               
                if($stype=="Inline-Freestyle")
			{
               echo '<th><div class="verticalText">Classic Slalom</div></th>
                <th><div class="verticalText">Speed Slalom</div></th>
                 <th><div class="verticalText">Pair Slalom</div></th> ';
                
			}
			 if($stype=="Other")
			{
               echo '<th><div class="verticalText">Main Discipline</div></th> ';
                 echo '<th><div class="verticalText">Other Discipline</div></th> ';
				 
				  echo '<th><div class="verticalText">Alpine</div></th> ';
				   echo '<th><div class="verticalText">Downhill</div></th> ';
				    echo '<th><div class="verticalText">Roller Derby</div></th> ';
					 echo '<th><div class="verticalText">Roller Freestyle</div></th> ';
					  echo '<th><div class="verticalText">Skateboarding</div></th> ';
					   echo '<th><div class="verticalText">Scooter</div></th> ';
				
						  	//  echo '<th><div class="verticalText">ShowGroup</div></th> ';
					  
			}
			
            
                     echo '    <th><div class="verticalText">Comments</div></th> ';
                    // echo '    <th><div class="verticalText">Remarks</div></th> '
                     ;
                
           
               echo '  </tr></thead> ';

//  id="example"  class="display"
$twocol=0;	
$itcount=0;
$curag="";
$curgender="";
$curteam="";

$rink1cnt=0;
$rink2cnt=0;
$road1cnt=0;
$road2cnt=0;
$quadskaterscnt=0;

$rink3cnt=0;
$rink4cnt=0;
$rink5cnt=0;
$rink6cnt=0;
$rink7cnt=0;

$road3cnt=0;
$road4cnt=0;
$road5cnt=0;
$p2pcnt=0;
$rinkelimcnt=0;
$p2prdcnt=0;

$roadelimcnt=0;
$relaycnt=0;
$mixedrelaycnt=0;
$inlineskaterscnt=0;

$rollerhockeycnt=0;
$inlinehockeycnt=0;





	echo '<tbody>';
	
	$slno=0;
	
	while($row = mysqli_fetch_array($result3))
  {
	   $status=trim($row["status"]);
	   
	   $slno=$slno+1;
 $appno=trim($row["appno"]);
$sname=trim($row["sname"]);
$hashcode=trim($row["hashcode"]);

$discipline=trim($row["skatertype"]);
$otherdiscipline=trim($row["otherdiscipline"]);

if($otherdiscipline=='on')
{
	$otherdiscipline="Yes";
}

if($discipline=="Speed-Quad")
{
	$quadskaterscnt++;
}

if($discipline=="Speed-Inline")
{
	$inlineskaterscnt++;
}



$skaterid=trim($row["skaterid"]);
$chno=trim($row["chno"]);

$dob=trim($row["dob"]);
$age=trim($row["age"]);
$ag=trim($row["agegroup"]);


if($discipline=="Roller-Hockey")
{
	if($ag=="7 to 9 - Cadet" || $ag=="9 to 11 - Cadet" )
	{
		$ag="7 to 11 - Cadet";
	}

	$rollerhockeycnt++;
}
if($discipline=="Inline-Hockey")
{
	if($ag=="7 to 9 - Cadet" || $ag=="9 to 11 - Cadet" )
	{
		$ag="7 to 11 - Cadet";
	}
	$inlinehockeycnt++;
}


$gender=trim($row["gender"]);
$club=trim($row["club"]);
$clubname=trim($row["clubname"]);


$school=trim($row["school"]);



$residingstate=trim($row["residingstate"]);
$residingdistrict=trim($row["residingdistrict"]);
$repstate=trim($row["repstate"]);
$repdistrict=trim($row["repdistrict"]);

$fathername=trim($row["fathername"]);

$address=trim($row["address"]);
$address2=trim($row["address2"]);
$city=trim($row["city"]);
$pin=trim($row["pin"]);
$phone=trim($row["phone"]);
$email=trim($row["email"]);
$blood=trim($row["bloodgroup"]);
$comments=trim($row["comments"]);


$payref=trim($row["payref"]);

$paystatus=trim($row["paystatus"]);


//$photourl=trim($row["photourl"]);
$nodob="";
$doburl=trim($row["doburl"]);
if($doburl=='NA')
{
$nodob="true";
}

$pwd=trim($row["aadhaarpass"]);


$position=trim($row["hockeyplayertype"]);

$jerseyno=trim($row["jerseyno"]);


	


$adjrink1=trim($row["adjrink1"]);if($adjrink1=="P"){$adjrink1="P";}else{$adjrink1="-";}
$adjrink2=trim($row["adjrink2"]);if($adjrink2=="P"){$adjrink2="P";}else{$adjrink2="-";}
$adjrink3=trim($row["adjrink3"]);if($adjrink3=="P"){$adjrink3="P";}else{$adjrink3="-";}

$u8race1q=trim($row["u8race1q"]);if($u8race1q=="P"){$u8race1q="P";}else{$u8race1q="-";}
$u8race2q=trim($row["u8race2q"]);if($u8race2q=="P"){$u8race2q="P";}else{$u8race2q="-";}
$u8race1i=trim($row["u8race1i"]);if($u8race1i=="P"){$u8race1i="P";}else{$u8race1i="-";}
$u8race2i=trim($row["u8race2i"]);if($u8race2i=="P"){$u8race2i="P";}else{$u8race2i="-";}

$rink1=trim($row["rink1"]);if($rink1=="P"){$rink1="P";if($status!="Delete"){$rink1cnt++;}}else{$rink1="-";}
$rink2=trim($row["rink2"]);if($rink2=="P"){$rink2="P";if($status!="Delete"){$rink2cnt++;}}else{$rink2="-";}
$rink3=trim($row["rink3"]);if($rink3=="P"){$rink3="P";if($status!="Delete"){$rink3cnt++;}}else{$rink3="-";}
$road1=trim($row["road1"]);if($road1=="P"){$road1="P";if($status!="Delete"){$road1cnt++;}}else{$road1="-";}

$rink4=trim($row["rink4"]);if($rink4=="P"){$rink4="P";if($status!="Delete"){$rink4cnt++;}}else{$rink4="-";}
$rink5=trim($row["rink5"]);if($rink5=="P"){$rink5="P";if($status!="Delete"){$rink5cnt++;}}else{$rink5="-";}
$rink6=trim($row["rink6"]);if($rink6=="P"){$rink6="P";if($status!="Delete"){$rink6cnt++;}}else{$rink6="-";}
$rink7=trim($row["rink7"]);if($rink7=="P"){$rink7="P";if($status!="Delete"){$rink7cnt++;}}else{$rink7="-";}

$road2=trim($row["road2"]);if($road2=="P"){$road2="P";if($status!="Delete"){$road2cnt++;}}else{$road2="-";}

$road3=trim($row["road3"]);if($road3=="P"){$road3="P";if($status!="Delete"){$road3cnt++;}}else{$road3="-";}

$road4=trim($row["road4"]);if($road4=="P"){$road4="P";if($status!="Delete"){$road4cnt++;}}else{$road4="-";}

$road5=trim($row["road5"]);if($road5=="P"){$road5="P";if($status!="Delete"){$road5cnt++;}}else{$road5="-";}

$p2p=trim($row["p2p"]);if($p2p=="P"){$p2p="P";if($status!="Delete"){$p2pcnt++;}}else{$p2p="-";}

$elim=trim($row["elim"]);if($elim=="P"){$elim="P";if($status!="Delete"){$elimcnt++;}}else{$elim="-";}


$p2prd=trim($row["p2prd"]);if($p2prd=="P"){$p2prd="P";if($status!="Delete"){$p2prdcnt++;}}else{$p2prd="-";}

$elimrd=trim($row["elimrd"]);if($elimrd=="P"){$elimrd="P";if($status!="Delete"){$elimrdcnt++;}}else{$elimrd="-";}

$relay=trim($row["relay"]);if($relay=="P"){$relay="P";if($status!="Delete"){$relaycnt++;}}else{$relay="-";}

$mixedrelay=trim($row["mixedrelay"]);if($mixedrelay=="P"){$mixedrelay="P";if($status!="Delete"){$mixedrelaycnt++;}}else{$mixedrelay="-";}

$figure=trim($row["figure"]);if($figure=="P"){$figure="P";}else{$figure="-";}
$free=trim($row["free"]);if($free=="P"){$free="P";}else{$free="-";}
$combined=trim($row["combined"]);if($combined=="P"){$combined="P";}else{$combined="-";}
$pair=trim($row["pair"]);if($pair=="P"){$pair="P";}else{$pair="-";}
$pairpartnername=trim($row["pairpartnername"]);
$pairpartnerag=trim($row["pairpartnerag"]);

$inlinefree=trim($row["inlinefree"]);if($inlinefree=="P"){$inlinefree="P";}else{$inlinefree="-";}
$solodance=trim($row["solodance"]);if($solodance=="P"){$solodance="P";}else{$solodance="-";}
$pairdance=trim($row["pairdance"]);if($pairdance=="P"){$pairdance="P";}else{$pairdance="-";}

$quartet=trim($row["quartet"]);if($quartet=="P"){$quartet="P";}else{$quartet="-";}

$coupledancepartnername=trim($row["coupledancepartnername"]);
$coupledancepartnerag=trim($row["coupledancepartnerag"]);

$quadhockey=trim($row["quadhockey"]);if($quadhockey=="P"){$quadhockey="P";}else{$quadhockey="-";}
$inlinehockey=trim($row["inlinehockey"]);if($inlinehockey=="P"){$inlinehockey="P";}else{$inlinehockey="-";}

$classicslalom=trim($row["classicslalom"]);if($classicslalom=="P"){$classicslalom="P";}else{$classicslalom="-";}
$speedslalom=trim($row["speedslalom"]);if($speedslalom=="P"){$speedslalom="P";}else{$speedslalom="-";}
$pairslalom=trim($row["pairslalom"]);if($pairslalom=="P"){$pairslalom="P";}else{$pairslalom="-";}

$alpine=trim($row["alpine"]);if($alpine=="P"){$alpine="P";}else{$alpine="-";}
$downhill=trim($row["downhill"]);if($downhill=="P"){$downhill="P";}else{$downhill="-";}
$rollerderby=trim($row["rollerderby"]);if($rollerderby=="P"){$rollerderby="P";}else{$rollerderby="-";}
$rollerfreestyle=trim($row["rollerfreestyle"]);if($rollerfreestyle=="P"){$rollerfreestyle="P";}else{$rollerfreestyle="-";}
$skateboarding=trim($row["skateboarding"]);if($skateboarding=="P"){$skateboarding="P";}else{$skateboarding="-";}
$precision=trim($row["precisionskating"]);if($precision=="P"){$precision="P";}else{$precision="-";}
$showgroup=trim($row["showgroup"]);if($showgroup=="P"){$showgroup="P";}else{$showgroup="-";}
$scooter=trim($row["scooter"]);if($scooter=="P"){$scooter="P";}else{$scooter="-";}

$bgc="";
if($status=="Approved by state")
{
	$bgc="Lime";
	}

	if($status=="Rejected")
{
	$bgc="grey";
	}

	if($status=="Verified By Dt")
{
	$bgc="LightGreen";
	}
	if($status=="Pending")
{
	$bgc="Red";
	}
	if($status=="Held")
{
	$bgc="Yellow";
	}
	if($status=="Delete")
{
	$bgc="LightGrey";
	}
	
	if($curag!=$ag ||$curgender!=$gender)
	{

			if($rollerhockeycnt>12)
		{
		echo '<tr style="background-color:red; color:white;"><td colspan=8>Error! More than 12 skaters in a '.$curag.' '.$curgender.' Team. </td></tr>';
		}

			if($inlinehockeycnt>16)
		{
		echo '<tr style="background-color:red; color:white;"><td colspan=8>Error! More than 16 skaters in a '.$curag.' '.$curgender.' Team. </td></tr>';
		}



		/*if($rink1cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in RINK-I</b></td></tr>';
		}
		if($rink2cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in RINK-II</b></td></tr>';
		}
		if($rink3cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in RINK-III</b></td></tr>';
		}
		if($road1cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in ROAD-I</b></td></tr>';
		}
		if($quadskaterscnt>3)
		{
		echo '<tr style="background-color:red; color:white;"><td colspan=8>Error! More than 3 skaters in an Age Group. </td></tr>';
		}
		
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>'.$rink1cnt." ".$rink2cnt." ".$rink3cnt." ".$road1cnt.'</b></td></tr>';
		$rink1cnt=0;
		$rink2cnt=0;
		$rink3cnt=0;
		$road1cnt=0;
		$quadskaterscnt=0;
		
		if($rink4cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in RINK-IV</b></td></tr>';
		}
		if($rink5cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in RINK-V</b></td></tr>';
		}
		if($rink6cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in RINK-VI</b></td></tr>';
		}
		if($p2pcnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in Point to Point</b></td></tr>';
		}
		if($elimcnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in Elimination-Track</b></td></tr>';
		}
		if($road2cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in ROAD-II</b></td></tr>';
		}
		if($road3cnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in ROAD-III</b></td></tr>';
		}
				
		if($roadelimcnt>2)
		{
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! More than 2 skaters in ELIMINATION-ROAD</b></td></tr>';
		}
		
		if($relaycnt!=3 && $relaycnt!=0)
		{
			//echo "Re".$relaycnt;
		echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>Error! There must be 3 skaters in RELAY 1</b></td></tr>';
		}
		
		
		if($inlineskaterscnt>4)
		{
		echo '<tr style="background-color:red; color:white;"><td colspan=8>Error! More than 4 skaters in an Age Group. </td></tr>';
		}
	
		
$rink4cnt=0;
$rink5cnt=0;
$rink6cnt=0;
$p2pcnt=0;
$rinkelimcnt=0;
$road2cnt=0;
$road3cnt=0;
$roadelimcnt=0;
$relaycnt=0;
$inlineskaterscnt=0;
			*/

$rollerhockeycnt=0;
$inlinehockeycnt=0;
		
	echo '<tr style="background-color:#e6ffe6;"><td colspan=8><h5 style="-webkit-margin-after:0.5em !important; -webkit-margin-before:0.67em !important;"><b>'.$ag.' '.$gender.'</b></h5></td></tr>';	
	$curag=trim($ag);
	$curgender=trim($gender);
	$curteam=trim($club);
	}
echo '<tr style="background-color:'.$bgc.'"><td>'.$slno.'</td>';
// if($_SESSION['username']=="secretary")
// {
 if($stype=="Speed-Quad"|| $stype=="Speed-Inline" || $stype=="Tenacity" || $stype=="Under5-Quad" || $stype=="Under5-Inline" )
			{
			echo '<td><b>'.$chno.'</b></td>';
			}
			// }
			

echo '<td>'.$appno.'</td><td id="status'.$appno.'">'.$status.'</td><td>'.$skaterid.'</td><td style=" text-align:left;">'.$sname.'<br/>'.$phone.'<!--<br/>Club: '.$clubname.'--></td><td>'.$dob.'</td><td>'.$age.'</td><td>'.$ag.'</td><td>'.$gender.'</td><td style="white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:100px; width:80%;">'.$club."<!--<br/>Club : ".$clubname.'</td>--><!--<td style="white-space: nowrap; text-overflow:ellipsis; overflow: hidden; max-width:100px; width:100%;">'.$address.'<br/>'.$address2.' '.$city.' '.$pin.'</td> <td class="noprint"><a href="'.$doburl.'" target="_blank" data-role="button" class="noprint ui-btn ui-btn-inline ui-mini ui-btn-raised">View Doc.</a></td><td class="noprint">'.$pwd.'</td>--><!--<td class="noprint"><a href="#" onclick="approveapp('.$appno.');"  data-rel="popup" data-position-to="window" data-role="button" class="ui-btn ui-btn-inline ui-mini ui-btn-raised clr-warning">APPROVE</a></td><td class="noprint"><a href="#" onclick="rejectapp('.$appno.');"  data-rel="popup" data-position-to="window" data-role="button" class="ui-btn ui-btn-inline ui-mini ui-btn-raised color-red">REJECT</a></td>-->';

if($_SESSION['username']=="secretary" || $_SESSION['usertype']=="District" || $_SESSION['usertype']=="Club")
//if($_SESSION['username']=="secretary" )
{
echo '<td class="noprint"><a href="#" onclick="editapp('.$appno.');"  data-rel="popup" data-position-to="window" data-role="button" class="ui-btn ui-btn-inline ui-mini ui-btn-raised">Edit</a></td>';
}

echo '<!--<td class="noprint"><a data-role="button" class="ui-btn ui-btn-inline ui-mini ui-btn-raised"  href="application.php?appno='.$appno.'&k='.urlencode($hashcode).'" target="_blank" >Print</a></td>--><td class="noprint"><a href="#" onclick="deleteapp('.$appno.');"  data-rel="popup" data-position-to="window" data-role="button" class="ui-btn ui-btn-inline ui-mini ui-btn-raised color-red">Delete</a></td>';



                if($stype=="Tenacity" || $stype=="all" )
			{
                echo '<td>'.$adjrink1.'</td><td>'.$adjrink2.'</td><!--<td>'.$adjrink3.'</td> -->';
			}
			    if($stype=="Under5-Quad" || $stype=="all" )
			{
                echo '<td>'.$u8race1q.'</td><td>'.$u8race2q.'</td>';
			}
			    if($stype=="Under5-Inline" || $stype=="all" )
			{
                echo '<td>'.$u8race1i.'</td><td>'.$u8race2i.'</td>';
			}
			if($stype=="Speed-Quad" || $stype=="all" )
			{
                echo '<td>'.$rink1.'</td><td>'.$rink2.'</td><td>'.$rink3.'</td><td>'.$road1.'</td><td>'.$road2.'</td>';
			}
			if($stype=="Speed-Inline" || $stype=="all" )
			{
                echo '<td style="border-left:1px solid black !important;">'.$rink4.'</td><td>'.$rink5.'</td><td>'.$rink6.'</td><td>'.$rink7.'</td><td>'.$p2p.'</td><td>'.$elim.'</td><td>'.$road3.'</td><td>'.$road4.'</td><td>'.$road5.'</td><td>'.$p2prd.'</td><td>'.$elimrd.'</td><td>'.$relay.'</td><td>'.$mixedrelay.'</td>';


			}
			if($stype=="Artistic")
			{
			echo '<td>'.$figure.'</td><td>'.$free.'</td><!--<td>'.$combined.'</td>--><td>'.$pair.'</td><td>'.$pairpartnername.'<br/>'.$pairpartnerag.'</td><td>'.$solodance.'</td><td>'.$pairdance.'</td><td>'.$coupledancepartnername.'<br/>'.$coupledancepartnerag.'</td><td>'.$inlinefree.'</td><td>'.$quartet.'</td><td>'.$showskating.'</td><td>'.$precision.'</td>';
			}
			if($stype=="Roller-Hockey" ||$stype=="Inline-Hockey"   )
			{
				echo '<td>'.$quadhockey.'</td><td>'.$inlinehockey.'</td>';
			echo '<td>'.$position.'</td><td>'.$jerseyno.'</td>';
			}
			if($stype=="Inline-Freestyle" )
			{
				echo '<td>'.$classicslalom.'</td><td>'.$speedslalom.'</td><td>'.$pairslalom.'</td>';
			}
			//href="#myPopup"
			
			if($stype=="Other")
			{
				echo '<td>'.$discipline.'</td>';
				echo '<td>'.$otherdiscipline.'</td>';
				
				echo '<td>'.$alpine.'</td>';
				echo '<td>'.$downhill.'</td>';
				echo '<td>'.$rollerderby.'</td>';
				echo '<td>'.$rollerfreestyle.'</td>';
				echo '<td>'.$skateboarding.'</td>';
				echo '<td>'.$scooter.'</td>';
				;
			//	echo '<td>'.$showgroup.'</td>';
			}
			
			echo '<td> '.$comments.' </td><!--<td>'.$paystatus.'<br/>'.$payref.'</td><td class="noprint"></td>--></tr>';
			


  }

		//echo '<tr style="background-color:red !important; color:white;"><td colspan=8><b>'.$rink1cnt." ".$rink2cnt." ".$rink3cnt." ".$road1cnt.'</b></td></tr>';
$rink1cnt=0;
$rink2cnt=0;
$road1cnt=0;
$road2cnt=0;
$quadskaterscnt=0;

		
$rink3cnt=0;
$rink4cnt=0;

$road3cnt=0;
$road4cnt=0;
$road5cnt=0;
$p2pcnt=0;
$rinkelimcnt=0;
$p2prdcnt=0;

$roadelimcnt=0;
$relaycnt=0;
$mixedrelaycnt=0;
$inlineskaterscnt=0;

$rollerhockeycnt=0;
$inlinehockeycnt=0;



echo '</tbody>';  
 
echo "</table>";
			
}

 ?>