php - 如何将这两个 html 表连接在一起?

标签 php mysql html

我想创建一个比较类型的页面。我目前有两个包含信息的表格,但希望将其放在表格上或将两者连接在一起。第一行将显示品牌名称,第二行将显示成本等...我正在获取所选复选框的值,并根据他们选择的内容进行比较。

$testName = $_POST['testCompare'];
$rpl = str_replace("_", " ", $testName);
$firstOne = "$rpl[0]";
$secondOne = "$rpl[1]";
echo "$firstOne";
echo "<br/>";
echo "$secondOne";

$query = "SELECT * FROM test_table WHERE test_name = '$firstOne'";
$query2 = "SELECT * FROM test_table WHERE test_name = '$secondOne'";
$result = mysql_query($query) or die ("Error in query: $query. " . mysql_error());
$result2 = mysql_query($query2) or die ("Error in query: $query2. " . mysql_error());

if (mysql_num_rows($result) > 0 && mysql_num_rows($result2) > 0) {

//if (mysql_num_rows($result) > 0) {

    while($row = mysql_fetch_row($result)) {            
        if ($firstOne == $row[1]) {
        {
            echo "<table border=1>";            
            echo "<tr>";
            echo "<td>" . $row[0] . "</td>";
            echo "<tr>";
            echo "<td>" . $row[1] . "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>" . $row[2] . "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>" . $row[3] . "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>" . $row[4] . "</td>";
            echo "</tr>";
            }
        }
        }echo "</table>";

    while($row2 = mysql_fetch_row($result2)) {          
        if ($secondOne == $row2[1]) {
        {   echo "<table border=1>";        
            echo "<tr>";
            echo "<td>" . $row2[0] . "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>" . $row2[1] . "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>" . $row2[2] . "</td>";
            echo "</tr>";
            echo "<tr>";
            echo "<td>" . $row2[3] . "</td>";
            echo "</tr>";
            echo "<td>" . $row2[4] . "</td>";
            echo "</tr>";
            }
        }
        }
        echo "</table>";
    }
 else {
        echo "No Results";
    }[/CODE]

谢谢

最佳答案

  1. 删除 </table>在第一个循环之后。
  2. 删除 <table border=1>来自两个循环
  3. 添加<table border=1在第一个循环之前。

目前,您正在定义一个新的 <table border=1>每次进入循环时。这将产生以下 HTML 代码:

<table ..>
<tr>...
<table ..>
..
<table> 
..
Et cetera
</table>
<table ..>
Et cetera
</table>

关于php - 如何将这两个 html 表连接在一起?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7664773/

相关文章:

php - 在 ezpublish 中创建可重写的 URL

html - VarChar MySQL 行 HTML 内容在输出时减少

c# - asp :label text using word-break on only long words? 上的断行

html - 如何创建圆形图像包装器

php - 网 bean "no tests executed"

php - 在接受 CSV 文件时,application/octet-stream 是一种安全的 MIME 类型吗?

mysql - 按年份计算行数,如果没有结果则添加值为 0 的行

mysql - 如何在单个查询中统计与基表结果匹配的多个表的记录?

javascript - 无法获取 html5 地理位置坐标来工作

php - MySQL 查询不显示 LEFT JOIN 和多个 AND 子句