gabriel_vincent
gabriel_vincent

Reputation: 1250

How to successfully reload an included php page?

I have a php page in which I want to include another php page, like this:

<?php
    include ("wrapper.php");
?>

It works just fine, but when I click on a div, which will trigger a javascript function like this:

function reloadNivoSlider () {
    $('#photo-show').fadeOut('slow', function () {
        $("#photo-show").load("nivo-slider/wrapper.php", function () {
            $('#photo-show').fadeIn('slow');
        })
    });
}

The div fades out and fades back in with the nivo slider loading forever. I tried to remove the animations, but the same happens. Could the MySQL request I do in wrapper.php be the reason of the problem? Does it stop the page from reloading? I actually don't know how $().load works, but I presume it reloads the page, right?

The wrapper.php file is:

<body>
<div id="wrapper">

    <div class="slider-wrapper theme-default">
        <div class="ribbon"></div>
        <div id="slider" class="nivoSlider">
            <?php
                mysql_connect(localhost,"root","");
                mysql_select_db("fotos") or die( "Unable to select database");

                $select = "SELECT * FROM 2a_mostra_kineret WHERE id='0';";
                $query = mysql_query($select);
                $row = mysql_fetch_assoc($query);

                $i = 0;

                while ($i <= 7) {
                    $verify = 1;
                    $random = rand(0,7);
                    // First Execution
                    if ($i == 0) {
                        $path[$i] = $row["path"] . $random . ".jpg";
                    }
                    // Other Executions
                    else {
                        while ($verify != 0) {
                            for ($s = 0; $s < $i; $s++) {
                                if ($row["path"] . $random . ".jpg" == $path[$s]) {
                                    $verify++;
                                    break;
                                }
                            }
                            if ($verify > 1) {
                                $random  = rand(0,7);
                                $verify = 1;
                            }
                            else $verify = 0;
                        }
                        $path[$i] = $row["path"] . $random . ".jpg";
                        //echo $random;
                    }
                    $i++;
                }

                for ($i = 0; $i <= 7; $i++) echo "<img src=\"$path[$i]\" alt=\"\" width=\"800\" height=\"600\"/>";

                mysql_close();
            ?>                              

        </div>
        <div id="htmlcaption" class="nivo-html-caption">
            <strong>This</strong> is an example of a <em>HTML</em> caption with <a href="#">a link</a>.
        </div>
    </div>

</div>
<script type="text/javascript" src="scripts/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="../jquery.nivo.slider.pack.js"></script>
<script type="text/javascript">
$(window).load(function() {
    $('#slider').nivoSlider();
});
</script>

Upvotes: 1

Views: 2719

Answers (2)

Rond
Rond

Reputation: 373

No its not possible, ajax is the way. Check links http://api.jquery.com/jQuery.get/ http://api.jquery.com/category/ajax/

Upvotes: 1

Halcyon
Halcyon

Reputation: 57703

Keep in mind that PHP is executed on the server. Once it's sent to the client you can no longer do any PHP. If you want JavaScript to 'fetch' new data from the server you'll have to use AJAX.

Upvotes: 0

Related Questions