订购/排序按钮

时间:2019-03-27 07:40:51

标签: php html css mysql

我有一个当前无法使用的订购按钮。我已经使用php和mysql在表中显示信息。我正在尝试选择一个值,然后将数据排序到表中。请检查代码,让我知道我在做什么错。

谢谢!

这是我的code.php

<?php
$con = mysqli_connect('localhost','root','', 'playground');
$results_per_page = 5;
$sql='SELECT * FROM merchant_details';
$result = mysqli_query($con, $sql);
$number_of_results = mysqli_num_rows($result);
$number_of_pages = ceil($number_of_results/$results_per_page);
/* $sortBy = (isset($_POST['sortBy']) ? $_POST['sortBy'] : NULL); 
if($sortBy != NULL) { 
$sql .= ' ORDER BY ' . $sortBy;
 } */
if (!isset($_GET['page'])) {
  $page = 1;
} else {
  $page = $_GET['page'];
}
$this_page_first_result = ($page-1)*$results_per_page;
$sql='SELECT * FROM merchant_details LIMIT ' . $this_page_first_result . ',' .  $results_per_page;
$result = mysqli_query($con, $sql);
echo"<form> 
   <select class='orderby' name='sortBy'> 
    <option value='company'>Company</option> 
    <option value='adress'>Adress</option> 
    <option value='city'>City</option> 
    <option value='phone'>Phone</option> 
    <option value='email'>E-mail</option> 
   </select> 
   <button class='orderBtn' type='submit' formaction='?' formmethod='post'>Order By</button> 
  </form>";
echo "<table id='merchants' border='1'>
<tr>
<th>Company</th>
<th>Adress</th>
<th>City</th>
<th>Phone</th>
<th>Email</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
 echo"
<tr>
<td>{$row['company']}</td>
<td>{$row['adress']}</td>
<td>{$row['city']}</td>
<td>{$row['phone']}</td>
<td>{$row['email']}</td>
</tr>";
}
echo"</table>";
for ($page=1; $page<=$number_of_pages; $page++) {
  echo '<a class="pagination" href="welcome.php?page=' . $page . '">' . $page . '</a> ';
}
?>

0 个答案:

没有答案