Click here to Skip to main content
15,867,888 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am creating a system within our company to upgrade a previous system built to display images on our TV's. I created a form that works where a user enters info such as name, playtime, end_date(when the slide should stop playing), as well as an image. The image gets stored in a folder, the name of the image gets stored in MySQL with the other data. End goal is to make is automatic based on the playtime they submitted.

I've been working on this so when user clicks the button, it displays the first slide in the table. When I click the button again, I anticipate it to move to the next slide which it doesn't. I believe what is going on here is when the post data is sent, n is resetting back to -1 which makes it stay in the same spot, correct me if I am wrong. I'm thinking I need to keep posting 'n'?


<form method="post">
    <input type="submit" name="test" id="test" value="Next Image" /><br/>
</form>

<?php
$n = -1;
    
function SlideShow($n) {
	$n++;
	$conn = mysqli_connect("localhost", "root", "", "tsl_tv_system");
	$image_details  = mysqli_query($conn, "SELECT * FROM slides limit $n,1");
     	while ($row = mysqli_fetch_array($image_details)) {    
	      		echo "<img src='upload/upload/".$row['attachment_loc']."' >";   
     			return $n; 
    }     
}

if(array_key_exists('test',$_POST)){
   SlideShow($n);
}
?>


What I have tried:

I've tried various resources online with no luck.
Posted
Updated 14-Jun-21 5:41am

1 solution

You either need to submit the current slide number to the server - something like this:
PHP
<?php
    function SlideShow($slide){
        $conn = mysqli_connect("localhost", "root", "", "tsl_tv_system");
        $image_details  = mysqli_query($conn, "SELECT * FROM slides limit $slide, 1");
        $row = mysqli_fetch_array($image_details);
        echo "<img src='upload/upload/".$row['attachment_loc']."'>";
    }
    
    $n = isset($_POST['n']) ? intval($_POST['n']) : -1;
?>
<form method="post">
    <input type="hidden" name="n" value="<?= $n >" />
    <input type="submit" name="test" value="Next Image" />
</form>
<?php
    SlideShow($n + 1);
?>
Or output all slides on the first request, and use Javascript to switch between them.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900