开发者

How can I join these two html tables together?

I want to create a compare sort of page. I currently have two tables with the information, but want it to be on table or join both together. The first row would show Name of brand, second would show cost, etc... I am grabbing the values of selected checkboxs and based on what they selected it get compared.

$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]

Thanks


  1. Remove the </table> after the first loop.
  2. Remove <table border=1> from both loops.
  3. Add <table border=1 before the first loop.

Currently, you're defining a new <table border=1> each time you enter the loop. This will result in this HTML code:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜