I am new to use SQL Server. I try to get data from a SQL Server table and convert it to JSON format and show it in HTML table. I try to do this two much. But still can't have success. If anyone know how to do this please help me. Any of your help effort is appreciated.
Here is my T-SQL query.
function Crawled_sites_total(){
//$sql = "SELECT * FROM crawl_site";
$sql = "SELECT
CSCH.CrawlSiteID, CSCH.CrawlHistoryID, CSCH.CountAtStart,
CSCH.CountAtEnd, CSCH.RecodsFound, CSAR.CrawlSite,
CSAR.AverageRecords as Standered,
CAST((((CONVERT(FLOAT, CSCH.RecodsFound) - CONVERT(FLOAT, CSAR.AverageRecords)) * 2 * 100) / (CONVERT(FLOAT, CSAR.AverageRecords) + CONVERT(FLOAT, CSCH.RecodsFound))) AS DECIMAL(18, 2)) as Tolerance
FROM
csCrawlSiteCrawledHistory as CSCH
INNER JOIN
csCrawledHistory as CH on CSCH.CrawlHistoryID = CH.CrawlHistoryID
INNER JOIN
csCrawlSiteAverageRecords as CSAR on csch.CrawlSiteID = CSAR.CrawlSiteId
WHERE
CH.CrawlHistoryID = (SELECT TOP 1 C.CrawlHistoryID
FROM csCrawledHistory C
WHERE C.EndTime IS NOT NULL
ORDER BY C.EndTime DESC) ";
//$result = $GLOBALS['conn']->query($sql);
while($row = mssql_fetch_assoc($sql)){
$row = array(
// data from theme
//'id' => $row['id'],
'CrawlSiteID' => $row['CrawlSiteID'],
'CrawlHistoryID' => $row['CrawlHistoryID'],
'CountAtStart' => $row['CountAtStart'],
'CountAtEnd' => $row['CountAtEnd'],
'RecodsFound' => $row['RecodsFound'],
'CrawlSite' => $row['CrawlSite'],
'Standered' => $row['Standered'],
'Tolerance' => $row['Tolerance'],
);
$data[] = preg_replace('/[\x00-\x1F\x80-\xFF]/', '', $row);
}
echo json_encode($data);
}