這可能有點混亂,但我需要將xhtml表單與php代碼結合起來。所以在這裏它是如何開始的:我創建了一個搜索框,用戶通過輸入關鍵字或標題來搜索產品,然後我的搜索頁面從MySQL搜索數據並以表格格式顯示信息。現在我的網頁假設用戶在顯示的表格中比較產品信息,如果用戶勾選結果表格的特定兩行並再次提交,那麼它會將它們帶到另一個網頁,在那裏比較兩個打勾產品的價格。我不知道我會怎麼做,所以你的建議會幫助我。如何將xhtml表單與php代碼結合起來?
echo "<table border='1' bordercolor='#000066'>
<th>Item</th><br />
<th>image</th>
<th>description</th>
<th>price</th>
<th>brand</th>
<th>store</th>
<th>Tick</th>
</tr>"; // setting up the table headings.
while ($query_row=mysql_fetch_assoc($query_run))
{
echo "<tr bgcolor='#F5FFFF'>";
echo "<td>". $query_row['title']. "</td>";
echo "<td><img HEIGHT='250' WIDTH='250' src=fetch.php?imageid=".$query_row['productid']."></td>";
echo "<td>". $query_row['description']."</td>";
echo "<td>"."£".$query_row['price']. "</td>";
echo "<td>". $query_row['brand']."</td>";
echo "<td><a href=".$query_row['store'].">Click here</a></td>";
echo '<td>';
?>
<form action="tick.php" method="post"> <br />
<input type="checkbox" name="compare" value="<?php echo $query_row['productid']?>" />select to compare<br /> <?php echo '</td>';
}
echo "</table>"; ?>
<input align="right"type="submit" name="formSubmit" value="Click to comapre" />
</form>
爲
以下代碼tick.php
<?php
$比較= $ _POST [ '比較'];
如果(空($比較)) {
echo("You didn't select any products.");
} 別的 { $ N =計數($比較);
echo("You selected $N product: ");
for($i=0; $i < $N; $i++)
{
echo($compare[$i] . " ");
}
}
?>
我試圖以表格格式顯示產品信息,並在表格中添加了額外的列,並在複選框中勾選了結果表格的特定行,但它不起作用。我會嘗試在問題中編輯我的代碼。 – 2013-03-04 09:25:57
你所描述的整個故事只是意味着你想要達到的目標,而且完全不需要xhtml。它沒有說明你需要處理xhtml的地點和原因。 – Lion 2013-03-04 09:29:06
我真的不知道如何在沒有xhtml的情況下工作。上述代碼顯示瞭如何顯示搜索產品的結果。 – 2013-03-04 09:34:43