gpt4 book ai didi

php - 如何使用 explode 显示表格,或者还有其他建议吗?

转载 作者:行者123 更新时间:2023-11-29 11:50:31 25 4
gpt4 key购买 nike

首先我想解释一下我的申请:

我已经为我的 QA 工作创建了一个应用程序。该应用程序生成一个文档,保存为 pdf 并添加到服务器。我其中有一个动态表,它使用 implode 函数将其保存到数据库中,并将其与数据库上的测试用例在同一行中用逗号分隔。

一切正常,但是当我想查看测试用例时,我很难弄清楚如何让它显示。我已经阅读了大量使用 explode 的场景,但没有运气......

<?php include 'app_database/database.php'; ?>
<?php
if(isset($_POST)){

$step = $_REQUEST['step'];
$url = $_REQUEST['url'];
$pass_fail = $_REQUEST['pass_fail'];
$comment = $_REQUEST['comment'];
$sql1 ="UPDATE qa_testing_application SET step='".implode(',',$step)."',url='" . implode(',',$url) . "',pass_fail='" . implode(',',$pass_fail) . "',comment='" . implode(',',$comment) . "' WHERE test_case_name='$test_case_name'";
$result= mysqli_query($database, $sql1) or die(mysqli_error($database));
}
?>

我是这样插入的。我想从数据库中检索它。

我希望将其显示如下:

请查看链接http://i.stack.imgur.com/6aglk.jpg

目前我正在尝试测试并找出如何显示它:不确定如何在这里实现 for 或 foreach 函数(如果需要)。

$countsteps = 0;
$counturls = 0;
$countpass_fails = 0;
$countcomments = 0;

$test_case_number = '21';
$select_tbl=mysqli_query($database,"select * from qa_testing_application WHERE test_case_number='$test_case_number'");
$result = mysqli_query($database, $sql1) or die(mysqli_error($database));
while($fetch=mysqli_fetch_object($result))
{
$step=$fetch->step;
$url=$fetch->url;
$pass_fail=$fetch->pass_fail;
$comment=$fetch->comment;

$steps=explode(",",$step);
$urls=explode(",",$url);
$pass_fails=explode(",",$pass_fail);
$comments=explode(",",$comment);

echo '<td>'.$steps[$countsteps++].'</td>';
echo '<td>'.$urls[$counturls++]."</td>";
echo '<td>'.$pass_fails[$countpass_fails++]."</td>";
echo '<td>'.$comments[$countcomments++]."</td>";

}

那么我如何才能将其显示在表格中?

编辑:

哦,这是我得到的错误:

enter image description here

最佳答案

undefined offset

此错误只是表明给定数组中不存在这样的键,或者您正在尝试从非数组变量中获取值。

要将数据显示为表格格式,您不需要分解来自数据库的数据。它们已经串联起来。

因此,要显示来自数据库的数据,请修改您的代码,如下所示:

    $test_case_number = '21';
$select_tbl=mysqli_query($database,"select * from qa_testing_application WHERE test_case_number='$test_case_number'");
$result = mysqli_query($database, $sql1) or die(mysqli_error($database));

echo '<table>';
echo '<th>Step</th><th>Url</th><th>Pass/Fail</th><th>Comment</th>';
while($fetch=mysqli_fetch_object($result))
{
echo '<tr>';
echo '<td>'.$fetch->step.'</td>';
echo '<td>'.$fetch->url.'</td>';
echo '<td>'.$fetch->pass_fail.'</td>';
echo '<td>'.$fetch->comment.'</td>';
echo '</tr>';
}
echo '</table>';

关于php - 如何使用 explode 显示表格,或者还有其他建议吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34151883/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com