简体   繁体   English

如何从PHP中的表中获取td数据

[英]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.

相关问题 php mysql 代码中的问题。 如何从数据库中获取特定的有序数据并在 php 中作为表视图显示到内部? - Issue in php mysql code. How to get specific ordered data from db and dispay to inside <td> as a table view in php? 如何使用PHP Simple DOM在没有属性的情况下从旁边的html table td元素中查找数据并获取文本? - How to find data and get text from html table td element next to it, without attribute using PHP Simple DOM? 如何使用PHP浏览HTML表并获取每个td中的数据? - How to go through an HTML table using PHP and get the data in each td? 如何在PHP Codeigniter中更改后获取表的TD ID VAL - How to get td id val of table after change in php codeigniter 如何在 td 和数据之后用 3 行在 php 中动态设计表 - How to design table for dynamically in php with 3 rows after td and data 如何在数据表的td中添加“ href”链接以打开PHP页面 - How to add a “href” link in a td of data table to open a PHP page 从html表中的每个td获取数据并将其传递给控制器 - get data from each td in html table and pass it to controller 如何使用PHP从网页上的表中获取数据 - How to get data from a table on a webpage in PHP 如何从td表中的js函数获取字符串值? - How to get string value from js function in td table? 如何从内部的表数据生成json数组 <td> 标签 - How to generate a json array from a table data inside a <td> tag
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM