trying to create a button that exports the results on the screen to a csv or excel file
im stuck ive been struggling to figure this out
searching the internet i see solutions using mysql functions , but i need to use sqlsrv_ functions instead
heres my code to display the query results on the screen (sorry if its hard to follow)
but i need help on coding the button. any help
[php]
<?php //include functions file require_once ('/includes/function.php'); //include header file include_once ('/includes/header.php'); ?>$query =“SELECT distinct ID, Source, ProductID,Summary,SubmissionDate, ProductName, ReviewText FROM Data
Left Outer join armoury
on left(data.ProductID,7) = armoury.Style
WHERE
(Data.Source “. $qsrch.”) and isnull(Data.ProductCategory,’’) “.$csrch. " and isnull(Data.ProductID,’’) “.$ssrch. " and isnull(armoury.EndUse,’’) “.$eusrch.” and Data.SubmissionDate >= '”.$_GET[‘startdate’].”’ and Data.SubmissionDate <= '”.$_GET[‘enddate’]."’ and isnull(Data.ProductGender,’’) ".$psrch. " and (isnull(Data.Summary,’’) “.$tsrch.” or isnull(Data.ReviewText,’’) ".$tsrch. " or isnull(Data.Comments,’’) ".$tsrch. “) order by data.submissiondate desc”;
if(!empty($_POST[‘query’])){
$query =$_POST[‘query’];
}
$result = exe($query);
if( $result === false)
{
echo “Error in query preparation/execution.\n”;
die( print_r( sqlsrv_errors(), true));
}
?>
"; echo sqlsrv_num_rows($result); echo " records returned"; echo '
ID | '; echo 'Source | '; echo 'Style | '; echo 'Summary | '; echo '|
---|---|---|---|---|
Date | '; echo 'Product Name | '; echo 'Review Text | '; echo '||
"; echo date_format($value,'m/d/y'); } Elseif($rkey == 'ID') { echo " | "; echo ' '; } Elseif($rkey =='Summary') { echo " | "; if (!is_null($value)){ echo substr($value,0,100); if (strlen($value)>100){ echo '[...]'; }} } Elseif($rkey =='ReviewText') { echo " | "; $str = $str ." ".strtolower($value); if (!is_null($value)){ echo substr($value,0,300); if (strlen($value)>300){ echo '[...]';}} } Else{ echo " | "; echo $value; } $index++;} echo" | "; $index=0; echo "
Sorry, no records returned. Please try adjusting your search parameters."; } [/php]