Trouble displaying random images on my front page

Trouble displaying random images on my front page.

The front page is “index.php”.

I am trying to adorn my front page with randomly selected images.
The images are listed in a text file: “actresses.txt”.
The images are jpg and are stored in the folder “actresses”.
What is supposed to happen is the image is replaced each time the page is refreshed.

The first code block should make the selection and then draw the image.
But it does not happen … Must be a syntax confusion.

The sequence should go thus …
1 Load the list into $pix
2 Make a random number from 1 to 779
3 Assign it to $i
4 Find the image title in the $i position in the list
5 Load the image from the actresses’ folder
6 Display it

[php]

<?php $pix=file("actresses.txt"); mt_srand(); $i=mt_rand (1,779); $pic=$pix[$i]; echo ''; ?>

[/php]
The second block adds the title of the image.
This block, happily, does work.
[php]<?php
$x=strlen($pic)-9;
$tit=substr($pic,0,$x);
echo $tit;
?>[/php]

Thank you for your kind attention :slight_smile:

Can you look at the source of the web page and post back with what PHP generated (the image tag you’re echoing).

Thank you for your help :-))
I’ve got it working now, with this code …

[php]<?php
$pix=file(‘images.txt’);
mt_srand();
$i=mt_rand (1,779);
$pic=$pix[$i];
echo ‘<img src=’ . chr(34) . ‘images/’ . $pic . chr(34) . ‘width=“100%”’ . ‘/>’;

// managed to add the width :slight_smile:

// $x=strlen($pic)-9;
// $tit=substr($pic,0,$x);
// decided not to add the name.
?>[/php]

You can see the result at julianbury.net

Now I just have to choose the right pictures …

Thank you again :smiley:

[size=36pt]font=times new roman[/font][/size]

Sponsor our Newsletter | Privacy Policy | Terms of Service