【发布时间】:2013-11-23 05:09:41
【问题描述】:
我想在 php while 循环中填充两个不同的 html 表。我当前的代码在名称不为空时填充表 1($row[name])。但是,我如何声明 table2 以便仅在名称为空时填充 table2 ?谁能告诉我如何声明 2 个不同的表并根据 db 中的名称值是否为空来填充它们?
//table declration
echo "<table border='1'>
<tr>
<th>ID</th>
<th>name</th>
<th>page URL</th>
<th>img URL</th>
</tr>";
foreach ($lines as $line) {
//print_r( $line );
$line = rtrim($line);
$result = mysqli_query($con,"SELECT ID,name,imgUrl,imgPURL FROM testdb WHERE imgUrl like '%$line'");
if (!$result) {
die('Invalid query: ' . mysql_error());
}
//echo $result;
if(mysqli_num_rows($result)>0)
{
if(mysqli_num_rows($result)>1)
{
echo "<br>Duplicate in DB:".$line."<br>";
};
while($row = mysqli_fetch_array($result))
{
$totalRows++;
if (!empty($row[name]))
{
echo "<tr>";
echo "<td>" . $row['ID'] ."(".$totalRows. ")</td>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['imgPURL'] . "</td>";
echo "<td>" . $row['imgUrl'] . "</td>"; echo "</tr>";
}
else
{
$emptyNameCounter++;
//fill table2 if name is empty
};
}; // end of while loop
}
else
{
echo "<br>Not Found:".$line."<br>";
};
};// end of for each line loop
echo "</table>";
【问题讨论】:
标签: php html mysql html-table