-1

I'm trying to make a video gallery using blueimp. https://github.com/blueimp Unfortunately I'm not that skilled in MySQL and I'm wondering how I can get the return of a query with youtube URLs into a JavaScript array. Example:

blueimp.Gallery([ { title: 'Sintel', href: 'https://archive.org/download/Sintel/sintel-2048-surround_512kb.mp4', type: 'video/mp4', poster: 'https://i.stack.imgur.com/W8qdL.jpg' }, ...

Thanks already, hope you can help.

Lebon
  • 138
  • 8

1 Answers1

0

You should use the PHP function json_encode() on your array to convert it to a javascript object.

You should do something like what was done here

$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
    $rows[] = $r;
}
print json_encode($rows);

You might need to do some work to assemble the array into the format that you want. Do that within the while loop of the above mentioned code IE:

$sth = mysqli_query("SELECT ...");
$rows = array();
while($r = mysqli_fetch_assoc($sth)) {
    $rows[]['title'] = $r['title'];
    $rows[]['href'] = $r['href'];
}
print json_encode($rows);
Community
  • 1
  • 1
Ding
  • 3,065
  • 1
  • 16
  • 27