PHP - Sorting tables/ table filtering using jquery

Hi Guys,

I am using the free code of tablefilter.free.fr and have adding this to my code but it does not get executed.

I have added the html and javascript into https://jsfiddle.net/koalyptus/eCqG3/ and it works fine but when i use my page -> http://mr-tipster.com/pages/newcard.php?venue=Southwell it does not render for some reason although the same html is output.

below is the full code i use on the page to create the tables and add the javascript.

        
    
    <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript"  src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <script type="text/javascript" src="../table/tablefilter.js"></script>
    
    <?php
  
    //show today's meeting names
    $venue               = $_GET['venue'];
    $time                = $_GET['time'];
    $totalyardstofurlong = "";
    $totalmailetofurlong = "";
    $totalfurlong        = "";
    $numbers             = 0;
    $grabtrack           = mysqli_query($db, 'SELECT Track, COUNT(*) c FROM tom_cards where Track IN ("Kempton (AW)","Chelmsford (AW)","Wolverhampton (AW)","Lingfield (AW)","Doncaster","Ascot","Southwell (AW)","Haydock","Newbury","Newcastle","Ayr","Newmarket (July)","York","Chepstow","Leicester","Windsor","Catterick","Sandown","Uttoxeter","Worcester","Nottingham","Newmarket","Goodwood","Musselburgh","Carlisle","Redcar","Beverley","Yarmouth","Brighton","Cheltenham","Thirsk","Ffos las","Bath","Stratford","Newton abbot","Hamilton","Market rasen","Ripon","Warwick","Fontwell","Pontefract","Chester","Southwell","Salisbury","Wetherby","Lingfield","Sedgefield","Wincanton","Exeter","Perth","Huntingdon","Towcester","Hexham","Ludlow","Plumpton","Aintree","Kelso","Taunton","Epsom","Bangor-on-dee","Kempton","Cartmel","Fakenham") GROUP BY Racetime HAVING c > 1;');
    $meeting             = array();
    
    echo "<div style='text-align: center ;margin:auto;'>";
    while ($grabtodaystrack = mysqli_fetch_array($grabtrack)) {
        $meeting[] = $grabtodaystrack['Track'];
    }
    foreach (array_unique($meeting) as $entry) {
        $sql222       = "SELECT Track FROM  `tom_cards` WHERE  `Track` = '" . $entry . "' and `Race_Name` LIKE  '%hurdal%' OR `Track` = '" . $entry . "' and  `Race_Name` LIKE  '%chase%'";
        $grabracetype = mysqli_query($db, $sql222);
        $numrows      = $grabracetype->num_rows;
        if ($numrows > 0) {
            echo '<a href="http://mr-tipster.com/pages/newcard.php?venue=' . urlencode($entry) . '" class="button green">' . $entry . '</a>';
        } else {
            echo '<a href="http://mr-tipster.com/pages/newcard.php?venue=' . urlencode($entry) . '" class="button jump">' . $entry . '</a>';
        }
        $met1 = array_values($meeting);
        /*
        if (array_shift($met1) == $entry && $venue ==""  || $venue == $entry)
        {
        echo '<a href="http://mr-tipster.com/pages/newcard.php?venue='.urlencode($entry).'" class="button green">'.$entry.'</a>';
        if ($venue =="")
        {
        $venue = array_shift($met1);
        }
        }
        else
        {
        
        
        echo '<a href="http://mr-tipster.com/pages/newcard.php?venue='.urlencode($entry).'" class="button jump">'.$entry.'</a>';  
        }
        */
    }
    // pull the times for that meeting
    $grabtracktimes = mysqli_query($db, 'SELECT Racetime,Going,distance, COUNT(*) c FROM tom_cards Where Track = "' . $venue . '" GROUP BY Racetime HAVING c > 1;');
    $meetingtime    = array();
    echo "<br />";
    while ($grabtodaystracktimes = mysqli_fetch_array($grabtracktimes)) {
        $meetingtime[] = $grabtodaystracktimes['Racetime'];
    }
    $meetingtime1 = array_unique($meetingtime);
    foreach ($meetingtime1 as $entrytime) {
        if ($time == "") {
            $time = array_shift(array_values($meetingtime1));
        }
        if (array_shift($meetingtime1) == $entrytime and $time == "" or $time == $entrytime) {
            echo '<a href="http://mr-tipster.com/pages/newcard.php?venue=' . urlencode($venue) . '&amp;time=' . $entrytime . '" class="button green medium">' . $entrytime . '</a>';
            if ($time == "") {
                $time = array_shift($meetingtime1);
            }
        } else {
            echo '<a href="http://mr-tipster.com/pages/newcard.php?venue=' . urlencode($venue) . '&amp;time=' . $entrytime . '" class="button white medium">' . $entrytime . '</a>';
        }
    }
    echo "<br /><b>" . $venue . "(" . $time . ")</b>";
    
    
      $sqltodaystrack  = "SELECT Left_or_Right,speed,surface FROM  `RaceCourse`  WHERE  `Course` = '" . $venue . "'";;
         $sqltodaystrack2  = mysqli_query($db,  $sqltodaystrack );
    $todaystrackleftorright = "";
    $todaystrackspeed = "";
    $todaystracksurface = "";
        while ( $sqltodaystrack3 = mysqli_fetch_array($sqltodaystrack2)) {
    	
    	$todaystrackleftorright = $sqltodaystrack3['Left_or_Right'];
    	$todaystrackspeed = $sqltodaystrack3['speed'];
    	$todaystracksurface = $sqltodaystrack3['surface'];
    	}
    
    
    
    
    
    
    
    
    $sql     = 'SELECT Race_Name,distance,going,surface FROM tom_cards Where Track ="' . $venue . '" and Racetime = "' . $time . '" group by Racetime  ';
    $horses2 = mysqli_query($db, $sql);
    $first   = true;
    while ($todayhorse = mysqli_fetch_array($horses2)) {
        if ($first == true) {
            // do something
            $first          = false;
            $todaysgoing    = $todayhorse['going'];
            $todaysdistance = miletofurlong($todayhorse['distance']);
            echo "<br /><br /><b>" . $todayhorse['Race_Name'] . "</b>";
    		//add notes about the race course here
    $sqlfortrack     = 'SELECT notes,Handicaps, Non_Handicaps FROM RaceCourse Where Course ="' . $venue . '"';
    $fortrack = mysqli_query($db, $sqlfortrack  );
    
    while ($fortrack2 = mysqli_fetch_array($fortrack)) {
    
    echo "<br /><span style='font-size:11px'><b>Course Notes:</b> ".$fortrack2['notes']."</span><BR />";
    //check if handicap or not and check for any course details
    
    if (strpos($todayhorse['Race_Name'], 'Handicap') !== FALSE)
    {
    echo "<span style='font-size:11px'>".$fortrack2['Handicaps']."<span/>";
    }
    else
    {
    echo "<span style='font-size:11px'>".$fortrack2['Non_Handicaps']."</span>";
    }
    
    
    
    }
            echo " <br /><br />Distance: <b>" . miletofurlong($todayhorse['distance']) . "f </b>(" . $todayhorse['distance'] . ") Going: <b>" . $todayhorse['going'] . "</b>";
            $surface = trim($db->real_escape_string($todayhorse['surface']));
        }
    }
    
    echo "</div>";
    
    echo "<table  id='table1'   style='border:0px;margin-top:50px;text-align: center ;'>";
    echo "<tr style='font-weight: bold;'><td>Horse</td><td>Form</td><td>History</td><td>OR/Class</td><td>MT Rating</td><td>Naps</td></tr>";
    $sql     = 'SELECT horse,rp,ts,Naps,`OR`,Class,Jockeys_Claim,Trainer,Track FROM tom_cards Where Track ="' . $venue . '" and Racetime = "' . $time . '"';
    $horses2 = mysqli_query($db, $sql);
    $loop    = 0;
    while ($todayhorse = mysqli_fetch_array($horses2)) {
        $placed  = "";
        $data    = "";
        $horse   = trim($todayhorse['horse']);
        $jockeys = $todayhorse['Jockeys_Claim'];
        $trainer = $todayhorse['Trainer'];
        $class   = $todayhorse['Class'];
        $or      = $todayhorse['OR'];
        $rp      = $todayhorse['rp'];
        $ts      = $todayhorse['ts'];
        $naps    = $todayhorse['Naps'];
        if ($surface == "Turf") {
            $win          = 0;
            $runs         = 0;
            $place        = 0;
            $horsesplaced = mysqli_query($db, 'SELECT Date,Place FROM horsesrp Where Horse = "' . $horse . '" and Track NOT LIKE "%(AW)%" order by Date DESC Limit 10');
            $check        = "no";
            while ($pasthorse = mysqli_fetch_array($horsesplaced)) {
                $dbDate     = $pasthorse['Date'];
                $placeddata = intval($pasthorse['Place']);
                //add 1 to runs everyloop to show how many runs they have had
                $runs       = $runs + 1;
                //if the horse has won a race then mark it red and add 1 point to the win tally
                if ($placeddata == 1) {
                    $placed .= "<b><span style='color:#8DB600'>" . $pasthorse['Place'] . "</span></b>";
                    $win = $win + 1;
                } else {
                    //if the horse was placed higher then 9th just add 0
                    if (intval($pasthorse['Place']) > 9) {
                        $pasthorse['Place'] = 0;
                    }
                    //echo all the places
                    if ($pasthorse['Place'] == "PU") {
                        $pasthorse['Place'] = str_replace($pasthorse['Place'], 'PU', '<b>P</b>');
                    }
                    if ($pasthorse['Place'] == "F") {
                        $pasthorse['Place'] = str_replace($pasthorse['Place'], 'F', '<b>F</b>');
                    }
                    if ($pasthorse['Place'] == "2" or $pasthorse['Place'] == "3") {
                        $pasthorse['Place'] = str_replace($pasthorse['Place'], $pasthorse['Place'], "<span style='color:#8DB600'>" . $pasthorse['Place'] . "</span>");
                    }
                    $placed .= $pasthorse['Place'];
                    // if runners are greater then 4 and less the 8 only 2 to place
                    if ($pasthorse['Runners'] < 4 and $pasthorse['Runners'] > 8) {
                        if ($pasthorse['Place'] == 2) {
                            $place = $place + 1;
                        }
                    }
                    if ($pasthorse['Runners'] < 7 and $pasthorse['Runners'] > 16) {
                        if ($pasthorse['Place'] == 2 or $pasthorse['Place'] == 3) {
                            $place = $place + 1;
                        }
                    }
                    if ($pasthorse['Runners'] < 15) {
                        if ($pasthorse['Place'] == 2 or $pasthorse['Place'] == 3 or $pasthorse['Place'] == 4) {
                            $place = $place + 1;
                        }
                    }
                }
            }
        } elseif ($surface == "AW") {
            $win          = 0;
            $runs         = 0;
            $place        = 0;
            $horsesplaced = mysqli_query($db, 'SELECT Runners,Place FROM horsesrp Where Horse = "' . $horse . '" and Track LIKE "%(AW)%" order by Date DESC Limit 10');
            while ($pasthorse = mysqli_fetch_array($horsesplaced)) {
                $placeddata = intval($pasthorse['Place']);
                //add 1 to runs everyloop to show how many runs they have had
                $runs       = $runs + 1;
                //if the horse has won a race then mark it red and add 1 point to the win tally
                if ($placeddata == 1) {
                    $placed .= "<b><span style='color:red'>" . $pasthorse['Place'] . "</span></b>";
                    $win = $win + 1;
                } else {
                    //if the horse was placed higher then 9th just add 0
                    if (intval($pasthorse['Place']) > 9) {
                        $pasthorse['Place'] = 0;
                    }
                    //echo all the places
                    $placed .= $pasthorse['Place'];
                    // if runners are greater then 4 and less the 8 only 2 to place
                    if ($pasthorse['Runners'] < 4 and $pasthorse['Runners'] > 8) {
                        if ($pasthorse['Place'] == 2) {
                            $place = $place + 1;
                        }
                    }
                    if ($pasthorse['Runners'] < 7 and $pasthorse['Runners'] > 16) {
                        if ($pasthorse['Place'] == 2 or $pasthorse['Place'] == 3) {
                            $place = $place + 1;
                        }
                    }
                    if ($pasthorse['Runners'] < 15) {
                        if ($pasthorse['Place'] == 2 or $pasthorse['Place'] == 3 or $pasthorse['Place'] == 4) {
                            $place = $place + 1;
                        }
                    }
                }
            }
        }
        $winner  = "";
        $placed1 = "";
        if ($runs != 0) {
            $winner  = "(" . round(($win / $runs) * 100) . "%) ";
            $placed1 = "(" . round((($place + $win) / $runs) * 100) . "%) ";
        }
        $thetrack = horseontrack($horse, $venue, $db);
        list($corseruns, $corsewins, $corseplace) = explode("/", $thetrack);
        $sqlhorses   = "SELECT distance,Place,Runners FROM  `horsesrp`  WHERE  `Horse` = '" . $horse . "' order by distance + 0,
             substring_index(distance, 'm', -1) + 0";
        $horseplaced = mysqli_query($db, $sqlhorses);
        $data        = "";
    	$dataleftorright = "";
    	$dataspeed = ""; 
    		$datasurface = ""; 
        $storage     = array();
    	$storetrackdirection = array();
       $storetrackdirectionsurface= array();
       $storetrackspeed= array();
        while ($pasthorse = mysqli_fetch_array($horseplaced)) {
            // check to see if its distance is that of today
            $placetotals = 0;
            $wintotals   = 0;
            $test        = "";
            $placeddata  = intval($pasthorse['Place']);
            if ($placeddata == 1) {
                $placetotals = 1;
                $wintotals   = 1;
            } else {
                if ($pasthorse['Runners'] > 4 and $pasthorse['Runners'] < 8) {
                    $test = "--between 5 and 7--" . $pasthorse['Place'];
                    if ($pasthorse['Place'] == 2) {
                        $placetotals = 1;
                    }
                }
                if ($pasthorse['Runners'] > 7 and $pasthorse['Runners'] < 16) {
                    $test = "--Between 8 and 15--" . $pasthorse['Place'];
                    if ($pasthorse['Place'] == 2 or $pasthorse['Place'] == 3) {
                        $placetotals = 1;
                    }
                }
                if ($pasthorse['Runners'] > 15) {
                    $test = "over 15" . $pasthorse['Place'];
                    if ($pasthorse['Place'] == 2 or $pasthorse['Place'] == 3 or $pasthorse['Place'] == 4) {
                        $placetotals = 1;
                    }
                }
            }
            // if the distance is the same
            // Take this outside of the if statements
            $mtfl = miletofurlong($pasthorse['distance']);
            if ($mtfl == $todaysdistance) {
                $Horsedist = "<b><span style='color:#ff4500 '>" . $mtfl . "f</span></b>";
            } elseif (($mtfl >= $todaysdistance - 1) && ($mtfl <= $todaysdistance + 1)) {
                // You don't need to check for equality here - if you get here it is because
                // the values are not equal
                $Horsedist = "<b><span style='color:#8DB600'>" . $mtfl . "f</span></b>";
            } else {
                $Horsedist = $mtfl . "f";
            }
            if (!isset($storage[$Horsedist])) {
                $storage[$Horsedist] = array(
                    "win" => 0,
                    "placed" => 0,
                    "raced" => 0
                );
            }
            // Then increment if required
            $storage[$Horsedist]["win"] += $wintotals;
            $storage[$Horsedist]["placed"] += $placetotals;
            $storage[$Horsedist]["raced"] += 1;
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
        }
        $sqlhorsesgoing   = "SELECT going,Place,Runners FROM  `horsesrp`  WHERE  `Horse` = '" . $horse . "' order by going";
        $horseplacedgoing = mysqli_query($db, $sqlhorsesgoing);
        $datagoing        = "";
        $storagegoing     = array();
        while ($pasthorsegoing = mysqli_fetch_array($horseplacedgoing)) {
            // check to see if its going is that of today
            $placetotalsgoing = 0;
            $wintotalsgoing   = 0;
            $placeddatagoing  = intval($pasthorsegoing['Place']);
            if ($placeddatagoing == 1) {
                $placetotalsgoing = 1;
                $wintotalsgoing   = 1;
            } else {
                if ($pasthorsegoing['Runners'] > 4 and $pasthorsegoing['Runners'] < 8) {
                    if ($pasthorsegoing['Place'] == 2) {
                        $placetotalsgoing = 1;
                    }
                }
                if ($pasthorsegoing['Runners'] > 7 and $pasthorsegoing['Runners'] < 16) {
                    if ($pasthorsegoing['Place'] == 2 or $pasthorsegoing['Place'] == 3) {
                        $placetotalsgoing = 1;
                    }
                }
                if ($pasthorsegoing['Runners'] > 15) {
                    if ($pasthorsegoing['Place'] == 2 or $pasthorsegoing['Place'] == 3 or $pasthorsegoing['Place'] == 4) {
                        $placetotalsgoing = 1;
                    }
                }
            }
            // if the going is the same
            // Take this outside of the if statements
            $mtfl1 = $pasthorsegoing['going'];
            if ($mtfl1 == $todaysgoing) {
                $Horsegoing = "<b><span style='color:#ff4500 '>" . $mtfl1 . "</span></b>";
            } else {
                $Horsegoing = $mtfl1;
            }
            if (!isset($storagegoing[$Horsegoing])) {
                $storagegoing[$Horsegoing] = array(
                    "win" => 0,
                    "placed" => 0,
                    "raced" => 0
                );
            }
            // Then increment if required
            $storagegoing[$Horsegoing]["win"] += $wintotalsgoing;
            $storagegoing[$Horsegoing]["placed"] += $placetotalsgoing;
            $storagegoing[$Horsegoing]["raced"] += 1;
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
        }
    	
    
        $data = "<table class='tg' align='center' style='font-size:10.5px;'><tr><th style='padding-right:5px;'></th><th style='padding-right:5px;'> Runs </th><th style='padding-right:5px;'> Wins </th><th style='padding-right:5px;'> Placed </th></tr>";
        foreach ($storage as $pony => $tab) {
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
            if ($tab["win"] !== 0) {
                $distancewinners = "<b><span style='color:#ff4500 '>" . $tab["win"] . "</span></b>";
            } else {
                $distancewinners = $tab["win"];
            }
            if ($tab["placed"] !== 0) {
                $distanceplace = "<b><span style='color:#ff4500 '>" . $tab["placed"] . "</span></b>";
            } else {
                $distanceplace = $tab["placed"];
            }
            $data .= " <tr style='height:18px;' border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $pony . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $distancewinners . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $distanceplace . "</td></tr>";
        }
        $data .= "</table>";
    	
    
        $datagoing = "<table class='tg' align='center' style='font-size:10.5px;'><tr><th style='padding-right:5px;'></th><th style='padding-right:5px;'> Runs </th><th style='padding-right:5px;'> Wins </th><th style='padding-right:5px;'> Placed </th></tr>";
        foreach ($storagegoing as $ponygoing => $tabgoing) {
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
            if ($tabgoing["win"] !== 0) {
                $distancewinners = "<b><span style='color:#ff4500 '>" . $tabgoing["win"] . "</span></b>";
            } else {
                $distancewinners = $tabgoing["win"];
            }
            if ($tabgoing["placed"] !== 0) {
                $distanceplace = "<b><span style='color:#ff4500 '>" . $tabgoing["placed"] . "</span></b>";
            } else {
                $distanceplace = $tabgoing["placed"];
            }
            $datagoing .= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $ponygoing . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tabgoing["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $distancewinners . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $distanceplace . "</td></tr>";
        }
        $datagoing .= "</table>";
    	
    	//work out which courses the horse has ran at
    	
     $horseplacedtracks  = "SELECT track,Place,Runners FROM  `horsesrp`  WHERE  `Horse` = '" . $horse . "'";
       $horseplacedtracks2  = mysqli_query($db, $horseplacedtracks  );
    $track ="";
    $leftorright = "";
    $surface = "";
    $speed = "";
    
     while ($pasthorsetracks  = mysqli_fetch_array($horseplacedtracks2 )) 
     {
     //remove (aw) and get the track name
    $track = trim(str_replace("(AW)", "", $pasthorsetracks['track']));
    //is the track left or right??
    
    
     // check to see if its going is that of today
            $placetotalstrack = 0;
            $wintotalstrack   = 0;
            $placeddatatrack  = intval($pasthorsetracks['Place']);
            if ($placeddatatrack == 1) {
                $placetotalstrack = 1;
                $wintotalstrack   = 1;
            } else {
                if ($pasthorsetracks['Runners'] > 4 and $pasthorsetracks['Runners'] < 8) {
                    if ($pasthorsetracks['Place'] == 2) {
                        $placetotalstrack = 1;
                    }
                }
                if ($pasthorsetracks['Runners'] > 7 and $pasthorsetracks['Runners'] < 16) {
                    if ($pasthorsetracks['Place'] == 2 or $pasthorsetracks['Place'] == 3) {
                        $placetotalstrack = 1;
                    }
                }
                if ($pasthorsetracks['Runners'] > 15) {
                    if ($pasthorsetracks['Place'] == 2 or $pasthorsetracks['Place'] == 3 or $pasthorsetracks['Place'] == 4) {
                        $placetotalstrack = 1;
                    }
                }
            }
    		
    		
    
    // check the track against the database and asign left or right
    $grabtrackdetails  = "SELECT Left_or_Right FROM  `RaceCourse`  WHERE  `Course` = '" . $track . "'";
       $grabtrackdetails2  = mysqli_query($db, $grabtrackdetails );
    while ($pastgrabtrackdetails  = mysqli_fetch_array($grabtrackdetails2 )) 
     {
    $leftorright = $pastgrabtrackdetails['Left_or_Right'];
    /////////////////////////////////////////////////////////////////////////////////////
      if (!isset($storetrackdirection[$leftorright])) {
                $storetrackdirection[$leftorright] = array(
                  "win" => 0,
                    "placed" => 0,
                    "raced" => 0
                );
            }
            // Then increment if required
           $storetrackdirection[$leftorright]["win"] += $wintotalstrack;
        $storetrackdirection[$leftorright]["placed"] += $placetotalstrack;
            $storetrackdirection[$leftorright]["raced"] += 1;
    		 }
    		 
    		 
    		 
    		 
    		 
    		 
    		 // check the track against the database and asign left or right
    $grabtrackdetailssurface  = "SELECT surface FROM  `RaceCourse`  WHERE  `Course` = '" . $track . "'";
       $grabtrackdetailssurface2  = mysqli_query($db, $grabtrackdetailssurface );
    while ($pastgrabtrackdetailssurface  = mysqli_fetch_array($grabtrackdetailssurface2 )) 
     {
    $surface = $pastgrabtrackdetailssurface['surface'];
    
    if ($surface == "")
    {
    $surface = "Mix";
    }
    /////////////////////////////////////////////////////////////////////////////////////
      if (!isset($storetrackdirectionsurface[$surface])) {
                $storetrackdirectionsurface[$surface] = array(
                  "win" => 0,
                    "placed" => 0,
                    "raced" => 0
                );
            }
            // Then increment if required
           $storetrackdirectionsurface[$surface]["win"] += $wintotalstrack;
        $storetrackdirectionsurface[$surface]["placed"] += $placetotalstrack;
            $storetrackdirectionsurface[$surface]["raced"] += 1;
    		 }
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    		 
    	// check the track against the database and asign speed
    $grabspeed  = "SELECT speed FROM  `RaceCourse`  WHERE  `Course` = '" . $track . "'";
       $grabspeed2  = mysqli_query($db, $grabspeed );
       
    
       
    while ($pastgrabspeed  = mysqli_fetch_array($grabspeed2 )) 
     {
    $speed = ucwords($pastgrabspeed['speed']);
    if ($speed  == "")
    {
    $speed  = "Mix";
    }
    //if ($speed !== "")
    //{
    /////////////////////////////////////////////////////////////////////////////////////
      if (!isset($storetrackspeed[$speed ]) ) {
                $storetrackspeed[$speed ] = array(
                  "win" => 0,
                    "placed" => 0,
                    "raced" => 0
                );
            }
            // Then increment if required
           $storetrackspeed[$speed ]["win"] += $wintotalstrack;
        $storetrackspeed[$speed ]["placed"] += $placetotalstrack;
            $storetrackspeed[$speed ]["raced"] += 1;
    		// }	 
    		 
    		 
    		 
    	}
    	}
    	
    	 	if ( count($storetrackdirection) !== 0)
    		{
    	 $dataleftorright .= "<table class='tg' align='center' style='font-size:10.5px;'><tr><th style='padding-right:5px;'></th><th style='padding-right:5px;'> Runs </th><th style='padding-right:5px;'> Wins </th><th style='padding-right:5px;'> Placed </th></tr>";
    ksort($storetrackdirection);
    	foreach ($storetrackdirection as $pony2 => $tab2) {
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
          if($todaystrackleftorright == $pony2 )
    	  {
          $dataleftorright.= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'><b><span style='color:#ff4500 '>" . $pony2 . "</b></span></td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["win"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["placed"]  . "</td></tr>";
    }  
    else{
     $dataleftorright.= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $pony2 . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["win"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["placed"]  . "</td></tr>";
    
    }
      }
    		 $dataleftorright .= "</table>";
    		 }
    		 else
    		 {
    		 $dataleftorright = "Not enough data!";
    		 }
    		 
    		 
    		 	if ( count($storetrackdirectionsurface) !== 0)
    		{
    		 
    		 	$datasurface .= "<table class='tg' align='center' style='font-size:10.5px;'><tr><th style='padding-right:5px;'></th><th style='padding-right:5px;'> Runs </th><th style='padding-right:5px;'> Wins </th><th style='padding-right:5px;'> Placed </th></tr>";
    ksort($storetrackdirectionsurface);
    	foreach ($storetrackdirectionsurface as $pony2 => $tab2) {
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
          if($todaystracksurface == $pony2 )
    	  {
          $datasurface.= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'><b><span style='color:#ff4500 '>" . $pony2 . "</b></span></td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["win"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["placed"]  . "</td></tr>";
    }  
    else{
     $datasurface.= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $pony2 . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["win"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["placed"]  . "</td></tr>";
    
    }
      }
    		 $datasurface .= "</table>";
    		 
    		 }
    		 
    		 
    		 
    		if ( count($storetrackspeed) !== 0)
    		{
    		 
    		  $dataspeed .= "<table class='tg' align='center' style='font-size:10.5px;'><tr><th style='padding-right:5px;'></th><th style='padding-right:5px;'> Runs </th><th style='padding-right:5px;'> Wins </th><th style='padding-right:5px;'> Placed </th></tr>";
    ksort($storetrackspeed);
    	foreach ($storetrackspeed as $pony2 => $tab2) {
            // $data .= "<span style='font-size:10.5px'>".$Horsedist. " -Won:".$wintotals. " Placed:".$placetotals."  </span><br />";
        if($todaystrackspeed  == $pony2 )
    	  {
           $dataspeed.= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'><b><span style='color:#ff4500 '>" . $pony2 . "</b></span></td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["win"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["placed"]  . "</td></tr>";
    }  
    else{
       $dataspeed.= " <tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" .$todaystrackspeed . $pony2 . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["raced"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["win"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $tab2["placed"]  . "</td></tr>";
    
    }
    
      }
    		 $dataspeed .= "</table>";
    }
    	
    	
    	 $horsehistory  = "SELECT Date,track,Class,Distance,going,Place,Jockeys_claim,`OR`,Runners FROM  `horsesrp`  WHERE  `Horse` = '" . $horse . "' order by Date DESC";
       $horsehistory2  = mysqli_query($db, $horsehistory  );
    $horseshistoryget = "<br />";
    
    ?>
    <script type="text/javascript">
    var tf<?php echo $loop; ?> = setFilterGrid("loop<?php echo $loop; ?>");
    </script>
    <?
    
    $horseshistoryget .= "<table id='loop".$loop."' class='mytable'  align='center' style='font-size:10.5px;'><tr><th style='padding-right:5px;'></th><th style='padding-right:5px;'> Course </th><th style='padding-right:5px;'> Class</th><th style='padding-right:5px;'> Distance </th><th style='padding-right:5px;'> Going</th><th style='padding-right:5px;'> Outcome </th><th style='padding-right:5px;'> Jockey </th><th style='padding-right:5px;'> OR </th></tr>";
    
     while ($gethorsehistory  = mysqli_fetch_array($horsehistory2 )) 
     {
    	
    	//$horseshistoryget .= "<tr style='height:18px;   border-top:1pt solid black;  border-bottom:0pt solid black;'><td  style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" .$gethorsehistory["Date"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $gethorsehistory["Track"] . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $gethorsehistory["Class"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $gethorsehistory["Distance"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $gethorsehistory["Place"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $gethorsehistory["Jockeys_claim"]  . "</td><td style='border-top:1pt solid black;  border-bottom:0pt solid black;'>" . $gethorsehistory["`OR`"]  . "</td></tr>";
    $timestamp = strtotime($gethorsehistory["Date"]);
     $newDate = date('d.m.y', $timestamp); 
    
     // check if the value is the same as today and bold it
     
    
    	
    $horseshistoryget .= "<tr><td>". $newDate. "</td>";
    
    
    
    //check what todays course speed and surface is like
    $todayscourseprofile = "SELECT speed,surface from RaceCourse where course = '".$venue."'    ";
      $todayscourseprofile2  = mysqli_query($db, $todayscourseprofile  );
       $todayscoursespeed = "" ;
     $todayscoursesurface = "";
     while ($gettodayscourseprofile  = mysqli_fetch_array($todayscourseprofile2 )) 
     {
     $todayscoursespeed = $gettodayscourseprofile["speed"] ;
     $todayscoursesurface = $gettodayscourseprofile ["surface"];
     }
    
    //check if venue has the same profile as this one 
    $trackprofie = trim(str_replace("(AW)", "", $gethorsehistory["track"]));
     $allcourseprofile = "SELECT speed, surface from RaceCourse where course = '".$trackprofie."' ";
    
      $allcourseprofile2  = mysqli_query($db, $allcourseprofile  );
     
     while ($getallcourseprofile  = mysqli_fetch_array($allcourseprofile2 )) 
     {
       $allcoursespeed = "" ;
     $allcoursesurface = "";
     $allcoursespeed = $getallcourseprofile["speed"] ;
     $allcoursesurface = $getallcourseprofile ["surface"];
     } 
     //if they match colour them
     
    
     if($todayscoursespeed ==  $allcoursespeed and  $allcoursesurface == $todayscoursesurface  )
     {
     if ($todayscoursespeed <> "" and $todayscoursesurface <> "")
     {
      $showtrack = "<span style='color:#336600 '>".$gethorsehistory["track"]."</span>";
      }
      else
      {
       $showtrack = $gethorsehistory["track"];
      }
     }
     elseif ($todayscoursespeed ==  $allcoursespeed)
     {
     
     if ($todayscoursespeed <> "")
     {
     $showtrack = "<span style='color:#996600 '>".$gethorsehistory["track"]."</span>";
      }
      else
      {
       $showtrack = $gethorsehistory["track"];
      }
     }
     elseif($todayscoursesurface ==  $allcoursesurface)
     {
      if ($todayscoursesurface <> "")
     {
     $showtrack = "<span style='color:#CC3300 '>".$gethorsehistory["track"]."</span>";
      }
      else
      {
       $showtrack = $gethorsehistory["track"];
      }
     
     }
     else
     
     {
     $showtrack = $gethorsehistory["track"];
     }
      
    
    
     
     if ($gethorsehistory["track"] == $venue)
    {
    $horseshistoryget .= "<td><b>" .  $showtrack.  "</b></td>";
    }
    else{
    $horseshistoryget .= "<td>" .  $showtrack."</td>";
    }
    
    
    
    
    
    if ($gethorsehistory["Class"] == "Class".$class)
    {
    $horseshistoryget .= "<td><b>" . $gethorsehistory["Class"] . "</b></td>";
    }
    else
    {
    $horseshistoryget .= "<td>" . $gethorsehistory["Class"] .  "</td>";
    }
    
    
    
    if (miletofurlong($gethorsehistory["Distance"]) ==  $todaysdistance)
    {
    $horseshistoryget .= "<td><b>" . miletofurlong($gethorsehistory["Distance"]). "f" . "</b></td>";
    }
    else
    {
    $horseshistoryget .= "<td>" . miletofurlong($gethorsehistory["Distance"]). "f" . "</td>";
    }
    
    if ($gethorsehistory["going"]  ==  $todaysgoing)
    {
    $horseshistoryget .= "<td><b>" . $gethorsehistory["going"] .  "</b></td>";
    }
    else{
    $horseshistoryget .= "<td>" .$gethorsehistory["going"] . "</td>";
    }
    
    if ($gethorsehistory["Place"] == 1){
    $pastplace = "<b><span style='color:#ff4500 '>".$gethorsehistory["Place"]."</span></b>";
    }
    else{
    $pastplace = $gethorsehistory["Place"];
    }
    $horseshistoryget .= "<td>" . $pastplace ."/". $gethorsehistory["Runners"].  "</td>";
    
    
    
    if ($gethorsehistory["Jockeys_claim"] ==  $jockeys)
    {
    $horseshistoryget .= "<td><b>" .$gethorsehistory["Jockeys_claim"].  "</b></td>";
    }
    else{
    $horseshistoryget .= "<td>" . $gethorsehistory["Jockeys_claim"] .  "</td>";
    }
    
    $horseshistoryget .= "<td>" .$t1. $gethorsehistory["OR"]  .$t2. "</td></tr>";
    
    	
    	}
    
    
    $horseshistoryget .= "</table><br />";
    	
        //does the jockey only have one ride today???
        echo "<tr valign='top'><td  >";
        echo "<b><span style='font-size:12px'> " . $horse . "</span></b> <sup><span style='font-size:10px;color:gray'><abbr title='Days Since Last Race'>" . horselastrace($horse, $db) . "</abbr> </span><b><span style='font-size:10px;color:red'><abbr title='Beaten Favourite'>" . horsebeatenfav($horse, $db) . "</abbr></span></sup></b>
    <br /><span style='font-size:10.5px'><abbr title='Jockey'>J: " . $jockeys . "</abbr><abbr title='Jockey Win rate last 4 months'> (" . round(howhotisjockey($jockeys, $db)) . "%)</abbr> " . " <abbr title='Jockey Win rate on horse'>(" . round(howhotisjockeyonhorse($jockeys, $db, $horse)) . "%)</abbr><abbr title='Jockey rides today'> " . jockeyridestoday($jockeys, $db) . "</abbr>
    <br /><abbr title='Trainer'> T: " . $trainer . "</abbr> <abbr title='Trainer Win rate last 4 months'>(" . round(howhotistrainer($trainer, $db)) . "%)</abbr> <abbr title='Trainers horses out today'>  " . trainersridestoday($trainer, $db) . "</abbr> </span></td>";
        echo "<td ><span style='font-size:11px'><abbr title='P = Pulled Up , F = Fell'> " . $placed . "</abbr></span> <span style='font-size:10.5px'> <abbr title='Win Percent'> " . $winner . "</abbr> <abbr title='Place Percent'>" . $placed1 . "</abbr></span>  </td>";
      //  echo "<td ><span style='font-size:11px'>".$dataleftorright.$dataspeed.$datasurface."</span></td>";
       // echo "<td >" . $data . "<br /></td>";
      //  echo "<td >" . $datagoing . "<br /></td>";
    echo "<td >".$horseshistoryget."</td>";
    
        echo "<td ><span style='font-size:11px'><abbr title='class and highest winning OR'> " . classtop2($horse, $db, $or, $class) . "</abbr></span> </td>";
        echo "<td ><span style='font-size:11px'><abbr title='Mr-Tipster speed rating'> " . round((($rp + $ts) / 2)) . "</abbr> </span></td>";
        echo "<td ><span style='font-size:11px'>" . $naps . "</span></td>";
        echo "</tr>";
        $loop = $loop + 1;
    }
    ?>
           </table>    
        </div>
                    </body>
            
                    </html>
       

Open in new window

runnerjp2005Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
There are 789 lines of code here, and we don't have your database, so we can't make any tests.  Is it possible to reduce this to something closer to the SSCCE?  Maybe you could use Chrome dev tools to help isolate the issue and show us where to start looking?
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Julian HansenCommented:
What are we looking for? The fiddle does not seem to do anything except display a table.

What is supposed to happen?
0
runnerjp2005Author Commented:
used dev toold sand helped
0
runnerjp2005Author Commented:
Thanks I have noted this for next time.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.