
Membre
|
Bonjours, j'ai un script pour des article ( screen : http://kommunauty.fr/media/image/1142.png / http://kommunauty.fr/media/image/1143.png / http://kommunauty.fr/media/image/1144.png )
mais j'aimerais faire des catégorie ( genre informatique, sport ... ) mais je sais pas comment mis prendre, pouriez vous m'aider svp ?
merci d'avance
EDIT : voici mes code ^^ :
database.php
<?php
// on se connecte a Mysql
$link = mysql_connect( 'localhost', 'username', 'password');
// si on ne se connecte pas ou die l'execution
if (!$link) die('Erreur de connection');
// on selectionne la base de données
mysql_select_db( 'ma_base_de_donnees' , $link );
?>
tuto.php :
<?php
// On appelle le fichier de connexion Mysql
require_once 'database.php';
// On recupere tous les articles
try
{
$sql = mysql_query("SELECT * FROM blog");
// on ferme la connexion MySQL
mysql_close();
if (!$sql) throw new Exception( mysql_error() );
}
catch (Exception $e) { die( $e->getMessage() ); }
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tuto</title>
</head>
<body>
<h1>Liste des articles</h1>
<a href="insert.php">Ajouter une donnée</a>
<?php
// On vérifie qu'il y a bien des articles
if( mysql_num_rows( $sql ) )
//on boucle chaque ligne récupérée
while( $row = mysql_fetch_object( $sql ) )
//on affiche les infos de chaque article
echo '<div><a href="show.php?id='.$row->id.'">'.$row->title.'</a></div>';
else
//message au cas ou il y a pas d'article
echo 'Aucun article';
?>
</body>
</html>
insert.php
<?php
// On appelle le fichier de connexion Mysql
require_once 'database.php';
// On vérifie les infos qu'on reçoit via un POST
if( $_POST && isset($_POST['title']) && isset($_POST['entry']) && $_POST['title'] && $_POST['entry'] )
{
$title = $_POST['title'];
$entry = $_POST['entry'];
// On vérifie si les anti quote sont active sinon on les rajoute
if(!get_magic_quotes_gpc())
{
$title = addslashes($title);
$entry = addslashes($entry);
}
// Pour éviter les injections SQL on protège les valeurs à insérer
$title = mysql_real_escape_string($title);
$entry = mysql_real_escape_string(nl2br($entry));
// On enregistre la ligne dans Mysql
try
{
$sql = mysql_query("INSERT INTO blog (title, entry, date_entered) VALUES ('".$title."','".$entry."', NOW())");
if (!$sql)
throw new Exception( mysql_error() );
// Si aucune erreur on redirige vers la page détail de l'article
else
header('location: show.php?id='.mysql_insert_id());
// on ferme la connexion
mysql_close();
}
catch (Exception $e) { die( $e->getMessage() ); }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tuto</title>
</head>
<body>
<form action="insert.php" method="post" name="form" id="form">
<div>
<label>Titre :
<input type="text" id="title" name="title" value=""/>
</label>
</div>
<div>
<label>Texte :
<textarea name="entry" id="entry"></textarea>
</label>
</div>
<div>
<input type="submit" value="Enregistrer" />
</div>
</form>
</body>
</html>
show.php
<?php
// On appelle le fichier de connexion Mysql
require_once 'database.php';
// On vérifie les infos qu'on reçoit via un GET
if( !isset($_GET['id']) || !($id = $_GET['id']) || !is_numeric($id) )
die('Erreur d\'acces');
// On recupere l'article via son ID
try
{
$sql = mysql_query("SELECT * FROM blog WHERE id = '".(int)$id."' LIMIT 1");
// on ferme la connexion
mysql_close();
if (!$sql) throw new Exception( mysql_error() );
}
catch (Exception $e) { die( $e->getMessage() ); }
// On vérifie qu'il y a bien un article
if( mysql_num_rows( $sql ) )
$row = mysql_fetch_object( $sql );
else
die('Aucune donnee');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Tuto</title>
</head>
<body>
<h1><?php echo $row->title; ?></h1>
<p>Ecrit le : <?php echo $row->date_entered; ?></p>
<p><?php echo $row->entry; ?></p>
<a href="index.php">Revenir au sommaire</a>
</body>
</html>

|
![ipodtouchpro]()
Membre
|
Tu veux faire une sorte de petit forum ???
|

Membre
|
oui enfin une sorte de blog avec des catégori diférente, et quand on écrit un truk, on choisi la catégorie.
|