[英]How to get td data from a table in PHP
I am currently stuck at this problem right now where I don't seem to have any idea how to implement this. 我现在正困在这个问题,我似乎不知道如何实现这个。 I have this table which is populated from a csv file in php and I want to get the data logged in order to calculate the daylight hours.
我有这个表从php中的csv文件填充,我想记录数据,以计算白天时间。
How can I get the data from the td "dateLogged", I did that in jquery before using children but I do not seem to be able to do that in php 我怎样才能从td“dateLogged”获取数据,我在使用子代之前在jquery中做了这个,但我似乎无法在php中做到这一点
//print out uploaded file.csv
echo "<html><body><table BORDER=1>\n\n";
echo " <tr><th>AvgCrown</th><th>MinCrown</th><th>MaxCrown</th><th>dateLogged</th><th>DaylightHours</th></tr>";
$f = fopen("./uploads/" . $_FILES["uploadedfile"]["name"], "r");
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>" . htmlspecialchars($cell) . "</td>";
}
echo "<td>" . calcDaylight() . "</td>";
echo "<tr>\n";
}
fclose($f);
echo "\n</table></body></html>";
Here is a sample how the table looks like Any help will be most welcome. 以下是表格外观的示例。欢迎任何帮助。
There's no need to parse the HTML if you can just grab the data while you're generating it. 如果您可以在生成数据时抓取数据,则无需解析HTML。 Something like this should be all you need:
这样的东西应该是你所需要的:
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
// Save the value before you output
$lastColValue = htmlspecialchars($cell);
echo "<td>" . $lastColValue . "</td>";
}
// If you want to store all log dates in an array:
$logDates[] = $lastColValue;
// Or if you want to do something with that value in calcDaylight:
echo "<td>" . calcDaylight( $lastColValue ) . "</td>";
echo "<tr>\n";
}
fclose($f);
Incidentally, if you do find you need to parse the HTML and are only familiar with jQuery, this library may strike your fancy: 顺便说一句,如果您确实发现需要解析HTML并且只熟悉jQuery,那么这个库可能会让您感到满意:
http://code.google.com/p/phpquery/ http://code.google.com/p/phpquery/
this? 这个?
while (($line = fgetcsv($f)) !== false) {
echo "<tr>";
foreach ($line as $cell) {
echo "<td>".htmlspecialchars($cell)."</td>";
}
echo "<td>" . calcDaylight( $cell[3] ) . "</td>";
echo "<tr>\n";
}
i might be wrong but 4th column is the field you want, no? 我可能错了,但第四列是你想要的字段,不是吗?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.