Page 1 sur 1

[Besoin d'aide] Réalistation d'un module de propagande

Posté : 23 août 2010, 17:22
par Titiii
Bonjour à tous !

Aujourd'hui je me lance dans la réalisation d'un module de propagande.

Le but de ce module est de faire défiler des phrases enregistrées par les membres du site.

Requis :
-Un site avec connexion de membres
-Une table dans la base de données
-Un module d'ajout de texte accessible pour les membres
-Un module de modération accessible pour le staff
-Le header contenant le script.

La base de données :
  • id Le numéro du message
  • pseudo Le nom du membre qui a posté le message
  • message Le message
Les module d'ajout de texte et de modérations seront faits par la suite, le principal (et plus dur) consistant à faire le script.

Le header : (Donc affiché sur chaque page)
<div id="conteneur">

<div id="header"><!--Début Du Menu Horizontal --> 
<a id="bouton1" href="index.php"></a>
<a id="bouton2" href="phpBB3"></a> 
<a id="bouton3" href="contact.php"></a>
<div id="texte"> <!-- Divers options et boutons contenus dans le header -->
<br />
  Bienvenue sur mon site
  <?php
  if ($_SESSION['connecter'] == 1)
  {
  echo $_SESSION['pseudo'];
  }
  else
  {
  echo Visiteur;
  }
  ?> <br />   
</div>




<!-- Fin Du Menu Horizontal --></div>
	<?php include("connexion_bdd.php"); ?> <!-- Connexion à la base de données -->
<h3><marquee> <!-- Balise pour faire bouger le texte -->
<?php $result = mysql_query("SELECT * FROM propagande"); <!-- Requète SQL -->
$numQuestion = mysql_num_rows($result);
$prendreAPartirDeLa = $numQuestion - 10; <!-- Ceci est pour prendre les dix derniers messages -->
$resultat = mysql_query("SELECT * FROM propagande ORDER BY id DESC LIMIT "$prendreAPartirDeLa", 10") <!-- Erreur affichée ici : Parse error: syntax error, unexpected T_VARIABLE in /home/leoserveur/www/heberg/fragefun/header.php on line 31 surement à cause de la variable, mais je ne sais pas comment faire autrement :S --> 
<!-- Affichage de la requète -->
echo ""$resultat['pseudo']""$resultat['message']"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
?>
<!-- Il faudrait faire en sorte que le message s'affiche sous la forme : " Titiii (Lien cliquable vers le profil) : Je trouve ce site super !                                                         Tomtom (Lien cliquable vers le profil) : Moi aussi ! :)                                                                        Mopan : etc...
</marquee> </h3>



<?php mysql_close(); ?>

Voilà, alors ce code ne marche pas, mais pouvez vous m'aider à trouver des solutions pour la faire marcher ? Merci beaucoup d'avance.

Cordialement Titiii

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 23 août 2010, 22:18
par AB
Y'a une solution qui défile beaucoup mieux que marquee sur ce lien vos-contributions/objet-defilant-javasc ... 51015.html
Tu peux alimenter facilement le défilant avec du texte et des liens provenant d'une base de donnée. Il faut juste remplacer les espaces du texte par des espaces insécables.
$lien = 'http://forum.phpfrance.com/';
$texte = str_replace(' ','&nbsp;'$texte);
$chaine = '<a class="liens" href="'.$lien.'">'.$texte.'</a>';
et tu insères $chaine ou plusieurs $chaine dans le code html de l'objet défilant comme dans les exemples.

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 24 août 2010, 14:11
par Titiii
Désolé, je ne comprend pas =S

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 24 août 2010, 19:28
par AB
Qu'est-ce que tu ne comprend pas ?

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 26 août 2010, 10:01
par Titiii
Ben je ne fait pas de java quoi...

En fait, ce que j'ai besoin de savoir c'est comment prendre les dix derniers résultats de la base de donnée et les afficher en mettant le pseudo et le message du premier des dix, des espaces, le pseudo et le message du second des dix, des espaces...

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 26 août 2010, 10:32
par sylvaing26
En fait ce que AB te propose c'est non seulement la mise en forme graphique (grace à java) mais aussi la récupération des données défilantes (avec PHP)

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 26 août 2010, 18:00
par AB
Ah c'est le code php que tu ne sais pas faire ? Un exemple avec la fonction dont je t'ai parlé qui est beaucoup plus paramétrable que la balise marquee et qui défile mieux :
<?php include("connexion_bdd.php");

//si on travaille en utf-8
header('Content-type: text/html; charset=UTF-8');
mysql_query("SET NAMES 'utf8'");

// requête
$query = "SELECT * FROM propagande ORDER BY id DESC LIMIT 10";

$ressource = mysql_query($query) or die(mysql_error());

function Caract_insecable($var)
{
	$cible = array(' ','-');
	$desti = array('&nbsp;','&#8209;');
	
	return str_replace($cible,$desti,$var);
}

$chaine = array();


while ($resultat = mysql_fetch_assoc($ressource))
{
	//$lien = 'http://forum.phpfrance.com/';
	$lien = $resultat['lien'];
	
	$pseudo = Caract_insecable($resultat['pseudo']);
	$message = Caract_insecable($resultat['message']);

    $chaine[] = '<a href="'.$lien.'">'.$pseudo.'</a>&nbsp;:&nbsp;'.$message;
}
$total_chaine = implode('&nbsp;&nbsp;&nbsp;&nbsp;',$chaine);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>

<script type="text/javascript">
<!--

function DF_ObjetDefilant(id,larg_d,mode,sens,vit,pos,b_esp,pause)
{
       
        this.DF_ObjetParam = typeof this.DF_ObjetParam == 'undefined' ? new Array() : this.DF_ObjetParam;      
        this.DF_ObjetParam[id] = typeof this.DF_ObjetParam[id] == 'undefined' ? new Array() : this.DF_ObjetParam[id];  
       
        if(typeof this.DF_ObjetParam[id]['id_defile'] == 'undefined') Set_param (id,larg_d,mode,sens,vit,pos,b_esp,pause);
       
        if (this.DF_ObjetParam[id]['largeur_def'] > 0 && this.DF_ObjetParam[id]['largeur_cadre'] > 0)
        {
                if (this.DF_ObjetParam[id]['mode'] == 'r') Boucle_ar(id); else Boucle_cont(id);
         
                this.DF_ObjetParam[id]['Timer'] = setTimeout(function(){DF_ObjetDefilant(id)},this.DF_ObjetParam[id]['delaicrnt']);    
        }
       
       


        function Set_param (id,larg_d,mode,sens,vit,pos,b_esp,pause)
        {
       
        var id_d = null;
        var id_c = null;
       
        if(!(id_d = document.getElementById(id)))  id_d = null; else if(!(id_c = document.getElementById(id_d.parentNode.id))) id_c = null;
       
       
        if(id_c != null && id_d != null && id_d.hasChildNodes())
       
                {
                        id_c.style.position = "relative";
                       
                        id_c.style.overflow = "hidden";
                                       
       
                        id_d.style.position = "absolute";
                       
                        id_d.width = "auto";
                       
                               
                        this.DF_ObjetParam[id]['largeur_def'] = id_d.offsetWidth;
                               
                        var div_defile = id_d.cloneNode(true); 
                       
                        var nb_noeud = id_c.childNodes.length;
                                                       
                        for (var i = 0; i < nb_noeud ; i++) id_c.removeChild(id_c.firstChild);
                       
                       
                        var largeur_cadre = document.createElement("div");
                       
                        id_c.appendChild(largeur_cadre);       
                       
                        this.DF_ObjetParam[id]['largeur_cadre'] = largeur_cadre.offsetWidth;
                       
                        id_c.removeChild(id_c.firstChild);
                       
               
                        id_c.appendChild(div_defile);
       
       
                        this.DF_ObjetParam[id]['id_defile'] =   document.getElementById(id);
                       
               
                        this.DF_ObjetParam[id]['largeur_def'] = larg_d == 'auto' ? this.DF_ObjetParam[id]['largeur_def'] : parseInt(larg_d);
                       
                        this.DF_ObjetParam[id]['id_defile'].style.width = this.DF_ObjetParam[id]['largeur_def']+'px';                  
                       
                        this.DF_ObjetParam[id]['mode'] = typeof mode != 'undefined' && (mode == 'r' || mode == 'b') ? mode : 'b';
                       
                        this.DF_ObjetParam[id]['sens_ini'] = typeof sens != 'undefined' && (sens == 'g' || sens == 'd') ? sens : 'g';
                       
                        this.DF_ObjetParam[id]['vitesse'] = typeof vit != 'undefined' && parseInt(vit) > 0 ? parseInt(vit) : 20;
               
                        this.DF_ObjetParam[id]['psinit'] = typeof pos != 'undefined' && parseFloat(pos) > 0 ? parseFloat(pos) : 0;
                       
                        this.DF_ObjetParam[id]['b_esp'] = typeof b_esp != 'undefined' && parseFloat(b_esp) > 0 ? parseFloat(b_esp) : 0;        
                       
                        this.DF_ObjetParam[id]['pause'] = typeof pause != 'undefined' && parseInt(pause) > 0 ? parseInt(pause) : 0;
                       
                       
               
                        this.DF_ObjetParam[id]['b_esp'] = this.DF_ObjetParam[id]['b_esp'] < 0  || this.DF_ObjetParam[id]['b_esp'] > 100 ? 0 : Math.ceil(this.DF_ObjetParam[id]['b_esp'] * this.DF_ObjetParam[id]['largeur_cadre']/100);
                       
               
                        this.DF_ObjetParam[id]['psinit'] = this.DF_ObjetParam[id]['psinit'] == 100 || this.DF_ObjetParam[id]['psinit'] < 0 || this.DF_ObjetParam[id]['psinit'] > 100 ? this.DF_ObjetParam[id]['largeur_cadre'] : Math.ceil(this.DF_ObjetParam[id]['psinit']*this.DF_ObjetParam[id]['largeur_cadre']/100);              
                       
                        this.DF_ObjetParam[id]['psinit'] = (this.DF_ObjetParam[id]['largeur_cadre'] > this.DF_ObjetParam[id]['largeur_def'] &&  this.DF_ObjetParam[id]['psinit'] == 0 ) ? this.DF_ObjetParam[id]['largeur_cadre'] - this.DF_ObjetParam[id]['largeur_def'] : this.DF_ObjetParam[id]['psinit'];
                       
                       
                        this.DF_ObjetParam[id]['pscrnt'] = this.DF_ObjetParam[id]['psinit'];
                       
                        this.DF_ObjetParam[id]['sens'] = 1;
               
               
                        this.DF_ObjetParam[id]['p_retour'] = this.DF_ObjetParam[id]['largeur_def'] >= this.DF_ObjetParam[id]['largeur_cadre'] ? this.DF_ObjetParam[id]['largeur_def'] - this.DF_ObjetParam[id]['largeur_cadre'] : 0;
                       
                       
                        this.DF_ObjetParam[id]['largeur_def'] += this.DF_ObjetParam[id]['b_esp'];                                              
                                                                       
               
                        this.DF_ObjetParam[id]['p_retour'] = this.DF_ObjetParam[id]['mode'] == 'b' ? this.DF_ObjetParam[id]['largeur_def'] : this.DF_ObjetParam[id]['p_retour'];
                       
               
                        if (this.DF_ObjetParam[id]['mode'] == 'r' && this.DF_ObjetParam[id]['largeur_def'] == this.DF_ObjetParam[id]['largeur_cadre'] && this.DF_ObjetParam[id]['psinit'] == 0) this.DF_ObjetParam[id]['largeur_def'] = 0;
               
                               
                        if (this.DF_ObjetParam[id]['largeur_def'] > 0 && this.DF_ObjetParam[id]['mode'] == 'b') Ajout_clone(id);
                       
                        id_c.style.visibility = "visible";
                       
                }
        }




        function Ajout_clone(id)
        {              
       
                           var div_contenu = document.createElement("div");
               
                           var nb_noeud = this.DF_ObjetParam[id]['id_defile'].childNodes.length;
                 
                           for (var i = 0; i < nb_noeud ; i++)
                           
                                   {                               
                                        div_contenu.appendChild(this.DF_ObjetParam[id]['id_defile'].firstChild.cloneNode(true));
                                        this.DF_ObjetParam[id]['id_defile'].removeChild(this.DF_ObjetParam[id]['id_defile'].firstChild);
                                   }
                           
                           
                           if (this.DF_ObjetParam[id]['b_esp'] > 0)
                           
                                   {       
                                        this.DF_ObjetParam[id]['sens_ini'] == 'g' ? div_contenu.style.marginRight = this.DF_ObjetParam[id]['b_esp']+'px' : div_contenu.style.marginLeft = this.DF_ObjetParam[id]['b_esp']+'px';  
                                   }
                                               
                           div_contenu.style.display = "inline";
                                   
                           this.DF_ObjetParam[id]['id_defile'].appendChild(div_contenu.cloneNode(true));
                                                       
                           var nb_clone = Math.ceil(this.DF_ObjetParam[id]['largeur_cadre']/(this.DF_ObjetParam[id]['largeur_def']));  
                                   
                           this.DF_ObjetParam[id]['id_defile'].style.width = ((nb_clone+1) * this.DF_ObjetParam[id]['largeur_def'])+'px';
                           
                           for (var j = 0; j < nb_clone ; j++)
                           
                                   {     
                                        this.DF_ObjetParam[id]['id_defile'].appendChild(this.DF_ObjetParam[id]['id_defile'].firstChild.cloneNode(true));    
                                   }
        }




        function Boucle_cont(id)
        {
                this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['vitesse'];
                this.DF_ObjetParam[id]['inverse'] = 1;
       
       
                if(this.DF_ObjetParam[id]['pscrnt'] == - this.DF_ObjetParam[id]['p_retour'])
                               
                                {                                      
                                this.DF_ObjetParam[id]['id_defile'].appendChild(this.DF_ObjetParam[id]['id_defile'].firstChild.cloneNode(true));  
                                this.DF_ObjetParam[id]['id_defile'].removeChild(this.DF_ObjetParam[id]['id_defile'].firstChild);
                                 
                                this.DF_ObjetParam[id]['inverse'] = -1;
                                       
                                this.DF_ObjetParam[id]['pscrnt'] = 0;
                               
                                this.DF_ObjetParam[id]['sens'] = -1;           
                                }
                               
                                else
                               
                                {
                                if(this.DF_ObjetParam[id]['pscrnt'] == this.DF_ObjetParam[id]['psinit'])
               
                                        {
                                        this.DF_ObjetParam[id]['sens'] *= -1;
                                        this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['pause'];
                                        }
                                }
                               
               
                         this.DF_ObjetParam[id]['sens_ini'] == 'g' ? this.DF_ObjetParam[id]['id_defile'].style.left = this.DF_ObjetParam[id]['pscrnt']+"px" : this.DF_ObjetParam[id]['id_defile'].style.right = this.DF_ObjetParam[id]['pscrnt']+"px" ;
                         
                        this.DF_ObjetParam[id]['pscrnt'] += this.DF_ObjetParam[id]['sens'];
       
        }
       
       
       
       
function Boucle_ar (id)
        {
                this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['vitesse'];
                this.DF_ObjetParam[id]['inverse'] = 1;
               
                if(this.DF_ObjetParam[id]['pscrnt']  == - this.DF_ObjetParam[id]['p_retour'] || this.DF_ObjetParam[id]['pscrnt'] == this.DF_ObjetParam[id]['psinit'])
                        {
                        this.DF_ObjetParam[id]['inverse'] = -1;
                        this.DF_ObjetParam[id]['delaicrnt'] = this.DF_ObjetParam[id]['pause'];
                        this.DF_ObjetParam[id]['sens'] *= -1;
                        }
                       
                this.DF_ObjetParam[id]['sens_ini'] == 'g' ? this.DF_ObjetParam[id]['id_defile'].style.left = this.DF_ObjetParam[id]['pscrnt']+"px" : this.DF_ObjetParam[id]['id_defile'].style.right = this.DF_ObjetParam[id]['pscrnt']+"px" ;
               
                this.DF_ObjetParam[id]['pscrnt'] += this.DF_ObjetParam[id]['sens'];
        }

}




function DF_ObjetNavigMous(id,etat)
{
        if(typeof this.DF_ObjetParam != 'undefined' && typeof this.DF_ObjetParam[id] != 'undefined' && this.DF_ObjetParam[id]['id_defile'] != null && typeof this.DF_ObjetParam[id]['Timer'] == 'number')
                {
                clearTimeout(this.DF_ObjetParam[id]['Timer']);
                if (etat == 'out') DF_ObjetDefilant(id);
                }
}




function DF_ObjetSensInverse(id)
{
if(typeof this.DF_ObjetParam != 'undefined' && typeof this.DF_ObjetParam[id] != 'undefined' && this.DF_ObjetParam[id]['id_defile'] != null && typeof this.DF_ObjetParam[id]['Timer'] == 'number' && this.DF_ObjetParam[id]['inverse'] == 1 && !(this.DF_ObjetParam[id]['pscrnt']  == - this.DF_ObjetParam[id]['p_retour'] || this.DF_ObjetParam[id]['pscrnt'] == this.DF_ObjetParam[id]['psinit'])) this.DF_ObjetParam[id]['sens'] *= -1;      
}




function addLoad_DF_ObjetDefilant(func) {

                if (window.addEventListener)
                {
                        window.addEventListener("load", func, false);
                }
       else if (document.addEventListener)
                {
                        document.addEventListener("load", func, false);
                }
       else if (window.attachEvent)
                {
                        window.attachEvent("onload", func);
                }
}

-->
</script>


<style type="text/css">
<!--
#cadre_texte {
        position: relative;
        width:560px;
        height:25px;
        border-top: 1px solid #CCCCCC;
        border-bottom: 1px solid #CCCCCC;  
        margin: 2em auto 0 auto;
        padding-top:2px;
        overflow: hidden;
        font-family:Arial, Helvetica, sans-serif;
        font-size:12px;
        color: #003399;
        visibility:hidden;
}
-->
</style>

<script type="text/javascript">
<!--
addLoad_DF_ObjetDefilant(function(){DF_ObjetDefilant('texte_defilant','auto','b','g','12','100','30','500')});
-->
</script>
</head>

<body>
<div id = "cadre_texte">
<div id = "texte_defilant"  onmouseover = "DF_ObjetNavigMous('texte_defilant','over')"  onmouseout = "DF_ObjetNavigMous('texte_defilant','out')"><?php echo $total_chaine?></div>
</div>


</body>
</html>
Bon le premier bloc de code javascript encombre un peu la page mais rien ne t'empêche de le mettre dans un fichier séparé, par exemple nommé objetdefilant.js et de faire ensuite juste un lien de type <script type="text/javascript" src="objetdefilant.js"></script> ce qui donnerait
<?php include("connexion_bdd.php");

//si on travaille en utf-8
header('Content-type: text/html; charset=UTF-8');
mysql_query("SET NAMES 'utf8'");

// requête
$query = "SELECT * FROM propagande ORDER BY id DESC LIMIT 10";

$ressource = mysql_query($query) or die(mysql_error());

function Caract_insecable($var)
{
        $cible = array(' ','-');
        $desti = array('&nbsp;','&#8209;');
       
        return str_replace($cible,$desti,$var);
}

$chaine = array();


while ($resultat = mysql_fetch_assoc($ressource))
{
        //$lien = 'http://forum.phpfrance.com/';
        $lien = $resultat['lien'];
       
        $pseudo = Caract_insecable($resultat['pseudo']);
        $message = Caract_insecable($resultat['message']);

    $chaine[] = '<a href="'.$lien.'">'.$pseudo.'</a>&nbsp;:&nbsp;'.$message;
}
$total_chaine = implode('&nbsp;&nbsp;&nbsp;&nbsp;',$chaine);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans titre</title>

<script type="text/javascript" src="objetdefilant.js"></script>

<style type="text/css">
<!--
#cadre_texte {
        position: relative;
        width:560px;
        height:25px;
        border-top: 1px solid #CCCCCC;
        border-bottom: 1px solid #CCCCCC;  
        margin: 2em auto 0 auto;
        padding-top:2px;
        overflow: hidden;
        font-family:Arial, Helvetica, sans-serif;
        font-size:12px;
        color: #003399;
        visibility:hidden;
}
-->
</style>

<script type="text/javascript">
<!--
addLoad_DF_ObjetDefilant(function(){DF_ObjetDefilant('texte_defilant','auto','b','g','12','100','30','500')});
-->
</script>

</head>

<body>
<div id = "cadre_texte">
<div id = "texte_defilant"  onmouseover = "DF_ObjetNavigMous('texte_defilant','over')"  onmouseout = "DF_ObjetNavigMous('texte_defilant','out')"><?php echo $total_chaine?></div>
</div>

</body>
</html>

Re: [Besoin d'aide] Réalistation d'un module de propagande

Posté : 28 août 2010, 17:28
par Titiii
Merci beaucoup, je vais essayer