TUTORIELS 
PHP : Construire un weblog

Page 1 | 2 | 3 | 4

Découvrir comment construire ce type d'application à mi-chemin entre le livre d'or et le gestionnaire de contenu.
 (30 janvier 2004)
 

Viennent ensuite les méthodes de création, de modification et de suppression des notes :

[...]

function set_note()
  {
  $sql = "INSERT INTO jlog_note (note_titre, note_texte, note_date, note_etat) ";
  $sql.= "VALUES ('$this->titre', '$this->texte', '$this->date', '$this->etat');";

  if (mysql_query($sql))
    {
    $this->id = mysql_insert_id();
    }
  else
    {
    $this->id = -1;
    }
  }

function maj_note($id)
  {
  $sql = "UPDATE jlog_note SET ";
  $sql.= "note_titre = '$this->titre', ";
  $sql.= "note_texte = '$this->texte', ";
  $sql.= "note_etat = '$this->etat' ";
  $sql.= "WHERE note_id = '$this->id';";

  if (mysql_query($sql))
    {
    $this->id = mysql_insert_id();
    }
  else
    {
    $this->id = -1;
    }
  }

function suppr_note($id)
  {
  $sql = "DELETE FROM jlog_note ";
  $sql.= "WHERE note_id = '$id';";

  if (mysql_query($sql))
    {
    $this->id = $id;
    }
  else
    {
    $this->id = -1;
    }
  }
}// fin de la classe

Forums
* Discutez en sur les forums

Ces méthodes seront utilisées dans notre administration, dont nous allons voir maintenant la forme et les méthodes:

[fichier admin/index.php]
<?php
require ("../fonctions/global.inc.php");
require ("../fonctions/fonctions.inc.php");

?>
<html>
  <head>
    <title>Administration</title>
  </head>
  <body bgcolor="#FFFFFF">
    <?=affichage();?>
  </body>
</html>

Voici pour la partie "superficielle" de l'administration, voyons maintenant les fonctions, stockées dans fonctions.inc.php...

Il nous faut tout d'abord tester où nous en sommes dans le processus : c'est la fonction affichage() qui se charge de répartir les tâches...

function affichage()
  {
  if ( (isset($_GET['creer'])) && ($_GET['creer'] == "ok") )
    {
    afficherCreer();
    }
  elseif ( ( (isset($_GET['Submit'])) && ($_GET['Submit']=="Valider la note") ) || (isset($_GET['creation'])) )
    {
    validerCreation($_GET['titre'], $_GET['texte'], $_GET['etat'], $_GET['date']);
    }
  elseif ( (isset($_GET['modifier'])) && (is_numeric($_GET['modifier'])) )
    {
    afficherModifier($_GET['modifier']);
    }
  elseif ( (isset($_GET['suppression'])) && (is_numeric($_GET['id'])) )
    {
    validerSuppression($_GET['id']);
    }
  elseif ( ( (isset($_GET['Submit'])) && ($_GET['Submit']=="Modifier la note") ) || (isset($_GET['modification'])) )
    {
    validerModification($_GET['id'], $_GET['titre'], $_GET['texte'], $_GET['etat']);
    }
  else
    {
    afficherAccueil();
    }
  }
[...]

Page 1 | 2 | 3 | 4

 
[ Xavier BorderieJDNet
 
Accueil | Haut de page