Struture de la base de donnée
Posté : 10 avr. 2011, 17:10
Bonjour j'ai télécharger un cours sur le site de developpez.com à cette adresse http://g-rossolini.developpez.com/tutoriels/php/cours/
Mais j'ai beau cherché la structure de la base de donnée de l'exemple d'application (c'est le chapitre 8 du cours). En fait je n'ai pas pu l'obtenir sur le site en question et malgré mes questions sont restées muettes.
Voici le code source consultable également sur le site: http://g-rossolini.developpez.com/tutoriels/php/cours/ merci pour vos précieuses réponses.
Code source:
<!-- PAGE ARTICLE: articles.php -->
Mais j'ai beau cherché la structure de la base de donnée de l'exemple d'application (c'est le chapitre 8 du cours). En fait je n'ai pas pu l'obtenir sur le site en question et malgré mes questions sont restées muettes.
Voici le code source consultable également sur le site: http://g-rossolini.developpez.com/tutoriels/php/cours/ merci pour vos précieuses réponses.
Code source:
<!-- PAGE ARTICLE: articles.php -->
<?php mysql_connect('localhost', 'utilisateur', 'motdepasse');
mysql_select_db('developpez');
function html($string)
{
return utf8_encode(htmlspecialchars($string, ENT_QUOTES));
}
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR">
<head>
<title>G. Rossolini - Articles</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<ul style="text-align: center">
<li style="display: inline"><a href="./" title="G. Rossolini - Tutoriels PHP">Accueil</a> -</li>
<li style="display: inline"><a href="./articles.php" title="G. Rossolini - Liste des publications">Publications</-</li>
<li style="display: inline"><a href="./auteurs.php" title="G. Rossolini - Liste des auteurs">Auteurs</a></li>
</ul>
<?php
if(empty($_GET['id']))
{
?>
<h1 style="text-align: center">Publications</h1>
<?php
$sql = 'SELECT c.id, c.name, COUNT(*) AS nb_articles
FROM category AS c
INNER JOIN article AS a ON a.category_id = c.id
GROUP BY c.id, c.name
ORDER BY c.name';
$db_categories = mysql_query($sql);
while($category = mysql_fetch_assoc($db_categories))
{
?><h2><?php echo html($category['name']); ?></h2><?php
$sql = 'SELECT ar.id, ar.title, au.id AS author_id, au.name AS author_name
FROM article AS ar
INNER JOIN author AS au ON ar.author_id = au.id
WHERE ar.category_id = %d
ORDER BY ar.title';
$db_article = mysql_query(sprintf($sql, $category['id']));
?><ul><?php
while($article = mysql_fetch_assoc($db_article))
{
?><li><a href="./articles.php?id=<?php echo (int)$article['id']; ?>" title="<?
php echo html($article['title']); ?>"><?php echo html($article['title']); ?></a>,
par <a href="./auteurs.php?id=<?php echo (int)$article['author_id']; ?>" title=""><?php echo
html($article['author_name']); ?></a></li><?php
}
?></ul><?php
}
}
else
{
$id = (int)$_GET['id'];
$sql = 'SELECT ar.title, ar.text, au.id AS author_id, au.name AS author_name
FROM article AS ar
INNER JOIN author AS au ON ar.author_id = au.id
WHERE ar.id = %d';
$db_article = mysql_query(sprintf($sql, $id));
if($article = mysql_fetch_assoc($db_article))
{
$article['text'] = utf8_decode($article['text']);
?>
<h1 style="text-align: center"><?php echo html($article['title']); ?></h1>
<div style="text-align: center; font-style: italic">Par <a href="./auteurs.php?id=<?php echo
html($article['author_id']); ?>" title="Publications de <?php echo html($article['author_name']); ?
>"><?php echo html($article['author_name']); ?></a></div>
<?php
echo nl2br(html($article['text']));
}
else
{
echo "Cet article n'existe pas...";
}
}
?>
<p style="text-align: center; font-size: 0.7em;">Copyright Guillaume Rossolini 2007-<?
php echo date('Y'); ?><br />
Contact : <a href="mailto:[email protected]" title="E-mail">[email protected]</a></p>
</body>
</html>
<!-- PAGE auteurs: auteurs.php -->
<?php
mysql_connect('localhost', 'utilisateur', 'motdepasse');
mysql_select_db('developpez');
function html($string)
{
return utf8_encode(htmlspecialchars($string, ENT_QUOTES));
}
?>
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-
strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr-FR" lang="fr-FR">
<head>
<title>G. Rossolini - Publications</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
</head>
<body>
<ul style="text-align: center">
<li style="display: inline"><a href="./" title="G. Rossolini - Tutoriels PHP">Accueil</a> -</li>
<li style="display: inline"><a href="./articles.php" title="G. Rossolini - Liste des publications">Publications</-</li>
<li style="display: inline"><a href="./auteurs.php" title="G. Rossolini - Liste des auteurs">Auteurs</a></li>
</ul>
<?php
if(empty($_GET['id']))
{
?>
<h1 style="text-align: center">Auteurs</h1>
<ul style="list-style-type: none">
<?php
$sql = 'SELECT au.id, au.name, COUNT(*) AS nb_articles
FROM author AS au
LEFT JOIN article AS ar ON ar.author_id = au.id
GROUP BY au.id, au.name
ORDER BY name';
$db_authors = mysql_query($sql);
while($author = mysql_fetch_assoc($db_authors))
{
?><li><a href="./auteurs.php?id=<?php echo (int)$author['id']; ?>" title="<?
php echo html($author['name']); ?>"><?php echo html($author['name']); ?></a> (<?
php echo (int)$author['nb_articles']; ?> articles)</li><?php
}
?>
</ul>
<?php
}
else
{
$id = (int)$_GET['id'];
$sql = 'SELECT name
FROM author
WHERE id = %d';
$db_author = mysql_query(sprintf($sql, $id));
if($author = mysql_fetch_assoc($db_author))
{
?>
<h1 style="text-align: center">Publications de <?php echo html($author['name']); ?></h1>
<ul>
<?php
$sql = 'SELECT id, title
FROM article
WHERE author_id = %d
ORDER BY title';
$db_article = mysql_query(sprintf($sql, $id));
while($article = mysql_fetch_assoc($db_article))
{
?><li><a href="./articles.php?id=<?php echo html($article['id']); ?>" title="Artcle par <?
php echo html($author['name']); ?>"><?php echo html($article['title']); ?></a></li><?php
}
?>
</ul>
<?php
}
else
{
echo "Cet auteur n'existe pas...";
}
}
?>
<p style="text-align: center; font-size: 0.7em;">Copyright Guillaume Rossolini 2007-<?
php echo date('Y'); ?><br />
Contact : <a href="mailto:[email protected]" title="E-mail">[email protected]</a></p>
</body>
</html>