';
/*** set the error reporting attribute ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
if(!isset($_GET['articleID'])){
echo "
Selection of all the articles
";
/*** SQL Query ***/
$query = "select article.name as name, article.price as price, ".
"category.name as category, article.articleID ".
"from article, category ".
"where article.categoryID=category.categoryID";
/*** loop of the results ***/
foreach ($dbh->query($query) as $row)
{
echo "{$row[name]}, ".
"CHF {$row[price]} ({$row[category]})
\n";
}
}
else{
$articleID = $_GET[articleID];
$query = "select article.name as name, article.price as price, ".
"category.name as category, article.articleID, article.description ".
"from article, category ".
"where article.categoryID=category.categoryID ".
"and article.articleID=:articleid ".
"limit 1";
$stmt = $dbh->prepare($query);
/*** bind the paramaters ***/
$stmt->bindParam(':articleid', $articleID, PDO::PARAM_INT);
/*** execute the prepared statement ***/
$stmt->execute();
/*** fetch the results ***/
$result = $stmt->fetchAll();
/*** loop of the results ***/
foreach($result as $row)
{
echo $row['articleID'].', ';
echo $row['name'].', ';
echo $row['price']."
\n";
}
}
/*** close the database connection ***/
$dbh = null;
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>