Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 从CSV填充的数据库表填充多个HTML表_Php_Html_Mysql_Csv_Html Table - Fatal编程技术网

Php 从CSV填充的数据库表填充多个HTML表

Php 从CSV填充的数据库表填充多个HTML表,php,html,mysql,csv,html-table,Php,Html,Mysql,Csv,Html Table,我目前有一个网站,它有一个简单的界面,用户可以登录并选择上传或查看。他们可以上传CSV(为此,CSV模板大约有300个字段),或者转到页面选择或搜索已上传的特定记录(按某些键排序) 在我的文件夹中有一个文件上传/提交部分的HTML页面,该页面使用upload.php文件,该文件大约有400行代码,用于处理将CSV插入数据库的操作。我现在创建了一个display.html文件,该文件在一个页面上为14或15个单独的html表提供了大约300行其他代码。我首先用HTML创建它们,因为它们都有不同的样

我目前有一个网站,它有一个简单的界面,用户可以登录并选择上传或查看。他们可以上传CSV(为此,CSV模板大约有300个字段),或者转到页面选择或搜索已上传的特定记录(按某些键排序)

在我的文件夹中有一个文件上传/提交部分的HTML页面,该页面使用upload.php文件,该文件大约有400行代码,用于处理将CSV插入数据库的操作。我现在创建了一个display.html文件,该文件在一个页面上为14或15个单独的html表提供了大约300行其他代码。我首先用HTML创建它们,因为它们都有不同的样式、标题和格式需要保留

我的目标是:当用户选择一条记录时,我需要显示包含所有不同表的html页面,并且每个表都需要由SQL暂存表中包含300个CSV字段的某些字段填充。因此,前10个字段将在一个表中,下7个字段将在一个表中,依此类推。我知道我不能在HTML页面中调用PHP,但我已经用HTML创建了表,所以我想知道是否可以将其更改为PHP并向现有表添加某些语法,以及如何按名称将这些字段插入到每个表行中。下面是一个上载PHP的示例,我在其中为列声明了变量:

PHP(用于上传单独的文件)

现有表的HTML(只有一个表。我尝试将PHP用作PHP文件时将其留在了文件中):


质量保证/质量控制检查表
服务地址正确
服务定位正确
仪表号正确吗
仪表制造商变更
仪表类型已更改
电表型号更改
低位寄存器正确
高位寄存器正确



我将PHP代码留在表中,以显示我的尝试,但我认为表名的命名约定对我的PHP不起作用。在我的网页上,我只收到成功的db连接的消息,但我的表并不像我只以PHP运行时那样显示。将数据库中的变量插入此页上的多个表的最佳方法是什么?

此解决方案允许您配置哪些列显示在哪个表中

<?php

$tables = array();
$tables[0] = array('title' => 'Qa/Qc CheckList', 'cols' => array('Order #' => 'orderNumber','Place' => 'place','Work Order' => 'workOrderNum'));
$tables[1] = array('title' => 'Another CheckList', 'cols' => array('Low Side MIU' => 'lowSideMIUNum','Account #' => 'accountNum','Name' => 'custName'));
// ... add other table definitions ...

if ($connect->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
    echo'success!';
}
$query1 = "SELECT * FROM staging";
$result1 = mysqli_query($connect,$query1);

$all_rows = mysqli_fetch_all($result1);

if($all_rows) {
    foreach($tables as $tableno => $tableinfo) {
        foreach($all_rows as $rowno => $row) {
?>
<!-- <?php echo $tableinfo['title']; ?> -->
<table>
<tr>
    <th colspan="2"><?php echo $tableinfo['title']; ?></th>
</tr>
<?php
            foreach($tableinfo as $col_label => $col_name) {
?>
<tr>
    <td><?php echo $col_label; ?></td>
    <td><?php echo $row[$col_name]; ?></td>
</tr>
<?php
            } // end of foreach $table_info
?>
</table>
<?php
        } // end of foreach $all_rows
?>
<?php
    } // end of foreach $tables

} else {
    echo "<p>No data found.</p>\n";
}
?>


尝试提供的示例时遇到了哪些错误?TMI。我在中途对.Kade M.失去了兴趣,没有错误,但当我执行HTML文件时,它们只显示表。否则,使用PHP代码,我会收到成功连接的调试消息和一个空白页面。CodeGodie,我过去在这个项目的CSV部分遇到了一些问题,我在这个问题上没有提供足够的信息。我已经学会了为我要达到的目标尽可能多地投入,因为我宁愿投入过多也不愿投入不足。注释中有一些代码,您是否在使用该代码?如果是,您将mysql和mysqli混合在这一行
while($row=mysql\u fetch\u array($result1)){
这也是有意义的。我从上面修改了我的代码,使所有的东西都使用“mysql”,我成功了,我只需调用正确行中的每个变量。如果我要保持这种格式,所有东西都将始终显示在相同的单元格中,只需从数据库中选择正确的记录。比如说,我用ea填充了一个下拉列表从数据库中选择ch工单号,是否有一种特殊的方法可以使用PHP从数据库中调用相应的记录?首先,使用mysqli而不是mysql。前者是当前的,后者是折旧的。至于第二个问题,您的SQL语句应该有一个where子句来从t中选择正确的记录谢谢,我的mac电脑已经自动更正了,但我确实把它们都改成了使用mysqli,还有where子句?
<!--<?php

$server = "localhost";
$user = "root";
$pw = "root";
$db = "uwsTest";

$connect = mysqli_connect($server, $user, $pw, $db);

$query1 = "SELECT * FROM staging";
$result1 = mysqli_query($connect,$query1);

if ($connect->connect_error) {
die("Connection failed: " . $conn->connect_error);
}else{
    echo'success!';
}


?>


<?
while($row = mysql_fetch_array($result1)){
?>
<!--Qa Table-->
<table>
<tr>
<th colspan="2">Qa/Qc CheckList</th>
</tr>
<tr>
<td>Service Address Correct</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>Service Loc Correct</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>Meter Number Correct</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>Meter Manufacturer Changed</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>Meter Type Changed</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>Meter Model Changed</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>Low Register Correct</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
<tr>
<td>High Register Correct</td>
<td><? echo $row['orderNumber'];?>&nbsp;</td>
</tr>
</table>
<br>
<br>

<?
}
?>
<?php

$tables = array();
$tables[0] = array('title' => 'Qa/Qc CheckList', 'cols' => array('Order #' => 'orderNumber','Place' => 'place','Work Order' => 'workOrderNum'));
$tables[1] = array('title' => 'Another CheckList', 'cols' => array('Low Side MIU' => 'lowSideMIUNum','Account #' => 'accountNum','Name' => 'custName'));
// ... add other table definitions ...

if ($connect->connect_error) {
die("Connection failed: " . $conn->connect_error);
} else {
    echo'success!';
}
$query1 = "SELECT * FROM staging";
$result1 = mysqli_query($connect,$query1);

$all_rows = mysqli_fetch_all($result1);

if($all_rows) {
    foreach($tables as $tableno => $tableinfo) {
        foreach($all_rows as $rowno => $row) {
?>
<!-- <?php echo $tableinfo['title']; ?> -->
<table>
<tr>
    <th colspan="2"><?php echo $tableinfo['title']; ?></th>
</tr>
<?php
            foreach($tableinfo as $col_label => $col_name) {
?>
<tr>
    <td><?php echo $col_label; ?></td>
    <td><?php echo $row[$col_name]; ?></td>
</tr>
<?php
            } // end of foreach $table_info
?>
</table>
<?php
        } // end of foreach $all_rows
?>
<?php
    } // end of foreach $tables

} else {
    echo "<p>No data found.</p>\n";
}
?>