As always you need to break up your task in smaller pieces.
So what do you need to know in order to create a dynamic slideshow for a mobile device?
Well, this is one possible approach:
1. Look for ways to make the page mobile friendly.
"Mobile first" is a buzzword these days, so you can look for that.
BootStrap is one example, see
Bootstrap 3 Tutorial[
^]
2. Learn how to make a static slideshow.
There are many different ways using HTML5 + JavaScript and/or CSS.
Just Google for "How to create a slideshow in HTML5".
3. Figure out how to get the batch of images you want to present.
Well, seem to have that covered with your MySQL queries.
4. Now you can look into how to change the pictures dynamically.
* You can, for example, create the whole or part pf the page using PHP.
This approach is good if you want to show different number of pictures for different users.
* You can choose to change the attributes of existing elements using jQuery.
See
jQuery Set Content and Attributes[
^].
This works well if you always want to show for example 10 pictures.
This is only way way to skin the cat. There are plenty more ways you can choose.