如何从CSV / . txt文件中读取某些数据到表中


How to read certain data from CSV / .TXT files into a table

我知道有很多教程我尝试了几乎所有的,但它似乎没有工作,有一个。txt文件(现在我将其转换为。csv,希望它能工作,但它没有)。

该文件包含以;分隔的数据,第一行包含某些事物的名称,其他行是记录。

我想要的是读取和显示正确的数据关于正确的工作id和客户id,可以插入到一个HTML表单,并在它运行后显示一个HTML表,但不幸的是,它不工作出于某种原因。代码如下:

首先是HTML表单的代码:
 <h2>Device's status </h2>
                    <form id="form" name="form" method="post" action="process.php">
                        <div class="form-group">
                            <input type="text" name="customerid" class="form-control" required="required" placeholder="Customer ID">
                        </div>
                        <div class="form-group">
                            <input type="text" name="workid" class="form-control" required="required" placeholder="Worksheet ID">
                        </div>
                        <div class="form-group">
                            <input type="submit" name="submit" class="btn btn-submit" value="Submit">
                        </div>
                    </form>
然后是process.php:
<?php
$workid     = @trim(stripslashes($_POST['workid'])); 
$customerid       = @trim(stripslashes($_POST['cusomterid'])); 
$file = file('WEBDATA.csv');
foreach($file as $line){
    list($workid,$customerid,$devicename,$devicesnumber,$manufactured,$offer,$grosspay;$status)= explode(";",$line);
}
?>

     <table border="1">
        <tr>
            <td> Worksheet ID </td>
            <td> Customer ID</td>
            <td> Device Name</td>
            <td> Serial Number</td>
            <td> Manufacturer</td>
            <td> Expected Price </td>
            <td> Gross Final Price </td>
            <td> Repairing status </td>
            <tr>
                        <td><?php echo "$workid" ?></td>
                        <td><?php echo "$customerid" ?>   </td>
                        <td><?php echo "$devicename" ?>   </td>
                        <td><?php echo "$devicesnumber" ?>   </td>
                        <td><?php echo "$manufactured" ?>   </td>
                        <td><?php echo "$offer" ?>   </td>
                        <td><?php echo "$grosspay" ?>   </td>
                        <td><?php echo "$status" ?>   </td>

有什么问题吗?如何做到这一点呢?简单地说:用户在HTML表单中输入2个id,它应该显示来自.csv文件的关于这2个id的数据。

我不知道你们有没有注意到或者我不完全理解这个问题,但是当我做这些改变时,它运行得很顺利,并给出了数据表。

<?php
$workid     = @trim(stripslashes($_POST['workid'])); 
$customerid       = @trim(stripslashes($_POST['cusomterid'])); 
$file = file('WEBDATA.csv');
?>
<table border="1">
    <tr>
        <td> Worksheet ID </td>
        <td> Customer ID</td>
        <td> Device Name</td>
        <td> Serial Number</td>
        <td> Manufacturer</td>
        <td> Expected Price </td>
        <td> Gross Final Price </td>
        <td> Repairing status </td>
    <tr>
<?php
foreach($file as $line){
    list($workid,$customerid,$devicename,$devicesnumber,$manufactured,$offer,$grosspay,$status)= explode(";",$line);
?>
        <td><?php echo "$workid" ?></td>
        <td><?php echo "$customerid" ?>   </td>
        <td><?php echo "$devicename" ?>   </td>
        <td><?php echo "$devicesnumber" ?>   </td>
        <td><?php echo "$manufactured" ?>   </td>
        <td><?php echo "$offer" ?>   </td>
        <td><?php echo "$grosspay" ?>   </td>
        <td><?php echo "$status" ?>   </td>             
<?php   } ?>
</table>