如果表中的每行$行的函数

时间:2013-09-02 08:49:53

标签: php mysql

我有一个表格,显示来自呼叫流程的数据。 我需要每行操作此表中的数据,以便从我的数据库中查找我的表的所有值(现在在代码中)将被转换为文本值。让我告诉你并解释一下:

我的表:

<?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']的此表中的值将以文本形式显示为“已回答或未回答”...

我该怎么做?

现在,我只能在桌子下面有一个回答:Answered:S 不知道如何按行排列。

4 个答案:

答案 0 :(得分:2)

 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>";
      }

答案 1 :(得分:1)

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

  echo "<td>" . $row['statusCalling'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

答案 2 :(得分:0)

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']=='NULL'?'Not Answered!':'Answered!') . "</td>";
  echo "<td>" . $row['statusCalling'] . "</td>";
  echo "</tr>";
  }
echo "</table>";

答案 3 :(得分:-1)

你可以使用;

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

然后通过替换来调用;

echo "<td>" . $row['statusAnswered'] . "</td>";

用;

echo "<td>{$checkstatus}</td>"