0
我想創建一個比較排序的頁面。我目前有兩張包含這些信息的表格,但希望將它們放在桌面上或將它們連接在一起。第一行顯示品牌名稱,第二行顯示成本等...我抓住選定複選框的值並根據他們選擇的比較結果。如何將這兩個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]
感謝
您可能會顯示數據庫表的方案?另外,在別人之前,你有一個SQL注入漏洞,因爲你不是逃避用戶輸入,即傳遞'$ _POST'變量而不消毒。 –
與您的問題無關,但您的代碼非常不安全。您不僅不會對輸入進行消毒,您在查詢中不使用佔位符。 – CanSpice