I got a client who wants to choose what products are displayed on index.php which is a couchcms managed page. The products are stored in a different database to where couchcms is installed and is using a different platform to couchcms
The products platform is using opencart
Is there any way the products can be chosen by the client so they can choose which products they want to display on the home page?
Below is the current code that I am using to get the products from the opencart database and works
I had a go myself and came up with the following code but I'm getting a blank white page on index.php and the error says "PHP Parse error: syntax error, unexpected end of file
The products platform is using opencart
Is there any way the products can be chosen by the client so they can choose which products they want to display on the home page?
Below is the current code that I am using to get the products from the opencart database and works
- Code: Select all
<?php
require_once 'dbconfig.php';
try {
$pdo = new PDO("mysql:host=$host;dbname=$dbname", $username, $password);
$sql = "SELECT oc_product.product_id, image, name, price FROM oc_product JOIN oc_product_description ON oc_product_description.product_id=oc_product.product_id WHERE oc_product.product_id='55' OR oc_product.product_id='54' OR oc_product.product_id='53' OR oc_product.product_id='52' ORDER BY Name DESC LIMIT 4";
$q = $pdo->query($sql);
$q->setFetchMode(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
die("Could not connect to the database $dbname :" . $e->getMessage());
}
?>
<?php while ($row = $q->fetch()): ?>
<!-- Portfolio Item Start -->
<div class="gallery-item foods">
<div class="item">
<div class="product">
<div class="product-thumb">
<img alt="" src="https://www.domain.co.uk/book-now/image/<?php echo ($row['image']) ?>" style="object-fit: cover;width: 100%;height: 250px;">
<div class="overlay">
<div class="btn-product-view-details">
<a class="btn btn-default btn-theme-colored btn-sm btn-flat pl-20 pr-20 btn-add-to-cart text-uppercase font-weight-700" href="https://www.domain.co.uk/book-now/index.php?route=product/product&path=-1&product_id=<?=$row["product_id"]?>" target="_blank">View details</a>
</div>
</div>
</div>
<div class="product-details text-center">
<a href="https://www.domain.co.uk/book-now/index.php?route=product/product&path=-1&product_id=<?=$row["product_id"]?>"><h5 class="product-title"><?php echo ($row['name']) ?></h5></a>
<div class="price"><ins><span class="amount">£<?php echo number_format($row['price'],2); ?></span></ins></div>
</div>
</div>
</div>
</div>
<!-- Portfolio Item End -->
<?php endwhile; ?>
I had a go myself and came up with the following code but I'm getting a blank white page on index.php and the error says "PHP Parse error: syntax error, unexpected end of file
- Code: Select all
<cms:php>
global $conn;
$servername = 'localhost';
$username = 'username';
$password = 'password';
$dbname = 'databasename';
$conn = new mysqli($servername, $username, $password, $dbname);
if ($conn->connect_error) {
die("Database Connection failed: " . $conn->connect_error);
}
</cms:php>
>
<cms:php>
global $conn;
$sql = 'SELECT oc_product.product_id, image, name, price FROM oc_product JOIN oc_product_description ON oc_product_description.product_id=oc_product.product_id WHERE oc_product.product_id="<cms:show product_id_1/>" OR oc_product.product_id="<cms:show product_id_2/>" OR oc_product.product_id="<cms:show product_id_3/>" OR oc_product.product_id="<cms:show product_id_4/>" ORDER BY Name DESC LIMIT 4';
$result = $conn->query($sql);
</cms:php>
<cms:php>
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
</cms:php>
<!-- Portfolio Item Start -->
<div class="gallery-item foods">
<div class="item">
<div class="product">
<div class="product-thumb">
<img alt="" src="https://www.domain.co.uk/book-now/image/<?php echo ($row['image']) ?>" style="object-fit: cover;width: 100%;height: 250px;">
<div class="overlay">
<div class="btn-product-view-details">
<a class="btn btn-default btn-theme-colored btn-sm btn-flat pl-20 pr-20 btn-add-to-cart text-uppercase font-weight-700" href="https://www.domain.co.uk/book-now/index.php?route=product/product&path=-1&product_id=<?=$row["product_id"]?>" target="_blank">View details</a>
</div>
</div>
</div>
<div class="product-details text-center">
<a href="https://www.domain.co.uk/book-now/index.php?route=product/product&path=-1&product_id=<?=$row["product_id"]?>"><h5 class="product-title"><?php echo ($row['name']) ?></h5></a>
<div class="price"><ins><span class="amount">£<?php echo number_format($row['price'],2); ?></span></ins></div>
</div>
</div>
</div>
</div>
<!-- Portfolio Item End -->
<cms:php>
}
}
</cms:php>
<cms:php>
global $conn;
$conn->close();
</cms:php>