1
每當用戶執行搜索時,我想顯示總額從付費金額。我的代碼如下:從下面的php + mysql表中顯示總計代碼
<?php
$sql = "SELECT * FROM users";
if(isset($_POST['search'])){
$search_term = mysql_real_escape_string($_POST['search_box']);
$sql .= " WHERE first_name = '{$search_term}'";
$sql .= " OR last_name = '{$search_term}'";
$sql .= "OR month = '{$search_term}'";
}
$query = mysql_query($sql) or die(mysql_error());
?>
<form name="search_form" method="POST"action="displaydata.php">
Search: <input type="text"name="search_box" value="" />
<input type="submit" name="search"value="Search..">
</form>
<table width="70%" cellpadding="5" cellspace="5">
<tr><td>Student ID</td><td>First Name</td><td>Last Name</td><td>Paid Amount</td><td>Course</td><td>Month</td><td>Year</td></tr>
<H3>Payment Voucher</H3><?php while ($row =mysql_fetch_array($query)) {?>
<tr><td><?php echo $row ['student_id']; ?></td><td><?php echo $row ['first_name']; ?></td><td><?php echo $row ['amount']; ?></td><td><?php echo $row ['month']; ?></td>
</tr>
<?php } ?>
請編輯您的問題並正確格式化您的代碼,以便我們可以閱讀您提供的內容。 –
使用mysqli而不是mysql,因爲mysql不再支持 –
你的表格是如何定義的? –