简体   繁体   中英

Issues with my php table and javascript image slider on the same page

My website image slider works without the php section but with the php section it stops on one picture. I am new to javascript idk how to fix this.Any help will be great thanks in advance.

This is the javascript for the Image slider, works without the php bit.

<script>
    var imagecount = 1;
    var total = 6;



 window.setInterval(function photoA(){
        var image = document.getElementById('image');
        imagecount = imagecount + 1;
        if(imagecount > total){imagecount = 1;}
        if(imagecount < 1){imagecount = total;}
        image.src = "Images/Img"+ imagecount + ".jpg";
        },5000);
      </script>

This is the HTML and I am not sure whether this is the problem or not.

<body onLoad="photoA()"> 
<div id="slider">
<img src="Images/Img.jpg" id="image" >
</div>
<div id="tablearea">
<h1>Video Games</h1>
<h2> Action </h2>

This is the table in the HTML code.

<div id="wrapper">
<table>
        <tr>
            <th width="30%">Game Title</th>
            <th width="10%">Genre</th>
            <th width="10%">Rank</th>
            <th width="15%">Platform</th>
            <th width="10%">Year</th>
            <th width="25%">Publisher</th>
        </tr>

And this is the php which when added to the code the image slider stops.

<?php
    //make the connection
    include 'DB_connect.php';

    //Build our query
    $divisionQuery = "SELECT * FROM  `TABLE 1` WHERE  `Genre` LIKE  'action'";

    //Ask our database our query and display the results
    $results = mysqli_query($conn, $divisionQuery);
    if (!$results) {
        echo 'Could not run query: ' . mysqli_errno();
        exit;
    }

    //Display the results row by row placing them in the table
    while ($row = mysqli_fetch_array($results)) {
        echo "<tr>";
            echo "<td>" . $row['Game Title'] . "</td>";
            echo "<td>" . $row['Genre'] . "</td>";
            echo "<td>" . $row['Rank'] . "</td>";
            echo "<td>" . $row['Platform'] . "</td>";
            echo "<td>" . $row['Year'] . "</td>";
            echo "<td>" . $row['Publisher'] . "</td>";
        echo "</tr>";
}
?>  

Note: php table still shows up when on website with image slider.

<script>
    var imagecount = 1;
    var total = 6;



 window.setInterval(function photoA(){
        var image = document.getElementById('image');
        imagecount = imagecount + 1;
        if(imagecount > total){imagecount = 1;}

        //Problem Is Here, everytime here, imagecount=1; so, it will show that value only. So, check it properly.

        if(imagecount < 1){imagecount = total;}
        image.src = "Images/Img"+ imagecount + ".jpg";
        },5000);
      </script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM