4
Through PHP, I am listing the MYSQL database records within a WHILE LOOP.
I would like to know how to do so that when clicking on ID, or DATA, the data is displayed in an increasing or decreasing way.
PHP SCRIPT:
<?php
$strSQL = "SELECT * FROM TABELA ORDER BY id DESC";
$rs = mysqli_query($conecta,$strSQL);
$error = mysqli_error($conecta);
if(!$error){
while($row = mysqli_fetch_array($rs)):
?>
<ul class="lista-posts">
<li class="seleciona"><input type="checkbox" id="checkbox" name="deletar[]" value="<?php echo $row['id']; ?> " /></li>
<li class="id"><?php echo $row['id']; ?></li>
<li class="titulo"><?php echo '<a title="'.$row['titulo'].'" class="link-texto" href="artigo-'.$row['slug'].'">'.substr($row['titulo'], 0, 63).'</a>'; ?></li>
<li class="data"><?php echo '<data class="data">'.date('d/m/Y', strtotime($row['data'])).'</data>'; ?></li>
<li class="data"><?php
if($row['id_categoria'] == 'faq') {
$novoIdCategoria = str_replace("faq","duvidas-frequentes",$row['id_categoria']);
echo '<a href="'.$novoIdCategoria.'.php">'.ucfirst("faq").'</a></data>';
} else {
echo '<a href="'.$row['id_categoria'].'.php">'.ucfirst($row['id_categoria']).'</a></data>';
} ?></li>
<li class="gerenciar"><?php
echo '<a title="Ver" class="apagar" href="artigo-'.$row['slug'].'"><label class="icon-eye"></label></a>';
echo '<a title="Editar" class="editar" href="edita.php?id='.$row['id'].'"><label class=" icon-pencil"></label></a>';?>
</li>
</ul>
<?php endwhile; ?>
From now on, thank you!
There are several ways to do this, one would use some grid js to sort the items another is to do a combo or the same link, when clicked it would make a request to php passed two arguments, by which column should be ordered and the orientation (increasing or decreasing)by being done with ajax or normal php request.
– rray
I was confused, as I said below. My default query performs the sort of records decreasing through the ID. How should I make each link trigger a different query?
– Cobra