Select products and config values from MySQL I have working code that gets product details and config values from a MySQL
database, but it's combined with HTML. Is there a better way to do this, maybe a class that I can use?

&lt;!DOCTYPE html&gt;
&lt;!--[if lt IE 7]&gt;      &lt;html class="no-js lt-ie9 lt-ie8 lt-ie7"&gt; &lt;![endif]--&gt;
&lt;!--[if IE 7]&gt;         &lt;html class="no-js lt-ie9 lt-ie8"&gt; &lt;![endif]--&gt;
&lt;!--[if IE 8]&gt;         &lt;html class="no-js lt-ie9"&gt; &lt;![endif]--&gt;
&lt;!--[if gt IE 8]&gt;&lt;!--&gt; &lt;html class="no-js"&gt; &lt;!--&lt;![endif]--&gt;
&lt;?php
require __DIR__ . '/vault/MySQL.php';

$id = ( isset( $_GET['pid'] ) &amp;&amp; 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-&gt;prepare( $query );
$stmt-&gt;bindParam(1, $_REQUEST['pid'], PDO::PARAM_INT);
$stmt-&gt;execute();

// store retrieved row to a variable
$row = $stmt-&gt;fetch(PDO::FETCH_ASSOC);

// values to fill up our form
extract ($row);

} catch (PDOException $exception) { // to handle error
    echo "Error: " . $exception-&gt;getMessage();
}
    }
else        {
    echo "something went wrong";
    }
// select all data
$iQ = "SELECT config_name, config_value FROM config";
$stmt = $con-&gt;prepare( $iQ );
$stmt-&gt;execute();

while ($row = $stmt-&gt;fetch(PDO::FETCH_ASSOC) )
{
$config[$row['config_name']] = $row['config_value'];
}
?&gt;
&lt;head&gt;
   &lt;meta charset="utf-8"&gt;
   &lt;!--[if IE]&gt;&lt;meta http-equiv='X-UA-Compatible' content='IE=edge,chrome=1'&gt;&lt;![endif]--&gt;
   &lt;title&gt;&lt;?php echo $config['frontend_title'] . " - " . $product_title;?&gt;&lt;/title&gt;
   &lt;meta name="description" content="&lt;?php echo "{$product_description}";?&gt;"&gt;
Several things...

Indentation

This: 

if ( $id != 0 ) {
try {
// etc.
} catch (PDOException $exception) { // to handle error
    echo "Error: " . $exception-&gt;getMessage();
}
    }


Would read easier as such:

if ( $id != 0 ) {
    try {
        // etc.
    } catch (PDOException $exception) { // to handle error
        echo "Error: " . $exception-&gt;getMessage();
    }
}


Comments

Many of your comments are of very little use, when the code speaks for itself. For instance:

    } catch (PDOException $exception) { // to handle error


Or:

// select all data


Or even:

// store retrieved row to a variable


SQL

You will save yourself and Mr. or Ms. Maintainer a good deal of grief if you format your SQL in a way that SQL programmers will be familiar with. For instance this:

$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";


Could instead be: 

$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";


I will say that it is good that you are using PDO. More experienced PHP programmers will hopefully have more to say about PHP code, I'm mostly a SQL guy.