PHP Slideshow

OK,

I trying to see if what I'm trying to do is possible. What I'm looking to do is to create a dynamic slideshow using php only. What I'm looking to do is have a Static Header and Footer. I only want the body of the page to change. The body will contain a image on the left hand side  and then on the right hand side the details of the image. The image and details will come from the Mysql database. OK here's is the steps I'm looking to do:

1) Read all records meeting my criteria into an Array.
2) Create a Loop to read through the array one record at a time.
3) Display the record
4) Wait 5 seconds
5) Loop around to read the next record in the array
6) Refresh the display with the new records data

Basically creating an infinite loop until the user intervenes and exits.

If this can be done how would you form the loop process? I have tried and I'm not getting the results I want, what I'm getting is the 2 records I have in the database being displayed at the same time instead of the first record displayed on the screen for 5 seconds then cleared and then the second record being displayed..

Here is what I have so far starting from the beginning of the array.:

// set array
$array = array();

// loop through query
while($row = mysqli_fetch_assoc($result)){
$image_array = explode(',', $row['PhotoUrls']);

  // add each row returned into an array
  $array[] = $row;
  ?>
 <table width="1280" border="1" cellspacing="0" cellpadding="0">
  <tr>
     <td rowspan="12" width="855" height="483"><img src="<?php echo $image_array[0]; ?>" width="855" height="483" /></td>
     <td colspan="2" width="427" align="center"><?php echo $row['Year'] . ' ' . $row['Make'] . ' ' . $row['Model'] . ' ' . $row['Trim'];?></td>
  </tr>
  <tr>
    <td colspan="3" width="427">&nbsp;</td>
  </tr>
  <tr>
    <td width="213">Bodystyle:</td>
    <td width="213"><?php echo $row['Body'];?></td>
  </tr>
  <tr>
    <td width="213">Engine:</td>
    <td width="213"><?php echo $row['EngineSize'];?></td>
  </tr>
  <tr>
    <td width="213">Mileage:</td>
    <td width="213"><?php echo $row['Mileage'];?></td>
  </tr>
  <tr>
    <td width="213">Ext. Color:</td>
    <td width="213"><?php echo $row['OEMColorNameExterior'];?></td>
  </tr>
  <tr>
    <td width="213">Int. Color:</td>
    <td width="213"><?php echo $row['GenericColorInterior'];?></td>
  </tr>
  <tr>
    <td width="213">Stock Number:</td>
    <td width="213"><?php echo $row['StockNumber'];?></td>
  </tr>
  <tr>
    <td colspan="3" width="427">
          <table width="427" border="1" cellspacing="0" cellpadding="0">
              <tr>
                     <td align="center">City MPG<br /><?php echo $row['FuelEconomyCity'];?></td>
                     <td align="center"><img src="#" /></td>
                     <td align="center">Hwy MPG<br /><?php echo $row['FuelEconomyHighway'];?></td>
              </tr>
            </table>
    </td>
  </tr>
  <tr>
    <td colspan="2" width="427">&nbsp;</td>
  </tr>
  <tr>
    <td colspan="2" width="427" align="center">Actual rating vary with options, driving conditions, habits and vehicle condition.</td>
  </tr>
</table>
<?php
sleep(5); //Pause for 5 seconds before looping around
}
?>
rraymond1130Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
For many reasons, javascript is a much better choice for doing slideshows.  First, it doesn't tie up the server like your code does.  Your 5 second wait takes a thousand times longer than the page would otherwise.  If you have a lot of traffic, you could easily run out of available connections to the server, especially if you get it to wait for many more images.  A javascript version runs in the browser after loading all the images and does not take up anymore time on the server after that.
0
rraymond1130Author Commented:
I forgot to mention that I would have this all running on a PC that would be sitting in a corner by itself just running this. Currently I have this running using Javascript. Where it's displaying images I create from Photoshop. I just wanted to create something dynamic that would save me the time of creating the images in Photoshop.
0
Dave BaldwinFixer of ProblemsCommented:
I just wanted to create something dynamic that would save me the time of creating the images in Photoshop.
I don't understand.  PHP isn't going to create the images.  ??  Is the web server on the same machine?

This http://www.dynamicdrive.com/dynamicindex14/fadeinslideshow.htm is the slideshow I use on a number of pages.  I modify it to suit the page and the image sizes.
0
JavaScript Best Practices

Save hours in development time and avoid common mistakes by learning the best practices to use for JavaScript.

rraymond1130Author Commented:
The images will come from the database with the detail information. The webserver will run on the same machine. Php will fetch the data and display it on the screen. I already have that working. It's just the displaying one record at a time is where I'm getting tripped up. I can't seem to make it display record 1 for 5 seconds and then display record 2 for 5 seconds etc.
0
Dave BaldwinFixer of ProblemsCommented:
The easy way is to use META refresh in the web page and just let PHP keep track of the count, maybe in a session variable, and fetch the next data from the database each time.

http://en.wikipedia.org/wiki/Meta_refresh

http://php.net/manual/en/reserved.variables.session.php
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeorgeTowersCommented:
The best choice is jQuery, you can take all the info that is comming from the query and create the slideshow, you can use this plugin for jquery (http://www.slidesjs.com/) or many others you could find on the internet.
0
Dave BaldwinFixer of ProblemsCommented:
George, it turns out that he is loading more than just images.  He is loading a bunch of things from the database.  Although you could do that with jQuery / AJAX, it is more than a standard slideshow will do.
0
Ray PaseurCommented:
Technically, "meta refresh" is no longer compliant with W3C guidelines, but it works in every browser I've used.  So I vote for DaveBaldwin's answer.
http://www.laprbass.com/RAY_temp_rraymond1130.php

<?php // RAY_temp_rraymond1130.php
error_reporting(E_ALL);

// KEEP TRACK OF THE IMAGE HERE, COUNTING FROM ZERO UP TO FOUR
session_start();
$image = isset($_SESSION['image']) ? $_SESSION['image'] : 0;
$image++;
$image = $image % 5;
$_SESSION['image'] = $image;

// SHOW THE IMAGE NUMBER
var_dump($_SESSION);

// THROW THE REFRESH INTO THE BROWSER
echo '<meta http-equiv="refresh" content="5">';

Open in new window

0
Dave BaldwinFixer of ProblemsCommented:
You could also use a javascript timer to reload the page if the META refresh was rejected.  Same principle though.
0
Ray PaseurCommented:
Yes, JavaScript would work, too.  But if it's not a site that requires validation, I wouldn't worry about the meta tag.  I think you nailed it.
0
rraymond1130Author Commented:
Hey Guys,

Good morning. I see where you are coming from with the refresh that seems as though that will work, but the image and detailed information  will be read from an Array that I write the records into from my database. How can that be incorporated into the code above?
0
Dave BaldwinFixer of ProblemsCommented:
I wouldn't do that.  I would just get the next record each time and forget the array.
0
Ray PaseurCommented:
Since the PHP session will contain a counter that gets incremented, you can SELECT the information you want to display FROM your database.table ORDER BY (whatever) and use a LIMIT clause to choose the next data element in the ORDER BY clause.

<?php // RAY_temp_rraymond1130.php
error_reporting(E_ALL);

// KEEP TRACK OF THE IMAGE HERE, COUNTING FROM ZERO UP TO FOUR
session_start();

// START WITH A VALUE OF ZERO
$image = isset($_SESSION['image']) ? $_SESSION['image'] : 0;
$image++;

// MODULO 5 GETS INTEGER REMAINDER
$image = $image % 5;

// STORE THE VALUE FOR NEXT TIME
$_SESSION['image'] = $image;

// ACTIVATE THIS TO SHOW THE IMAGE NUMBER
// var_dump($_SESSION);

// CREATE A QUERY (SKELETON) USING EITHER "WHERE" OR "ORDER" TO CHOOSE THE IMAGE
// SEE http://dev.mysql.com/doc/refman/5.7/en/select.html
$sql = "SELECT image, info FROM database.table ORDER BY column LIMIT $image, 1";
echo PHP_EOL . $sql;

// THROW THE REFRESH INTO THE BROWSER
echo '<meta http-equiv="refresh" content="5">';

Open in new window

0
rraymond1130Author Commented:
Hey Guys hope you had a good weekend. As usual your solutions worked like a charm.
0
Dave BaldwinFixer of ProblemsCommented:
Good, glad to help.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.