Php 对CSV数据进行Fire查询
我有一个公共的谷歌电子表格。我从远程URL获取了Php 对CSV数据进行Fire查询,php,Php,我有一个公共的谷歌电子表格。我从远程URL获取了CSV数据作为一个数组。然后我将信息显示为一个HTML列表,引用适当的数组项。 现在我想对它启动一个php select查询,以便只显示某个特定参与者的八卦。如何实现? (我想使用一个变量$Name.wen。我提供名称。我应该了解那个演员的八卦。) 我的excel工作表包含以下列 > 1.Sr No. > 2.Name > 3.Gossip 这是我的php页面的代码,它以列表的形式检索数据: $lines = file('htt
CSV
数据作为一个数组。然后我将信息显示为一个HTML列表,引用适当的数组项。
现在我想对它启动一个php select查询,以便只显示某个特定参与者的八卦。如何实现?
(我想使用一个变量$Name.wen。我提供名称。我应该了解那个演员的八卦。)
我的excel工作表包含以下列
> 1.Sr No.
> 2.Name
> 3.Gossip
这是我的php页面的代码,它以列表的形式检索数据:
$lines = file('https://docs.google.com/spreadsheet/pub?key=0AgzUC4MxdChJdFIyMHFUZ21PS053b3Z1OHFnbHJwYVE&single=true&gid=0&output=csv');
$headers = array_shift($lines);
foreach ($lines as $line)
{
$ldata = explode(',', trim($line));
if ($ldata[0] == '') break;
echo '<li>Sr No. <strong>' . $ldata[0] . '</strong></li><li>Name <strong>' . $ldata[1] . '</strong></li><li>Gossip <strong>' . $ldata[2] . '</strong></li>';
}
$lines=文件('https://docs.google.com/spreadsheet/pub?key=0AgzUC4MxdChJdFIyMHFUZ21PS053b3Z1OHFnbHJwYVE&single=true&gid=0&output=csv');
$headers=数组移位($line);
foreach($line作为$line)
{
$ldata=分解(“,”,修剪($line));
如果($ldata[0]='')中断;
回音“序号”.$ldata[0]”。 姓名“.$ldata[1]”。 八卦“.$ldata[2]”。 ;
}
如果名称不符合要求,则不显示行:
<?php
// get the CSV data as an array from the remote URL
$lines = file('https://docs.google.com/spreadsheet/pub?key=0AgzUC4MxdChJdFIyMHFUZ21PS053b3Z1OHFnbHJwYVE&single=true&gid=0&output=csv');
// get rid of header row
$headers = array_shift($lines);
// Loop through data- therer is only one line hear
foreach ($lines as $line) {
$ldata = explode(',', trim($line)); // split row to its own array of elements
if ($ldata[0] == '') break; // an empty line means we are done, so exit the foreach loop
if($ldata[1] == $var_with_required_name) {
// now we can just output the information as an HTML list, referencing the appropriate array items
echo '<li>Sr No. <strong>' . $ldata[0] . '</strong></li><li>Name <strong>' . $ldata[1] . '</strong></li><li>Gossip <strong>' . $ldata[2] . '</strong></li>';
}
}
?>
如果名称不符合要求,则不显示行:
<?php
// get the CSV data as an array from the remote URL
$lines = file('https://docs.google.com/spreadsheet/pub?key=0AgzUC4MxdChJdFIyMHFUZ21PS053b3Z1OHFnbHJwYVE&single=true&gid=0&output=csv');
// get rid of header row
$headers = array_shift($lines);
// Loop through data- therer is only one line hear
foreach ($lines as $line) {
$ldata = explode(',', trim($line)); // split row to its own array of elements
if ($ldata[0] == '') break; // an empty line means we are done, so exit the foreach loop
if($ldata[1] == $var_with_required_name) {
// now we can just output the information as an HTML list, referencing the appropriate array items
echo '<li>Sr No. <strong>' . $ldata[0] . '</strong></li><li>Name <strong>' . $ldata[1] . '</strong></li><li>Gossip <strong>' . $ldata[2] . '</strong></li>';
}
}
?>
试一试:
<?php
// get the CSV data as an array from the remote URL
define('GOOGLE_DOC','https://docs.google.com/spreadsheet/pub?key=0AgzUC4MxdChJdFIyMHFUZ21PS053b3Z1OHFnbHJwYVE&single=true&gid=0&output=csv');
if(isset($_GET['filterColumn'])){define('FILTER_COLUMN',$_GET['filterColumn']);}
if(isset($_GET['filterValue'])){define('FILTER_VALUE',$_GET['filterValue']);}
function readCSVIntoArray($fileName)
{
$rows=array();
if (($handle = fopen($fileName, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){$rows[]=$data;}
fclose($handle);
}
$h=array_shift($rows);
return array($h,$rows);
}
list($head,$rows)=readCSVIntoArray(GOOGLE_DOC);
header('Content-Type: text/html; charset=utf-8');
?><!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Ultimater's Example</title>
<style type="text/css">
html,body
{
margin:0;
padding:0;
font-family:'Source Sans Pro',sans-serif;
font-size: 13px;
color:black;
background:#e2e2ec;
line-height:15px;
}
table{border-collapse:collapse;}
table thead tr th{font-weight:bold;padding:2px;margin:1px;border:1px solid black;background-color:blue;color:white;}
table tbody tr td{margin:1px;padding:2px;border:1px solid black;}
</style>
</head>
<body>
<div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<select name="filterColumn">
<?php foreach($head as $i=>$h){echo sprintf('<option value="%s">%s</option>',$i,htmlentities($h));} ?>
</select>
<input type="text" name="filterValue" place-holder="filter" value="" />
<input type="submit" value="Filter" />
</form>
</div>
<hr />
<?php
echo '<table>';
echo '<thead><tr><th>'.implode('</th><th>',$head).'</th></tr></thead>';
echo '<tbody>';
foreach($rows as $row)
{
if(defined('FILTER_COLUMN')&&defined('FILTER_VALUE'))
{
if(strpos($row[FILTER_COLUMN],FILTER_VALUE)===false)continue;
}
echo '<tr><td>'.implode('</td><td>',$row).'</td></tr>';
}
echo '</tbody>';
echo '</table>';
?>
</body>
</html>
Ultimater的例子
html,正文
{
保证金:0;
填充:0;
字体系列:'sourcesans-Pro',Sans-serif;
字体大小:13px;
颜色:黑色;
背景:#E2EC;
线高:15px;
}
表{边框折叠:折叠;}
表THAD tr{字体大小:粗体;填充:2px;边距:1px;边框:1px纯黑色;背景色:蓝色;颜色:白色;}
表tbody tr td{边距:1px;填充:2px;边框:1px纯黑色;}
试一试:
<?php
// get the CSV data as an array from the remote URL
define('GOOGLE_DOC','https://docs.google.com/spreadsheet/pub?key=0AgzUC4MxdChJdFIyMHFUZ21PS053b3Z1OHFnbHJwYVE&single=true&gid=0&output=csv');
if(isset($_GET['filterColumn'])){define('FILTER_COLUMN',$_GET['filterColumn']);}
if(isset($_GET['filterValue'])){define('FILTER_VALUE',$_GET['filterValue']);}
function readCSVIntoArray($fileName)
{
$rows=array();
if (($handle = fopen($fileName, "r")) !== FALSE)
{
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE){$rows[]=$data;}
fclose($handle);
}
$h=array_shift($rows);
return array($h,$rows);
}
list($head,$rows)=readCSVIntoArray(GOOGLE_DOC);
header('Content-Type: text/html; charset=utf-8');
?><!doctype html>
<html>
<head>
<meta charset="utf-8" />
<title>Ultimater's Example</title>
<style type="text/css">
html,body
{
margin:0;
padding:0;
font-family:'Source Sans Pro',sans-serif;
font-size: 13px;
color:black;
background:#e2e2ec;
line-height:15px;
}
table{border-collapse:collapse;}
table thead tr th{font-weight:bold;padding:2px;margin:1px;border:1px solid black;background-color:blue;color:white;}
table tbody tr td{margin:1px;padding:2px;border:1px solid black;}
</style>
</head>
<body>
<div>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="GET">
<select name="filterColumn">
<?php foreach($head as $i=>$h){echo sprintf('<option value="%s">%s</option>',$i,htmlentities($h));} ?>
</select>
<input type="text" name="filterValue" place-holder="filter" value="" />
<input type="submit" value="Filter" />
</form>
</div>
<hr />
<?php
echo '<table>';
echo '<thead><tr><th>'.implode('</th><th>',$head).'</th></tr></thead>';
echo '<tbody>';
foreach($rows as $row)
{
if(defined('FILTER_COLUMN')&&defined('FILTER_VALUE'))
{
if(strpos($row[FILTER_COLUMN],FILTER_VALUE)===false)continue;
}
echo '<tr><td>'.implode('</td><td>',$row).'</td></tr>';
}
echo '</tbody>';
echo '</table>';
?>
</body>
</html>
Ultimater的例子
html,正文
{
保证金:0;
填充:0;
字体系列:'sourcesans-Pro',Sans-serif;
字体大小:13px;
颜色:黑色;
背景:#E2EC;
线高:15px;
}
表{边框折叠:折叠;}
表THAD tr{字体大小:粗体;填充:2px;边距:1px;边框:1px纯黑色;背景色:蓝色;颜色:白色;}
表tbody tr td{边距:1px;填充:2px;边框:1px纯黑色;}
Actor存储在Name
列中,对吗?Actor存储在Name
列中,对吗?@PalakSanghani欢迎您。JFYI:@PalakSanghani欢迎你。和JFYI: