我是脚本和Web开发的新手。我正在以分页格式显示CSV文件。显示CSV文件的代码如下。
<?php
$names = file('demo.csv');
$page = $_GET['page'];
//constructor takes three parameters
//1. array to be paged
//2. number of results per page (optional parameter. Default is 10)
//3. the current page (optional parameter. Default is 1)
$pagedResults = new Paginated($names, 20, $page);
$handle = fopen('demo.csv', 'r');
if (($data = fgetcsv($handle, 1000, ',')) !== FALSE)
{
}
echo "<table border='3' bgcolor='#dceba9' style='float:center; margin:50'>";
echo '<tr><th>'.implode('</th><th>', $data).'</th></tr>';
//when $row is false loop terminates
while ( $row = $pagedResults->fetchPagedRow())
{
echo "<tr><td>";
//echo '<tr><th>'.implode('</th><th>', $data).'</th></tr>';
$row1 = str_replace( ',', "</td><td>", $row );
echo $row1;
echo "</td></tr>";
}
fclose($handle);
echo "</table>";
//important to set the strategy to be used before a call to fetchPagedNavigation
$pagedResults->setLayout(new DoubleBarLayout());
echo $pagedResults->fetchPagedNavigation();
//$data1 = [];
$total_columns = 0;
$handle1 = fopen('demo.csv', 'r');
while (false !== ($row = fgetcsv($handle1, 1000, ','))) {
0 === $total_columns and $total_columns = count($row);
$i = 1;
while (++$i <= $total_columns) {
$data1[$i][] = (int) $row[$i - 1];
}
}
$i = 0;
while (++$i <= $total_columns) {
$_SESSION["min-column-$i"] = min($data1[$i]);
$_SESSION["max-column-$i"] = max($data1[$i]);
}
$_SESSION['totalcolumns'] = $total_columns;
fclose($handle1);
?>
现在,根据CSV文件的列数,我需要那么多滑块。对于滑块,最小值和最大值基于列的最小值和最大值。代码如下。
<?php include 'index.php'; ?>
<?php
$totalcolumns = $_SESSION["totalcolumns"];
?>
<!-- Activate Simple Slider on your input -->
<h2>Keyword Scores</h2>
<?php
$i = 1;
while (++$i <= $_SESSION['totalcolumns']) {
$range = $_SESSION["min-column-$i"] . ',' . $_SESSION["max-column-$i"];?>
<br><?php echo "Keyword" ?>
<?php echo $i -1 ?>
<br><input type="text" data-slider="true" data-slider-range="<?php echo $range ?>" data-slider-step="1">
<?php } ?>
<form action = "update.php" method="post"><input type="submit" name="submit"value="SUBMIT"></form>
<script>
$("[data-slider]")
.each(function () {
var range;
var input = $(this);
$("<span>").addClass("output")
.insertAfter(input);
range = input.data("slider-range").split(",");
$("<span>").addClass("range")
.html(range[0])
.insertBefore(input);
$("<span>").addClass("range")
.html(range[1])
.insertAfter(input);
})
.bind("slider:ready slider:changed", function (event, data) {
$(this).nextAll(".output:first")
.html(data.value.toFixed(2));
});
</script>
现在,当我选择滑块中的值并点击“ SUBMIT ”按钮时,我应该相应地更新CSV的显示。 (即)只应显示满足滑块的行。我不知道如何做这个部分,因为我试图再包含一个PHP文件。但我无法将值传递给PHP文件。有人可以帮我这一部分吗?