Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


Placing Array in Slideshow

Posted on 2013-02-03
Medium Priority
Last Modified: 2013-02-23
Hi all,

I have a bunch of different sentence sequences that I would like to show in slideshow style and I'm wondering the most efficient way to display them on the page.

Here is how I would like it to work. A user selects an exercise from a dropdown and it starts a simple slideshow (taken from a MYSQL DB based on the selection the user makes).. For example, it displays on the page "Sentence 1" and then after 10 seconds this fades out and "Sentence 2" appears. It would just be simple text that would display so I don't need a complex jquery slideshow to do this. Just a script that allows me to put elements from a database into it and then set in the script at what time interval it will move onto the next sentence.

Any advice on the best way to do this would be greatly appreciated. I'm quite familiar with the API for jquery Royalslider for example but I think this would be too complex for what I need here.


Question by:TLN_CANADA
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 3
LVL 11

Accepted Solution

mcnute earned 2000 total points
ID: 38850345
Hello Tld, I think you're working in your phpfox environment and hence with php.
I would do it with ajax in jquery and php in the backend:

url: 'page_which_outputs_your_array.php',
type: 'post',
data: 'option=selected_value',
dataType: 'json',
success: function(dat){

   // pass the values which are already in a json object to the function which executes the text change on your page




function textchange(object){
var i = 0;    
$('.text-container').text(object[i].value); // where value is the name of the database field, to check this check what your json_encode methods throughs out in the console by console.log(dat);
if (i > object.size) {
        i = 0; 

   }, 1000);

Open in new window

On the php page_which_outputs_your_array.php:
// connection to db
// query with post value $option =  $_POST['option'];
// now use json_encode() method to ship the json back to your ajax call

$query = "SELECT * FROM table WHERE option=$option";
$result = mysql_query($query);
echo json_encode($result);  // this is very useful since the data is already prepared to use on your receiving page.

Open in new window


Author Comment

ID: 38850380
Thank you so much mate! This is exactly what I'm after. I'll test this tomorrow and let you know how it goes.
LVL 11

Expert Comment

ID: 38850528
I havn't tested it, so it might have some syntax issues or other issues. Just post back here, I'll help to clear the flaws out.
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!


Author Comment

ID: 38852968
Thanks mcnute, looking at this again I guess my first concern has to be how to best store this information in the DB. I was thinking of storing it in a table with an individual record for each option. Then I could use a delimiter for each individual sentence that would be displayed sequentially. For example a record could be:

Text 1 ; Text 2 ; Text 3;

What do you think about going about it this way?



Author Comment

ID: 38862348
Thanks mcnute, I have integrated the code on the page now. How do I output the function on the page to see if it's working correctly.

Regarding the db, should I put all of the values I want in the one record in the db and use a delimiter or would it be better to put them in separate fields and call the field names sentence_1 sentence_2 sentence_3 etc. ?
LVL 11

Expert Comment

ID: 38863084
I would do a whole table for that with, so that your rows in the table represent your textblocks. That's just what I would do. It would be easier to maintain for my likings.

Author Comment

ID: 38874765
Thanks mcnute,

Here is the table I've created for this. Let me know if this isn't what you intended. If you could show me how to integrate this with what we have here that would be great.

-- phpMyAdmin SQL Dump
-- version 3.5.5
-- Host: localhost
-- Generation Time: Feb 10, 2013 at 09:13 PM
-- Server version: 5.1.66-cll
-- PHP Version: 5.2.6

SET time_zone = "+00:00";

/*!40101 SET NAMES utf8 */;

-- Database: `foxdbmain`

-- --------------------------------------------------------

-- Table structure for table `video_exercises`

CREATE TABLE IF NOT EXISTS `video_exercises` (
  `video_ex_id` int(11) NOT NULL AUTO_INCREMENT,
  `video_ex_title` varchar(35) NOT NULL,
  `block_1` varchar(255) NOT NULL,
  `block_2` varchar(255) NOT NULL,
  `block_3` varchar(255) NOT NULL,
  `block_4` varchar(255) NOT NULL,
  `block_5` varchar(255) NOT NULL,
  `block_6` varchar(255) NOT NULL,
  PRIMARY KEY (`video_ex_id`)

-- Dumping data for table `video_exercises`

INSERT INTO `video_exercises` (`video_ex_id`, `video_ex_title`, `block_1`, `block_2`, `block_3`, `block_4`, `block_5`, `block_6`) VALUES
(1, 'Hakomi Exercise 1 ', 'Slide 1 - H-  Practice ', 'Slide 2 - H 2', 'Slide 3 - H 3', '', '', ''),
(2, 'Hakomi Exercise 2 ', 'Slide 1 of Ex 2 ', 'Slide 2 of Ex 2', 'Slide 2 of Ex 3', '', '', '');


Open in new window

Thanks again,


Author Comment

ID: 38887257
Hi mcnute, would you like me to send you any other information about this? Did I setup the table in the correct format?



Author Comment

ID: 38895887
Hi mcnute,

I just wanted to check in and see if you will be able to assist me in completing this?



Featured Post

Use Filtering Commands to Process Files in Linux

Learn how to manipulate data with the help of various filtering commands such as `cat`, `fmt`, `pr`, and others in Linux.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are a couple ways to attach a JavaScript function to dynamically created elements. You can make a new script for each element as it’s created or you can use delegation. Delegation allows a single script that is added at page creation to mat…
This article discusses how to implement server side field validation and display customized error messages to the client.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

688 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question