Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi,
I want show images on button's click event one by one.. i am using following piece of code to get name of images stored in a folder... this piece of code displays all images on a page.. but i want to show one image at a time and want to show next on button's click....

the code is

PHP
<?php

$files = glob("MyPP/*.*");

 for ($i=0; $i<count($files)-1; $i++)

 { $num = $files[$i];
 
//I want to call this statement on button's click event
   echo '<img src="'.$num.'" alt="random image" />'."<br /><br />";

 }

?>


Please guide me how i do it...

Thanks in advance
Posted

1 solution

You can't do that in PHP...

PHP runs in the server and has no idea of the client's side.

Clicking a button and reacting to it must be done using forms.

You could do something like:
<form name='FormName' action='PHP_FILE_TO_EXEC.php' method='POST' enctype='application/x-www-form-urlencoded' onsubmit='return JS_FUNCTION();'>

If JS_FUNCTION is never returning TRUE then you will have created an event that will be running in javascript (you'll have called the JS_FUNCTION each time you will press the button.

Another thing you can do is to call the same PHP file you are in but with some parameters passed in the POST...

Hope this helps...
 
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