听起来很简单,但我不知道从哪里开始。
我的网站有一系列可供用户选择的选项。从该选择中,构建一个查询,并从数据库中提取数据。然后以表格格式返回。
此时,数据显示出来,用户可以单击按钮将记录导出到 Excel 工作表中。
这是查询:
<?php
function displayrecords(){
$place = $_GET['place'];
$time = $_GET['time'];
$name = $_GET['name'];
$sql_json = "";
$where = "";
if($place != ""){
$where = " `place` = '".mysql_real_escape_string($place)."'";
}
if($time != ""){
if( $where != "" ) $where .= " AND ";
$where .= " `time` = '".mysql_real_escape_string($time)."'";
}
If($name != ""){
if( $where != "" ) $where .= " AND ";
$where .= " `name` = '".mysql_real_escape_string($name)."'";
}
if ($where != "") $sql_json = "SELECT * FROM `database`" . " WHERE " . $where . ";";
$QueryResult = @mysql_query($sql_json) or die ('<div>Use filters to search</div>');
$resnum = mysql_num_rows($QueryResult);
if ($resnum == 0){
echo "<div>Your search returned no results</div";
}
else {
echo "<table>\n";
echo "<tr><th>Place</th>" . "<th>Time</th>" . "<th>Name</th></tr>\n";
while(($Row = mysql_fetch_assoc($QueryResult)) !== FALSE){
echo "<tr><td>{$Row[place]}</td>";
echo "<td>{$Row[time]}</td>";
echo "<td>{$Row[name]}</td></tr>";
};
echo "</table>\n";
}
}
?>
此时我可以在 html 中调用该函数:
<?php displayrecords(); ?>
然后这是我用来导出的按钮:
<input class="btn btn-success btn-small" type="submit" name="get_report" value="Get Report" />
这就是我卡住的地方。我知道我可能不得不使用 javascript 或其他东西。请给我一些见解。无需关闭我的代码。我使用的是常规 mysql,而不是 mysqli 或 pdo。
请告诉我下一步我需要做什么才能使按钮工作,以便它导出到 Excel 工作表。我会很感激你的帮助。
谢谢你。