On my frontpage I have a custom block. That block contains an php include. When the page loads, the block fetch some php code and show 10 random images.
I have noticed some differences about how the code/block behaves in D7 and D9.
On my D7 installation I could for example click the home button any time and get 10 new random images.
Not so with D9. Here, if I click the home button nothing happens image wise. It shows the same images, which suggests that the php script is not reloading. Even if I reload the entire page pressing F5 on the keyboard I get the same sequence of images.
To get 10 new random images I have to go to another page, i.e. leave the front page.
The odd thing is that if I return to the front page the same random images are shown as before.
Why is that?
So I created a block: images. It contains an php include:
<?php include 'xxx/xxx/xxx/xxx/xxx/xxx.inc.php'; ?>
Here’s the php code that get the images:
<?php
$servername = "xxx";
$username = "xxx";
$password = "xxx";
$dbname = 'xxx';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT * FROM xxx ORDER BY RAND() DESC LIMIT 15";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
// output data of each row
while($row = mysqli_fetch_assoc($result)) {
echo $row["xxx"];
echo "<br>" . "<br>";
}
} else {
echo "0 results";
}
mysqli_close($conn);
?>