Hai
I have some html files and i would like to display them in a random manner using the php.
can any one help me out..I have been trying this one..
but it is not working..
<?php
$dir="./clock/";
$nimg="10";
$itype="html";
$rnumb=rand(1,$nimg);
echo "<a href=".$dir."clock".$rnumb.".".$itype."></a>";
?>
I have modified your code -
//by speifying this and using in the echo below, all the files in the array should be from this directory only
$dir = "./clock/";
$arr_file_names = array(1=>'my_string.html','my_script.html','new_counntry.html','test.php','test1.php','test2.php','etst2.php','something.php','ejej.php','bored.php');
$number_of_html_files = count($arr_file_names);
$rnumb = ceil(rand(1,$number_of_html_files));
// test the file name with its file path here -
//echo $dir."clock".$arr_file_names[$rnumb];
echo "<a href=".$dir."clock".$arr_file_names[$rnumb]."></a>";
?>
network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
hai pal
this is not displaying any thing..
i have the code changed to this one..
then it is just showing me the link. where as i require the code to display the html file directly
<?php
$dir = "./clock/";
$arr_file_names = array(1=>'clock1.html','clock2.html','clock3.html','clock4.html','clock5.html','clock6.html','clock7.html','clock8.html','clock9.html','clock10.html');
$number_of_html_files = count($arr_file_names);
$rnumb = ceil(rand(1,$number_of_html_files));
// test the file name with its file path here -
//echo $dir."clock".$arr_file_names[$rnumb];
echo "<a href=".$dir."clock".$arr_file_names[$rnumb].">$arr_file_names[$rnumb]</a>";
?>
That means you want to include the file randomly in the page (yes, its called 'include'), so need to use the anchor tags
replace the line10 in above code with the below one -
include(".$dir."clock".$arr_file_names[$rnumb].");
network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
its right, line17 should have been like this -
include("$dir".clock."$arr_file_names[$rnumb]");
network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76
but the only thing is that it is displaying the path as http://localhost/
when i am checking in my machine..
how do i change it to my machine ip
an if i changed it to my ip address it dispalying a big error.
Warning: include() [function.include]: URL file-access is disabled in the server configuration in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17
Warning: include( http://192.168.0.35/chaitu/magpierss/clock/clock9.html ) [function.include]: failed to open stream: no suitable wrapper could be found in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17
Warning: include() [function.include]: Failed opening 'http://192.168.0.35/chaitu/magpierss/clock/clock9.html' for inclusion (include_path='.;C:\Program Files\xampp\php\pear\') in C:\Program Files\xampp\htdocs\chaitu\magpierss\re.php on line 17
dir is chaned to
$dir = "http://192.168.0.35/chaitu/magpierss/clock/";
Its fine if you put the relative path, instead of the absolute one.
Its about how you define the $dir
make it this way -
$dir = "/clock/";
at line3
or else you can set it to the ip too, as below -
$dir = "http://192.168.0.35/chaitu/magpierss/clock/";
include("$dir".$arr_file_names[$rnumb]);
echo "<a href=".$dir.$arr_file_names[$rnumb].">$arr_file_names[$rnumb]</a>";
at line3
network18
Practically a Master Poster
619 posts since Sep 2009
Reputation Points: 29
Solved Threads: 76