Hi
This is the continuing story of my lock-down project to build a website for my wife's vintage shop!
First, thanks to all who've helped me so far, you've enabled be to make great progress.
I'm in the trial stages and I'm finding that a php file I use to get the stock information from the database for customers to see is taking 6 seconds to load.
The code is shown below.
<!DOCTYPE html>
<html lang = "en-US">
<head>
<meta charset = "UTF-8">
<title>getRailItems.php</title>
</head>
<body>
<?php
//get railID from the html rail file in function getRaiItems()
$railID = filter_input(INPUT_POST, 'railID');
try {
//connect to database
$con= new PDO('mysql:host=localhost;dbname=xxxx', "xxxx", "xxxx");
$con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//create a SELECT statement based on $railID
$stmt = $con->prepare('SELECT stockID, ItemHeadline, ItemDescription, Price_GBP, Postage_GBP FROM stock WHERE rails_railID = ?');
$stmt->execute(array($railID));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($result)){
print "$railID";
print "No matches found";
} else {
foreach($result as $row){
$stockID = $row["stockID"];
$ItemHeadline = $row["ItemHeadline"];
$ItemDescription = $row["ItemDescription"];
$Price_GBP = $row["Price_GBP"];
$Postage_GBP = $row["Postage_GBP"];
print <<< HERE
<div id="itemInfo">
<div id="itemAlphaNum">
<h3>Item Headline</h3> <p>$ItemHeadline</p>
<h3>Item Description</h3> <p>$ItemDescription</p>
<h3>Price(£)</h3> <p>$Price_GBP</p>
<h3>Postage(£)</h3> <p>$Postage_GBP</p>
</div>
</div>
<div id="itemPhotos">
HERE;
$stmt = $con->prepare("SELECT photo FROM photos WHERE `stock_stockID` = ?");
$stmt->execute(array($stockID));
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (empty($result)){
print "$stockID";
print "No photos found";
} else {
foreach($result as $row){
$photo = $row["photo"];
$photoEncoded = base64_encode($photo);
print <<< HERE
<div class="photo"><img src="data:image/jpg;charset=utf8;base64,$photoEncoded"></div>
HERE;
} // end record loop
} // end 'empty results' if
print <<< HERE
</div> <!-- end itemPhotos div -->
HERE;
} // end record loop
} // end 'empty results' if
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
} // end try
?>
</body>
</html>
When I just get text information the load time is a fraction of a second but when I get the images to accompany the text the load time is about 6 seconds.
I've used similar image handling coding for uploading data into the database and found no loading time problems.
I've tried increasing the cache size in the php.ini file to no avail.
If someone has some suggestions for how to proceed I'd be very grateful.
Many thanks
Mike