0
<html>
<head>
    <title>Get HTML code from any web page</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/jquery.xdomainajax.js"></script>
    <script src="js/clientJs.js"></script>
    <link rel="stylesheet" href="style.css" type="text/css" media="screen"/>
</head>
<body>
<div class="result"></div>
</body>
</html>

<?php
require_once('../connect.php');
error_reporting(-1);
function number_pad($number, $n)
{
    return str_pad((int)$number, $n, "0", STR_PAD_LEFT);
}

function GetLastChapter($id)
{
    $query = mysql_query("select*from tchapter where id_komik='$id' order by chapter desc limit 0,1") or die(mysql_error());
    $row = mysql_fetch_assoc($query);
    return $row['chapter']+1;
}
$manga_Array = array
(
    array("1","http://www.komikid.com","Naruto",GetLastChapter(1),"18"),
    array("4","http://www.komikid.com","One_Piece",GetLastChapter(4),"18")
);

foreach ($manga_Array as $manga) {
    print_r($manga); echo "<br>";
    $page = 0;
    $now = 1;
    while ($page < $manga[4]) {
        $page = number_pad($now, 2);
        $now++;

        $url = "$manga[1]/$manga[2]/$manga[3]/$page/";
        ?>
        <script>
            var myurl = '<?php echo $url ?>';
            setTimeout(function() {
                getHTMLContent(myurl,<?php echo $manga[0]; ?>,<?php echo $manga[3]; ?>);
            }, <?php echo $now * 5000 ?>);
        </script>
    <?php
    }
}
?>

above there is the code i use for grab image from my site, but i think it cannot work properly, everytime function getHTMLcontent called the url is always the same url. sorry my english not good, i hope you guys understand what i mean.

1
  • @AllenChak : it +1, i get the $page values from $now Commented Dec 11, 2013 at 3:57

2 Answers 2

2

The function called by setTimeout will refer to the same variable "myurl". You can pass your parameter into the function:

<script>
var myurl;

myurl = 'URL 1';
setTimeout(function(url) {
    alert(url);    // 'URL 1'
}, 3000, myurl);

myurl = 'URL 2';
setTimeout(function(url) {
    alert(url);    // 'URL 2'
}, 6000, myurl);
</script>
Sign up to request clarification or add additional context in comments.

Comments

1

You are using global variable of myurl.

<script>
    setTimeout(function() {
        getHTMLContent('<?php echo $url ?>', <?php echo $manga[0]; ?>, <?php echo $manga[3]; ?>);
    }, <?php echo $now * 5000 ?>);
</script>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.