Mysql, load the wrong one

Asked

Viewed 86 times

0

Hello, in case I add some file here it goes to the end of the list, however I want it to go to the beginning.

Code that performs this

if($sql = mysqli_query($coneccao, "SELECT * FROM arquivos_downloads WHERE nome LIKE '%$palavra_chave%'"))
    {   
        while($linha = mysqli_fetch_array($sql))
        {
            if($i == $linha['id'] || $i != $linha['id'])
            {   
                $arq = $linha['nome'];

                $arq_title = $arq;

                $arq_nome = substr($linha['nome'], 0, 50);
                $arq_nome = str_replace("_", " ", $arq_nome);

                for($icont = 0; $icont <= 10000; $icont++)
                {
                    $arq_nome = str_replace("[".$icont."]", "", $arq_nome);
                    $arq_title = str_replace("[".$icont."]", "", $arq_title);
                }

                $torrent = new Torrent("Uploads/".$arq.".torrent");

        ?>      
                <div id="lista_arquivos_painel">
                    <div id="lista_arquivos_informacoes">
                        <div id="nome_arquivo_div">
                            <span id="nome_arquivo" title="<? echo $arq_title ?>"><b><? echo $arq_nome; ?></b></span>
                        </div>
                        <div id="tamanho_arquivo_div">
                            <span id="tamanho_arquivo" class="informacoes"><b><? echo $torrent->size(2); ?></b></span>
                        </div>
                        <div id="arquivos_arquivo_div">
                            <span id="arquivos_arquivo" class="informacoes"><b>3</b></span>
                        </div>
                        <div id="tempo_arquivo_div">
                            <span id="tempo_arquivo" class="informacoes"><b>9 dias</b></span>
                        </div>
                        <div id="seeds_arquivo_div">
                            <span id="seeds_arquivo" class="informacoes"><b>15234</b></span>
                        </div>
                        <div id="leechs_arquivo_div">
                            <span id="leechs_arquivo" class="informacoes"><b>16785</b></span>
                        </div>
                    </div>

                    <div id="lista_arquivos_botoes" href="#" id="botao_magnet">
                        <div id="botao_magnet_div">
                            <a href="<? echo $torrent->magnet(); ?>" target="_top" id="botao_magnet"><b>MAGNET</b></a>
                        </div>
                        <div id="botao_torrent_div">    
                            <a id="botao_torrent" href="<? echo "baixar.php?arquivo=Uploads/".$arq.".torrent" ?>"><b>.TORRENT</b></a>
                        </div>
                    </div>
                </div>
        <?       
            }
        }
    }
  • Have you tested with ORDER BY nome DESC?

  • I got it all figured out, thanks.

1 answer

1


You can tell Mysql how you want to sort the results. If you use

ORDER BY nome DESC

that is to say: order by the field nome descending order.

The complete query would be

"SELECT * FROM arquivos_downloads WHERE nome LIKE '%$palavra_chave%' ORDER BY nome DESC"
  • Hello, I do not want to arrange alphabetically but by position, the most recent first.

  • @Lucascarezia do you have any field in the comic book with this information? ID? can you sort by this field.

  • 1

    It did, thank you

Browser other questions tagged

You are not signed in. Login or sign up in order to post.