J'ai une base avec des livres, je souhaite réaliser une pagination alphabétique, ceci dit j'ai un blocage dans mon code :
Quelqu'un peut m'aider ?
Code : Tout sélectionner
<?php
$connect = mysqli_connect('localhost', 'root', '', 'mabase');
$char = '';
if(isset($_GET["char"]))
{
$char = $_GET["char"];
$char = preg_replace('#[^a-z]#i', '', $char);
$query = "SELECT * FROM matable WHERE auteur LIKE '$char%'";
}
else
{
$query = "SELECT * FROM matable ORDER BY auteur";
}
$result = mysqli_query($connect, $query);
?>
<!DOCTYPE html>
<html>
<head>
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<br /><br />
<div class="container" style="width:1100px;">
<h2 align="center">Livres</h2>
<br /><br />
<div class="table-responsive">
<div align="center">
<?php
$char = range('A', 'Z');
echo '<ul class="pagination">';
foreach($character as $alphabet)
{
echo '<li><a href="index.php?character='.$alphabet.'">'.$alphabet.'</a></li>';
}
echo '</ul>';
?>
</div>
<table class="table table-bordered">
<tr>
<th width="50%">Auteur</th>
<th width="50%">Titre</th>
</tr>
<?php
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["auteur"]; ?></td>
<td><?php echo $row["titre"]; ?></td>
</tr>
<?php
}
}
else
{
?>
<tr>
<td colspan="3" align="center">Aucun résultat trouvé</td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</body>
</html>