Click to See Complete Forum and Search --> : Random Urls out of txt ?
BigBob
08-02-2003, 04:27 AM
I am new, i have questions, and i want answers ^^
Hope you can help me, ok here is my problem:
I have a site, and i want to have random pics with link as a gallery, but no pic should be dublicated, so -> its would be great if i just could write urls in a txt file, and javascrip splits this img+url links and load them into my page, checking that no pic is two times on my page.
Please tell me if this is possible
Bootsman123
08-02-2003, 06:10 AM
I don't know if you can read text files with Javascript. Don't think so actually. But it can be easily done with PHP.
BigBob
08-02-2003, 06:17 AM
can you please tell me how i can do that or give me a link to a php script that can do that stuff ?
Bootsman123
08-02-2003, 06:29 AM
There are several ways of doing it with an extra file.
resource.php
<?php
$img_array = array ("img1.gif", "img2.gif", "img3.gif", "img4.gif", "img5.gif");
$url_array = array ("url1", "url2", "url3", "url4", "url5");
?>
random_image.php
<?php
@include ('resource.php');
/* Rest of the script. */
?>
For the random script I suggest checking:
http://www.php.net/array-rand
If you want to use a text-file, I suggest checking this:
http://www.php.net/fopen
BigBob
08-02-2003, 07:34 AM
thx, but thats not exactly what i want, i will make an other example:
Url.txt :
-----
<a href="http://url1.de"><img src="http://img1.jpg"></a>
<a href="http://url2.de"><img src="http://img2.jpg"></a>
<a href="http://url3.de"><img src="http://img3.jpg"></a>
<a href="http://url4.de"><img src="http://img4.jpg"></a>
<a href="http://url5.de"><img src="http://img5.jpg"></a>
<a href="http://url6.de"><img src="http://img6.jpg"></a>
-----
Than each Url Tags need to be splited and kicked into and aray variable, for example on the main page :
Picture-links: 'var[1]' , 'var[2]' , 'var[3]', 'var[4]', 'var[5]', 'var[6]'
And i want to load this url tags in random position in my page also no picture link should be dublicated. Is that possible ?
Bootsman123
08-02-2003, 07:47 AM
I still don't get it completely. What do you mean by "Than each Url Tags need to be splited and kicked into and aray variable"?
<?php
$input_array = file ("Url.txt");
/* $array is an array, containing 6 items */
$number_img = 3;
$rand_img = array_rand ($input_array, $number_img);
for ($i = 0; $i < count ($rand_img); $i++)
{
echo $rand_img[$i];
}
?>
BigBob
08-02-2003, 08:34 AM
ok i try to explain ^^
60 img links in a txt file, like this
<a href="http://url1.de"><img src="http://img1.jpg"></a>
<a href="http://url2.de"><img src="http://img2.jpg"></a>
<a href="http://url3.de"><img src="http://img3.jpg"></a>
<a href="http://url4.de"><img src="http://img4.jpg"></a>
<a href="http://url5.de"><img src="http://img5.jpg"></a>
<a href="http://url6.de"><img src="http://img6.jpg"></a>
etc...
The main site shows 30 of 60 img links loaded from the txt randomly, so i have 30 pictures with a link on it
So later i can easy paste my urls in the txt file and the script automaticly list them randomly in the main page, now understand ?
Bootsman123
08-02-2003, 09:32 AM
No, but you can set $number_img to 30, to get 30 random images + link. And if you want to place the images random on the page, check this topic:
http://forums.webdeveloper.com/showthread.php?s=&threadid=14486
And could you provide me with some code of what you've already done, because you can't expect me (or others) to do all the coding for you.
BigBob
08-02-2003, 10:32 AM
my code is in javascript and not loaded out of a txt