Hi,
I am currently having a bit of a problem in work with a PHP code. Here is my code:
This code is incomplete because I need to insert some sort of variable at the top and also complete the if statement on line 84. At first, I had four images on a banner, each of which were picked by a random generator. Each generator has a choice of two images to pick for that particular space.
However, I have since created more random generators ($nrandom5 - $nrandom8). These work in exactly the same way as the first four did, but what I want to do is to be able to load images from $nrandom5 to $nrandom8 on one page, but images from $nrandom1 to $nrandom4 on the other pages.
Basically, I think I need my code to say "if (name of php file), display $image_name5 to $image_name8, else display $image_name1 to $image_name4". My problem is I am not sure how to get PHP to recognise the names of other PHP files. It is probably a simple function but I am relatively inexperienced in PHP and so any help would be appreciated.
I am currently having a bit of a problem in work with a PHP code. Here is my code:
Code:
<?php
$nrandom1 = rand(1,3);
$image_name1 = "image01.jpg";
if ($nrandom1 == 2) {
$image_name1 = "image01.jpg";
}
if ($nrandom1 == 3) {
$image_name1 = "image02.jpg";
}
$nrandom2 = rand(1,3);
$image_name2 = "image03.jpg";
if ($nrandom2 == 2) {
$image_name2 = "image03.jpg";
}
if ($nrandom2 == 3) {
$image_name2 = "image04.jpg";
}
$nrandom3 = rand(1,3);
$image_name3 = "image05.jpg";
if ($nrandom3 == 2) {
$image_name3 = "image05.jpg";
}
if ($nrandom3 == 3) {
$image_name3 = "image06.jpg";
}
$nrandom4 = rand(1,3);
$image_name4 = "image07.jpg";
if ($nrandom4 == 2) {
$image_name4 = "image07.jpg";
}
if ($nrandom4 == 3) {
$image_name4 = "image08.jpg";
}
$nrandom5 = rand(1,3);
$image_name5 = "image09.jpg";
if ($nrandom5 == 2) {
$image_name5 = "image09.jpg";
}
if ($nrandom5 == 3) {
$image_name5 = "image10.jpg";
}
$nrandom6 = rand(1,3);
$image_name6 = "image11.jpg";
if ($nrandom6 == 2) {
$image_name6 = "image11.jpg";
}
if ($nrandom6 == 3) {
$image_name6 = "image12.jpg";
}
$nrandom7 = rand(1,3);
$image_name7 = "image13.jpg";
if ($nrandom7 == 2) {
$image_name7 = "image13.jpg";
}
if ($nrandom7 == 3) {
$image_name7 = "image14.jpg";
}
$nrandom8 = rand(1,3);
$image_name8 = "image15.jpg";
if ($nrandom8 == 2) {
$image_name8 = "image15.jpg";
}
if ($nrandom8 == 3) {
$image_name8 = "image16.jpg";
}
if ...
{
echo "<img src=\"logo.bmp\" border=\"1\" /><img src=\"$image_name5\" border=\"1\" /><img src=\"$image_name6\" border=\"1\" /><img src=\"$image_name7\" border=\"1\" /><img src=\"$image_name8\" border=\"1\" />";
}
else
{
echo "<img src=\"logo.bmp\" border=\"1\" /><img src=\"$image_name1\" border=\"1\" /><img src=\"$image_name2\" border=\"1\" /><img src=\"$image_name3\" border=\"1\" /><img src=\"$image_name4\" border=\"1\" />";
}
?>
However, I have since created more random generators ($nrandom5 - $nrandom8). These work in exactly the same way as the first four did, but what I want to do is to be able to load images from $nrandom5 to $nrandom8 on one page, but images from $nrandom1 to $nrandom4 on the other pages.
Basically, I think I need my code to say "if (name of php file), display $image_name5 to $image_name8, else display $image_name1 to $image_name4". My problem is I am not sure how to get PHP to recognise the names of other PHP files. It is probably a simple function but I am relatively inexperienced in PHP and so any help would be appreciated.
Comment