Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

105
Visualizações
My jQuery's getJSON result is not in order

I have a SQL query which get my playlist ordered by tag and name :
SELECT * FROM playlist WHERE iduser=9 ORDER BY tag,name ASC;

Result :

iduser idplaylist name tag
9 PL74A6S2w9aDA-Gdnhb7b58wRSjYo7t9LK AlphaCast : Table Quest Comedy
9 PL1UBPUKVQV3qV0o9W1Yy0H8krB1IvhC1R AlphaCast : Baldurs gate 3 Gaming
9 PL1UBPUKVQV3oRu-NanDuXxFxMUR1li9XU AlphaCast : The Witcher 3 Gaming
9 PLUUOiZvrsOA-vaRZTFWPPd4Xij_LhmePy Lore Starcraft Gaming

I send this result row by row to a JavaScript function which aims to use the Youtube API and get a JSON for each idplaylist and send this JSON to another JavaScript function.

The problem is that when I use $.getJSON by idplaylist, the JSON I get are not in the same order than the table result above.

The code :

<?php
   $sql = "SELECT * FROM playlist WHERE iduser=? ORDER BY tag,name ASC;";
   mysqli_stmt_bind_param($stmt, "i", $_SESSION["iduser"]);
   mysqli_stmt_execute($stmt);
   $result = mysqli_stmt_get_result($stmt);

   while($row = mysqli_fetch_assoc($result)){
      $playlistid = $row['idplaylist'];
      $playlistname = $row['name'];
      $playlisttag = $row['tag'];
      echo "<script>displayplaylist('$playlistid', '$playlistname', '$playlisttag');</script>";
   }
?>
function displayplaylist(playlistid, playlistname, playlisttag) {
   var key = '';
   var playlistId = playlistid;
   var URL = 'https://www.googleapis.com/youtube/v3/playlistItems';

   var options = {
     part: 'snippet',
     key: key,
     maxResults: 50,
     playlistId: playlistId
   }

   $.getJSON(URL, options function (data) {
     resultplaylist(data, playlistname, playlisttag);
     resultvideos(data, playlistid);               
   });
}
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda