Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda