gpt4 book ai didi

php - 如果表中每 $row 都有函数

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

我有一个表,其中显示了调用流程中的数据。我需要按行操作该表中的数据,以便从数据库中查找的表中的所有值(现在在代码中)都将转换为文本值。让我向你展示并解释一下:

我的 table :

<?php
include_once "Connect2Martijn1.php";
?>

<link rel="stylesheet" href="CSSMartijn1.css">
</link>



<head>
<meta charset="iso-8859-1">
<meta name="description"content="VoizXL ">
<meta name="keywords"content="VoizXL ">
<meta name="author"content="Kenn Lo-A-Tjong">
</meta>
<title>Call Flow</title>


</head>



<fieldset>
<article class="rondehoeken">
<header>
<div class="streep1"></div>
<div class="streep2"></div>
<div class="streep3"></div>
<div class="streep4"></div>
<div class="streep5"></div>
<h1 id="artikel-titel" >Call Flow</h1>
</header>

<div id="artikel-container">

<table class="table 1">
<thead>
<title>Call Flow</title>
<meta charset = "UTF-8" />
<style type = "text/css">
table, td, th {
border: 1px solid black;
}
</style>
</thead>

<tbody>
<?php
$con=mysqli_connect("localhost","root","","voizxl_wachtrij");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM Callflow");

echo "<table border='0'>
<tr>
<th>Nummer</th>
<th>Naam</th>
<th>Status</th>
<th>Time</th>
</tr>";



while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $row['statusAnswered'] . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}
echo "</table>";


mysqli_close($con);
?>

(我想要的)转换数据的示例:

<?php
if ($row['statusAnswered'] ="NULL")
{
echo "Not Answered!";
}
else
{
echo "Answered!";
}
?>

我想要实现的是例如。如果数据库中该行的值为 NULL 或非,则 $row['statusAnswered'] 中此表中的值将以文本形式显示为“已应答或未应答”...

我该怎么做?

现在我只能在 table 下有 1 个回显说已回答:S不知道如何将其放在每 $row 中。

最佳答案

 while($row = mysqli_fetch_array($result))
{
if (!isset($row['statusAnswered']))
{
$answered = "Not Answered!";
}
else
{
$answered = "Answered!";
}
echo "<tr>";
echo "<td>" . $row['calleridnum'] . "</td>";
echo "<td>" . $row['calleridname'] . "</td>";
echo "<td>" . $answered . "</td>";
echo "<td>" . $row['statusCalling'] . "</td>";
echo "</tr>";
}

关于php - 如果表中每 $row 都有函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18569067/

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