Hello mates,
My third post here and hopefully, third time is a charm.
We have a query that displays searched results based on dynamic WHERE clause.
In other words, out of 8 search params, a user could search by either one or more params by simply passing a dynamic WHERE clause called $searchType.
This works great.
The last phase is to pass the value of $searchType via querystring to another page called exports.php and then dump the contents of the records associated with $searchType into a .csv file.
This is where I am having issues.
First the url with params:
Three params are passed from this url to exports.php.
Here is the entire code for exports.php:
Right now, I am having issues with $strTypes.
Warning: sqlsrv_fetch_array() expects parameter 1 to be resource boolean given in exportsw.php on line 35
Obviously, I am relatively new to php.
Any ideas how to work this out?
Thanks in advance
My third post here and hopefully, third time is a charm.
We have a query that displays searched results based on dynamic WHERE clause.
In other words, out of 8 search params, a user could search by either one or more params by simply passing a dynamic WHERE clause called $searchType.
This works great.
The last phase is to pass the value of $searchType via querystring to another page called exports.php and then dump the contents of the records associated with $searchType into a .csv file.
This is where I am having issues.
First the url with params:
Code:
echo "<br /><br /><a class='btn btn-default' href='exportsw.php?start=".urlencode($row_start)."&end=".urlencode($num_rows)."&stypes=".urlencode($searchType)."'>Export to CSV</a>";
Three params are passed from this url to exports.php.
Here is the entire code for exports.php:
Code:
<?php
$filename ="bids";
header("Content-type: application/csv");
header("Content-Disposition: attachment; filename=$filename.csv");
header("Pragma: no-cache");
header("Expires: 0");
ini_set('display_errors',1);
$private=1;
error_reporting(E_ALL ^ E_NOTICE);
// Connect to SQL Server database
include("connections/Connect.php");
$start = $_REQUEST["start"];
$end = $_REQUEST["end"];
$strTypes = $_REQUEST['stypes'];
// echo $strTypes;
$csv_output = 'Row,"Bid Date","Due Date","Due Time","Project Title","ID","Department","Type","Award Date","Last Update","Status"'."\r\n";
if(strpos($strTypes, 'bidDate') !== false){
$sql = " SELECT c.* FROM (
SELECT ROW_NUMBER() OVER(ORDER BY ID) AS RowID,CONVERT(VARCHAR(11), b.BidDate, 106) BidDate,CONVERT(VARCHAR(11), b.DueDate, 106) DueDate, b.DueTime, b.BidTitle, b.BidID, da.DeptAlias, b.BidType, CASE WHEN b.AwardDate ='01/01/1900' Then NULL ELSe CONVERT(VARCHAR(11), b.AwardDate, 106) END AS AwardDate, CASE WHEN b.LastUpdate='01/01/1900' THEN NULL ELSE CONVERT(VARCHAR(11), b.LastUpdate, 106) END AS LastUpdate, s.Status
FROM bids b inner join DeptALIAS da on b.AliasID = da.AliasID inner join Dept d on da.DeptCode =d.DeptCode inner join Status s on b.BidStatus=s.StatusId where b.BidDate = (strpos($strTypes, 'bidDate')
) AS c
WHERE c.RowID > $start AND c.RowID <= $end ORDER BY c.RowID ASC
";
}
// echo $sql;
$select_c = sqlsrv_query( $conn, $sql);
echo $csv_output;
while($result = sqlsrv_fetch_array($select_c, SQLSRV_FETCH_ASSOC))
{
echo implode(",", $result)."\n";
}
exit;
?>
Right now, I am having issues with $strTypes.
Warning: sqlsrv_fetch_array() expects parameter 1 to be resource boolean given in exportsw.php on line 35
Obviously, I am relatively new to php.
Any ideas how to work this out?
Thanks in advance