Fonction et SGBD--> problème de répétition

Résolu/Fermé
Smoking bird Messages postés 870 Date d'inscription mardi 11 mars 2008 Statut Membre Dernière intervention 10 juillet 2011 - 11 mars 2008 à 20:57
Smoking bird Messages postés 870 Date d'inscription mardi 11 mars 2008 Statut Membre Dernière intervention 10 juillet 2011 - 16 avril 2008 à 18:52
Bonjour foule,

J'ai un problème très embêtant. Je code un système de backoffice assez développé, pour permettre à mes clients de modifier ce qu'ils veulent dans leur site, sans beaucoup de connaissances en code. Pour cela, j'installe un système de css dynamique, qui passe par plusieurs tables, et utilise php et mysql. C'est la première fois que j'utilise plusieurs tables pour la même requête, donc je pense que ma "débutance" (joli mot non?) est à l'origine de l'erreur.

Voici comment ça se passe:
J'ai une requête qui appelle les 3 tables concernées avec toutes leurs colonnes. Cette requête se concrétise dans un tableau qui affiche tout ça (mysql_fetch_array power^^).

Une fonction me permet ensuite de mieux définir tout ça, et de récupérer un à un les éléments css (en me lisant, je commence à me dire que le problème vient bêtement de là).

Lorsque je charge ma page et que je regarde le code source, j'obtiens la liste des éléments qu'il me faut (3 élements)... fois 9. Donc, vive les duplicatas de propriétés.

Voici le code source:



<?php


function bckplus($what,$what1,$what2,$where)
{

//on récupère les propriétés en fonction de l'objet et du document auquel il est associé
$sql="SELECT item.id AS itid,item.document AS itdoc,item.object AS itobj,item.backgroundattachment AS itbckatt,item.backgroundrepeat AS itbckrep,
item.backgroundcolor AS itbckcolor,item.backgroundimage AS itbckimg,item.border AS itborder,item.listype AS itlistype,
position.id AS posid, position.document AS posdoc, position.object AS posobj, position.position AS pospos, position.floater AS posflo,
position.zindex AS poszin, position.lefter AS poslef, position.toper AS postop, position.righter AS posrig, position.bottomer AS posbot,
position.margin AS posmar, position.padding AS pospad, position.width AS poswid, position.height AS poshei,
style.id AS stid, style.document AS stdoc, style.object AS stobj, style.fontfamily AS stff, style.fontsize AS stfsz, style.fontstretch AS stfstr,
style.fontstyle AS stfst, style.fontvariant AS stfv, style.fontweight AS stfw, style.color AS stcol, style.textdecoration AS sttd,
style.textalign AS stta, style.texttransform AS sttt, style.letterspacing AS stls, style.wordspacing AS stws FROM item,position,style
WHERE item.object='".$what."' AND position.object='".$what1."' AND style.object='".$what2."'
AND item.document='".$where."' AND position.document='".$where."' AND style.document='".$where."'";
$query=mysql_query($sql);

while($css=mysql_fetch_array($query))
{

if($css['itobj'])
{
echo $css['itobj']." { ";
};

if($css['itbckatt'])
{
echo "background-attachment:".$css['itbckatt']."; ";
};

if($css['itbckrep'])
{
echo "background-repeat:".$css['itbckrep']."; ";
};

if($css['itbckcol'])
{
echo "background-color:".$css['itbckcol']."; ";
};

if($css['itbckimg'])
{
echo "background-image:url('".$css['itbckimg']."'); ";
};

if($css['itborder'])
{
echo "border:".$css['itborder']."; ";
};

if($css['itlistype'])
{
echo "list-style-type:".$css['itlistype']."; ";
};

if($css['pospos'])
{
echo "position:".$css['pospos']."; ";
};

if($css['posflo'])
{
echo "float:".$css['posflo']."; ";
};

if($css['poszin'])
{
echo "z-index:".$css['poszin']."; ";
};

if($css['poslef'])
{
echo "left:".$css['poslef']."; ";
};

if($css['postop'])
{
echo "top:".$css['postop']."; ";
};

if($css['posrig'])
{
echo "right:".$css['posrig']."; ";
};

if($css['posbot'])
{
echo "bottom:".$css['posbot']."; ";
};

if($css['posmar'])
{
echo "margin:".$css['posmar']."; ";
};

if($css['pospad'])
{
echo "padding:".$css['pospad']."; ";
};

if($css['poswid'])
{
echo "width:".$css['poswid']."; ";
};

if($css['poshei'])
{
echo "height:".$css['poshei']."; ";
};

if($css['stff'])
{
echo "font-family:".$css['stff']."; ";
};

if($css['stfsz'])
{
echo "font-size:".$css['stfsz']."; ";
};

if($css['stfstr'])
{
echo "font-stretch:".$css['stfstr']."; ";
};

if($css['stfst'])
{
echo "font-style:".$css['stfst']."; ";
};

if($css['stfv'])
{
echo "font-variant:".$css['stfv']."; ";
};

if($css['stfw'])
{
echo "font-weight:".$css['stfw']."; ";
};

if($css['stcol'])
{
echo "color:".$css['stcol']."; ";
};

if($css['sttd'])
{
echo "text-decoration:".$css['sttd']."; ";
};

if($css['stta'])
{
echo "text-align:".$css['stta']."; ";
};

if($css['sttt'])
{
echo "text-transform:".$css['sttt']."; ";
};

if($css['stls'])
{
echo "letter-spacing:".$css['stls']."; ";
};

if($css['stws'])
{
echo "word-spacing:".$css['stws']."; ";
};
//fin de la ligne de propriétés
echo " }";

?>

<?php
};//fin du while de récupération des propriétés

};//fin de la fonction bckplus qui récupère les propriétés de what et where


//fonction de récupération de chaque élément de css
$sqlCALLER="SELECT item.id AS itid,item.document AS itdoc,item.object AS itobj,item.backgroundattachment AS itbckatt,item.backgroundrepeat AS itbckrep,
item.backgroundcolor AS itbckcolor,item.backgroundimage AS itbckimg,item.border AS itborder,item.listype AS itlistype,
position.id AS posid, position.document AS posdoc, position.object AS posobj, position.position AS pospos, position.floater AS posflo,
position.zindex AS poszin, position.lefter AS poslef, position.toper AS postop, position.righter AS posrig, position.bottomer AS posbot,
position.margin AS posmar, position.padding AS pospad, position.width AS poswid, position.height AS poshei,
style.id AS stid, style.document AS stdoc, style.object AS stobj, style.fontfamily AS stff, style.fontsize AS stfsz, style.fontstretch AS stfstr,
style.fontstyle AS stfst, style.fontvariant AS stfv, style.fontweight AS stfw, style.color AS stcol, style.textdecoration AS sttd,
style.textalign AS stta, style.texttransform AS sttt, style.letterspacing AS stls, style.wordspacing AS stws FROM item,position,style
WHERE item.document='main' AND position.document='main' AND style.document='main' ORDER BY item.id,position.id,style.id";

$query=mysql_query($sqlCALLER);
?>
<style type="text/css">
<?php

while($recall=mysql_fetch_array($query))
{
bckplus($recall['itobj'],$recall['posobj'],$recall['stobj'],main);

};
//fin de la fonction de récupération des éléments de css
?>
</style>

</head>
<body id="main">

<?php
bckplus('#main ul','#main ul','#main ul','main');
?>





Voilà, si quelqu'un a une idée quant à une éventuelle solution pour ce problème, je suis plus que preneur :) je remercie au passage tous ceux qui s'intéresseront à mon problème, et salut la communauté de commentcamarche.net, ceci était mon tout premier message :)

Smoking bird
A voir également:

3 réponses

Smoking bird Messages postés 870 Date d'inscription mardi 11 mars 2008 Statut Membre Dernière intervention 10 juillet 2011 58
11 mars 2008 à 23:31
petit up, because un peu urgent^^
0
Smoking bird Messages postés 870 Date d'inscription mardi 11 mars 2008 Statut Membre Dernière intervention 10 juillet 2011 58
12 mars 2008 à 20:55
up
0
Smoking bird Messages postés 870 Date d'inscription mardi 11 mars 2008 Statut Membre Dernière intervention 10 juillet 2011 58
13 mars 2008 à 14:03
up
0
Smoking bird Messages postés 870 Date d'inscription mardi 11 mars 2008 Statut Membre Dernière intervention 10 juillet 2011 58
16 avril 2008 à 18:52
problème résolu, j'ai oublié comment ^^ (ça remonte)
0