I have working code that gets products details and config values from MySQL bit it's combined with HTML, I would like to know a better way to do this, maybe a class that I can use.
<!DOCTYPE html>
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
<?php
require __DIR__ . '/vault/MySQL.php';
$id = ( isset( $_GET['pid'] ) && is_numeric( $_GET['pid'] ) ) ? intval( $_GET['pid'] ) : 0;
if ( $id != 0 ) {
try {
// select all data
// $query = "SELECT product_id, product_title, product_description, product_category, product_image FROM products WHERE product_id = ? LIMIT 1";
$query = "SELECT p.product_id AS product_id, p.product_title AS product_title, p.product_description AS product_description, categories.category_name AS category_name, p.product_category AS product_category, p.product_image AS product_image, p.product_image_thumb AS product_image_thumb FROM products p LEFT JOIN categories ON p.product_category=categories.category_id WHERE p.product_id = ? LIMIT 1";
$stmt = $con->prepare( $query );
$stmt->bindParam(1, $_REQUEST['pid'], PDO::PARAM_INT);
$stmt->execute();
// store retrieved row to a variable
$row = $stmt->fetch(PDO::FETCH_ASSOC);
// values to fill up our form
extract ($row);
} catch (PDOException $exception) { // to handle error
echo "Error: " . $exception->getMessage();
}
}
else {
echo "something went wrong";
}
// select all data
$iQ = "SELECT config_name, config_value FROM config";
$stmt = $con->prepare( $iQ );
$stmt->execute();
while ($row = $stmt->fetch(PDO::FETCH_ASSOC) )
{
$config[$row['config_name']] = $row['config_value'];
}
?>
<head>
<meta charset="utf-8">
<!--[if IE]><meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'><![endif]-->
<title><?php echo $config['frontend_title'] . " - " . $product_title;?></title>
<meta name="description" content="<?php echo "{$product_description}";?>">
...