Hello,

I was wondering if someone could point me in the right direction about the following. I'm showing 4 pictures at a time on a webpage based on a php/mysql-recordset of about 50 records. I could add a next button to move through the pictures, but I'd like to make it move automatically in such a way that every second 1 new picture is shown at the left side and 1 picture is removed at the right side. When the end of the recordset is reached, it starts with #1 again. So basically a slide show with 4 pictures that moves 1 picture every second.

So far code is :

<?php require_once('../Connections/test.php'); ?>
<?php
$maxRows_Recordset1 = 4;
$pageNum_Recordset1 = 0;
if (isset($HTTP_GET_VARS['pageNum_Recordset1'])) {
$pageNum_Recordset1 = $HTTP_GET_VARS['pageNum_Recordset1'];
}
$startRow_Recordset1 = $pageNum_Recordset1 * $maxRows_Recordset1;

mysql_select_db($database_test, $test);
$query_Recordset1 = "SELECT * FROM producten where nieuw='1'";
$query_limit_Recordset1 = sprintf("%s LIMIT %d, %d", $query_Recordset1, $startRow_Recordset1, $maxRows_Recordset1);
$Recordset1 = mysql_query($query_limit_Recordset1, $test) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);

if (isset($HTTP_GET_VARS['totalRows_Recordset1'])) {
$totalRows_Recordset1 = $HTTP_GET_VARS['totalRows_Recordset1'];
} else {
$all_Recordset1 = mysql_query($query_Recordset1);
$totalRows_Recordset1 = mysql_num_rows($all_Recordset1);
}
$totalPages_Recordset1 = ceil($totalRows_Recordset1/$maxRows_Recordset1)-1;
?>

<table width="549" height="100" border="0" cellpadding="0" cellspacing="0">
<tr>

              <td><?php do { ?>
                <img src="../img/thmbnls/<?php echo $row_Recordset1['prodid']; ?>.jpg" alt="<?php echo $row_Recordset1['naam_nl']; ?>" title="<?php echo $row_Recordset1['naam_nl']; ?>" width="96" height="96"> 
                <?php } while ($row_Recordset1 = mysql_fetch_assoc($Recordset1)); ?>
	  </td>

            </tr>

</table>

Cheers,
yousaf FAYYAZ.

    May be totally off the mark here, but it looks like there are two basic ways to do this. One way involves a bit of JavaScript, the other a simple meta tag and possibly an iframe (just thinking easiest solution, maybe not the best).

    :: JavaScript ::

    You can actually have the script load all of the images into the page. For instance, if you use the PHP code to create a list of load_image("../images/blah.jpg"); where load_image() is a JavaScript function that caches (preloads) an image, you could use JavaScript to change the src="../images/blah.jpg" tag of the slideshow. Just have the JavaScript shift the source. I know that's not a very in-depth explanation, but, it points you in the "right" direction.

    :: Meta/IFrame ::

    This one is a bit more reliant on the PHP. Using cookies/sessions/query_line you can use a simple meta tag <meta http-equiv='refresh' content='3;url=page.php'> to force an iframe containing the output of your PHP script to refresh, displaying a new set of 4 pictures. This one would be easier in my mind, but, I love PHP more than I do JavaScript, so I may be a bit biased.

    Hope this helps!

      Thanks for the reply,

      But i am looking some one to debug the php code that i pasted.

      Cheers,
      yousaf FAYYAZ.

        Originally posted by yousaf931
        Thanks for the reply,

        But i am looking some one to debug the php code that i pasted.


        Cheers,
        yousaf FAYYAZ.

        It might help if you tyell us what is not working?

        J.

          I have given the details above the code.

          Cheers,
          yousaf FAYYAZ.

            Ok, so you're asking what needs to be done to the PHP code to allow it to change which pictures are shown on each reload?

              yes u got the point.

              Cheers,
              yousaf FAYYAZ.

                Ah! Well that is an entirely different story. Heh.

                :: PHP! [Got it right this time?] ::

                I touched on this with the IFrame/Meta Tag bit in my earlier post. This is actually fairly simple. If you add something with query line values like: page.php?start_pic=1&end_pic=4 then you'll be able to add that to your MySQL queries:

                SELECT pic_url FROM pictures LIMIT $start_pic, $end_pic

                It'll also make the load on your databases a little easier seeing as you're only getting smaller recordsets. Add some php code like this to start things off:

                  extract ( $_GET, EXTR_OVERWRITE ); //pull the query-line vars into the local namespace
                
                  $start = ($start_pic > 0) ? $start_pic : 1;
                  $end   = (($end_pic > 0) && ($end_pic > $start_pic)) ? $end_pic : 4;
                

                That's the basic idea. You can do it in a much cleaner way I'm sure, but again, you get the idea. Then you just use the $start and $end variables for your LIMIT part, and badda bing badda boom, there's your script. 🙂

                  Write a Reply...