Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

109
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!