I would like to display one image at a time on a webpage. I used a query to get a set of images from the database into an array. I have tried along these lines:
$my=& JFactory::getUser();
$db=& JFactory::getDBO();
$a=& $my->id;
$query="SELECT id FROM jos_phocagallery_categories WHERE accessuserid='$a'";
$db->setQuery($query);
$r=$db->loadResult();
$queryc="SELECT filename FROM jos_phocagallery WHERE catid='$r'";
$db->setQuery($queryc);
$results=$db->loadResultArray();
$image=current($results);
echo 'imgag srx="images/phocagallery/'.$image.'" />';
I changed echo line above because the line was not allowed
A开发者_运维知识库fter this code I've tried to add an input button that calls "next($results)" and then replace $image, but it seems the whole query is beeing implemented from the beginning again. So I can't get the pointer of the array to step forward. Not even in an echo.
What Am I doing wrong?
Regards / Viktor
If you are reloading the page to get to the next image, then you are going to need to pass the ID or array key to the next page so it knows where you left off. The other option would be to step through the array without reloading the page, instead using some Javascript to load the next image and replace the current one when the button is clicked.
EDIT
Ok, with that info you will definitely need to use some Javascript to make it work. Even though Joomla comes with Mootools, I prefer jQuery partially due to the availability of plugins to do all sorts of stuff. I didn't look too hard, but this carousel image plugin could be very easily modified to do what you like by simply changing it to display one image at a time instead of three.
http://www.gmarwaha.com/jquery/jcarousellite/index.php
With a little Googling you might even be able to find an exact match.
精彩评论