Jump to content

help with ajax slidshow from Mysql DB


niceguy82

Recommended Posts

hello guys this is my first post to your forum i hope that you can help me with my problem

 

i have that script to take last images added to mysql database and slidshow in main page with intrval 10 second

but there is a problem with code it's show first image and after 10 second it show up all the other images in one time

here i'll post you the code i have

the first file slideshow.php

<html>
<head>
<script language="javascript">
function jah_switch(url,target)
{

    if (document.getElementById(target).innerHTML != '')
    {
        document.getElementById(target).innerHTML = '';
    }
    else
    {

        jah(url,target);
    }

}
function Switch(url,target) {
    // native XMLHttpRequest object
        
    if (window.XMLHttpRequest) {
        req = new XMLHttpRequest();
        req.onreadystatechange = function() {jahDone(target);};
        req.open("GET", url, true);
        req.send(null);
    // IE/Windows ActiveX version
    } else if (window.ActiveXObject) {
        req = new ActiveXObject("Microsoft.XMLHTTP");
        if (req) {
            req.onreadystatechange = function() {jahDone(target);};
            req.open("GET", url, true);
            req.send();
        }
    }
}    

function jahDone(target) {
    // only if req is "loaded"
    if (req.readyState == 4) {
        // only if "OK"
        if (req.status == 200) {
            results = req.responseText;
            document.getElementById(target).innerHTML = results;
        } else {
            document.getElementById(target).innerHTML="خطأ:\n" +
                req.statusText;
        }
    }
}
</script>
</head>
<body>
<?php

require('config.php');


echo '<div id="photo_show">';

$get_phos = mysql_query ("select Car_pic from car order by Car_id desc LIMIT 10");

$phos= mysql_fetch_array($get_phos);


echo '<img width="200" src="'.$phos['Car_pic'].'" />';


echo '</div>';


// echo "<script>setInterval('switch(\'photo_show.php\', \'photo_show\')', 10000);</script>";  

echo "<script>setInterval('Switch('photo_show.php', 'photo_show\)', 10000);</script>";  

?>
</body>
</html> 

 

and the second file photo_show.php

<?php
include('config.php');
$get_phos = @mysql_query ("select Car_pic from car order by Car_id desc LIMIT 10") or trigger_error(mysql_error(),E_USER_ERROR);
while($phos = @mysql_fetch_array($get_phos))
{
   echo '<img width="200" src="'.$phos['Car_pic'].'" />';
}  
?> 

 

 

 

and this the output of code on the server

http://www.2worldshopping.com/test/slidshow.php

 

Link to comment
https://forums.phpfreaks.com/topic/201172-help-with-ajax-slidshow-from-mysql-db/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.