Before i place this question i searched other similar problems like mine with tables and forms but i didn't manage to find solution. As you can see from my code i don't know why but this is not working.. I have a form and inside there is one form method='post'
.. when i click the button Descending or Ascending nothing is happening and i don't know why ? any suggestions?
<form method="post">
<table class="table table-bordered table-striped">
<thead>
<tr>
<th scope='col'>Id</th>
<th scope='col'>Name
<button class="btn btn-info btn-sm dropdown-toggle" type="button" id="dropdownMenuButton" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
Sort by
</button>
<div class="dropdown-menu" aria-labelledby="dropdownMenuButton">
<button name="nameDescending" type="submit" class="dropdown-item btn btn-info">Descending</button>
<button name="nameAscending" type="submit" class="dropdown-item btn btn-info">Ascending</button>
</div>
</th><!-- ORDER BY "name" -->
<th scope='col'>Last</th><!-- ORDER BY "lastname" -->
<th scope='col'>Email</th><!-- ORDER BY "email" -->
<th scope='col'>Telephone</th><!-- ORDER BY "telephone" -->
</tr>
</thead>
<tbody>
<?php
if(isset($_POST['nameDescending'])){
$sql = "SELECT * FROM cust_information ORDER BY name DESC";
}
if(isset($_POST['nameAscending'])){
$sql .= "SELECT * FROM cust_information ORDER BY name ASC";
}
$result = mysqli_query($conn,$sql);
$rowCount = mysqli_num_rows($result);
if($rowCount > 0){
while($row = mysqli_fetch_assoc($result)){
echo "<tr>
<td scope='row'>{$row['auto_id']}</td> <!--difference between class='row' / scope='row'-->
<td>{$row['name']}</td>
<td>{$row['lastname']}</td>
<td>{$row['email']}</td>
<td>{$row['telephone']}</td>
</tr> ";
}
} else{
echo "<tr> <td colspan='5'>Nothing was found!</td> </tr> ";
}
?>
</tbody>
</table>
</form>