Javascript et php
a
-
a -
a -
Bonjour,
J'ai rencontré une difficulté que je n'arrive pas à résoudre :
J'ai créé un fichier php test dans lequel j'ai inséré des enregistrements phpmyadmin d'une base de donnée répertoriant des informations sur des films récents.
Chaque élément comporte 6 champs, l'id, le titre du film, l'adresse de l'affiche du film, le casting et le synopsis.
J'ai inséré dans la base de donnée 10 films.
J'ai inséré un moteur de recherche mot pour mot basique sur cette page.
il existe 2 pages, une page index.php et une résultat.php, le résultat de la recherche est redirigée vers la page résultat.
Suite à une recherche, la page comprend uniquement l'affiche du film, et en cliquant dessus, grâce au Javascript on fait apparaitre une fenêtre composée de 3 div (contenaire, contenu et bouton fermeture).
Le contenu contient le titre du film, son affiche, son casting et son synopsis.
Le tout marche parfaitement bien pour 1 seul résultat :
http://img15.hostingpics.net/pics/749740capture.png
Le problème est que pour plusieurs résultat, par exemple une recherche à vide,
javascript m'affiche le contenu de la première affiche.
Par exemple si je clique sur Tinin ou sur n'importe quelle autre affiche j'aurais alors le contenu de Intouchables :
http://img15.hostingpics.net/pics/350134capture2.png
Votre aide est la bienvenue.
J'ai rencontré une difficulté que je n'arrive pas à résoudre :
J'ai créé un fichier php test dans lequel j'ai inséré des enregistrements phpmyadmin d'une base de donnée répertoriant des informations sur des films récents.
Chaque élément comporte 6 champs, l'id, le titre du film, l'adresse de l'affiche du film, le casting et le synopsis.
J'ai inséré dans la base de donnée 10 films.
J'ai inséré un moteur de recherche mot pour mot basique sur cette page.
il existe 2 pages, une page index.php et une résultat.php, le résultat de la recherche est redirigée vers la page résultat.
Suite à une recherche, la page comprend uniquement l'affiche du film, et en cliquant dessus, grâce au Javascript on fait apparaitre une fenêtre composée de 3 div (contenaire, contenu et bouton fermeture).
Le contenu contient le titre du film, son affiche, son casting et son synopsis.
Le tout marche parfaitement bien pour 1 seul résultat :
http://img15.hostingpics.net/pics/749740capture.png
Le problème est que pour plusieurs résultat, par exemple une recherche à vide,
javascript m'affiche le contenu de la première affiche.
Par exemple si je clique sur Tinin ou sur n'importe quelle autre affiche j'aurais alors le contenu de Intouchables :
http://img15.hostingpics.net/pics/350134capture2.png
Votre aide est la bienvenue.
A voir également:
- Javascript et php
- Easy php - Télécharger - Divers Web & Internet
- Expert php pinterest - Télécharger - Langages
- Telecharger javascript - Télécharger - Langages
- A javascript error occurred in the main process - Forum Handicap / Accessibilté
- A javascript error occurred in the main process - Forum Windows
3 réponses
Hello,
Le problème bien probablement de la boucle qui génère ton code JS : il faudrait qu'on la voit ; car juste comme ça il est difficile de t'aider !
Le problème bien probablement de la boucle qui génère ton code JS : il faudrait qu'on la voit ; car juste comme ça il est difficile de t'aider !
Merci pour vos réponses,
Je n'ai pas utilisé de boucle qui génère du javascript, je l'ai simplement ajouté à l'enregistrement php.
Je ne maitrise absolument pas le javascript, j'ai juste utilisé l'outil comportement de Dreamweaver.
Voici pour le moteur de recherche basique en php:
Les fonctions javascript utilisées :
Et le code de l'affichage des enregistrements doublé php javascript :
Je n'ai pas utilisé de boucle qui génère du javascript, je l'ai simplement ajouté à l'enregistrement php.
Je ne maitrise absolument pas le javascript, j'ai juste utilisé l'outil comportement de Dreamweaver.
Voici pour le moteur de recherche basique en php:
<?php require_once('../Connections/connexion51.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
}
$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? doubleval($theValue) : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}
}
$colname_rsRecherche = "-1";
if (isset($_POST['recherche'])) {
$colname_rsRecherche = $_POST['recherche'];
}
mysql_select_db($database_connexion51, $connexion51);
$query_rsRecherche = sprintf("SELECT * FROM test WHERE titre LIKE %s", GetSQLValueString($colname_rsRecherche . "%", "text"));
$rsRecherche = mysql_query($query_rsRecherche, $connexion51) or die(mysql_error());
$row_rsRecherche = mysql_fetch_assoc($rsRecherche);
$totalRows_rsRecherche = mysql_num_rows($rsRecherche);
?>
Les fonctions javascript utilisées :
<script type="text/javascript">
function MM_showHideLayers() { //v9.0
var i,p,v,obj,args=MM_showHideLayers.arguments;
for (i=0; i<(args.length-2); i+=3)
with (document) if (getElementById && ((obj=getElementById(args[i]))!=null)) { v=args[i+2];
if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
obj.visibility=v; }
}
function MM_scanStyles(obj, prop) { //v9.0
var inlineStyle = null; var ccProp = prop; var dash = ccProp.indexOf("-");
while (dash != -1){ccProp = ccProp.substring(0, dash) + ccProp.substring(dash+1,dash+2).toUpperCase() + ccProp.substring(dash+2); dash = ccProp.indexOf("-");}
inlineStyle = eval("obj.style." + ccProp);
if(inlineStyle) return inlineStyle;
var ss = document.styleSheets;
for (var x = 0; x < ss.length; x++) { var rules = ss[x].cssRules;
for (var y = 0; y < rules.length; y++) { var z = rules[y].style;
if(z[prop] && (rules[y].selectorText == '*[ID"' + obj.id + '"]' || rules[y].selectorText == '#' + obj.id)) {
return z[prop];
} } } return "";
}
function MM_getProp(obj, prop) { //v8.0
if (!obj) return ("");
if (prop == "L") return obj.offsetLeft;
else if (prop == "T") return obj.offsetTop;
else if (prop == "W") return obj.offsetWidth;
else if (prop == "H") return obj.offsetHeight;
else {
if (typeof(window.getComputedStyle) == "undefined") {
if (typeof(obj.currentStyle) == "undefined"){
if (prop == "P") return MM_scanStyles(obj,"position");
else if (prop == "Z") return MM_scanStyles(obj,"z-index");
else if (prop == "V") return MM_scanStyles(obj,"visibility");
} else {
if (prop == "P") return obj.currentStyle.position;
else if (prop == "Z") return obj.currentStyle.zIndex;
else if (prop == "V") return obj.currentStyle.visibility;
}
} else {
if (prop == "P") return window.getComputedStyle(obj,null).getPropertyValue("position");
else if (prop == "Z") return window.getComputedStyle(obj,null).getPropertyValue("z-index");
else if (prop == "V") return window.getComputedStyle(obj,null).getPropertyValue("visibility");
}
}
}
function MM_dragLayer(objId,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v9.01
//Copyright 2005-2006 Adobe Macromedia Software LLC and its licensors. All rights reserved.
var i,j,aLayer,retVal,curDrag=null,curLeft,curTop,IE=document.all;
var NS=(!IE&&document.getElementById); if (!IE && !NS) return false;
retVal = true; if(IE && event) event.returnValue = true;
if (MM_dragLayer.arguments.length > 1) {
curDrag = document.getElementById(objId); if (!curDrag) return false;
if (!document.allLayers) { document.allLayers = new Array();
with (document){ if (NS) { var spns = getElementsByTagName("span"); var all = getElementsByTagName("div");
for (i=0;i<spns.length;i++) if (MM_getProp(spns[i],'P')) allLayers[allLayers.length]=spns[i];}
for (i=0;i<all.length;i++) {
if (MM_getProp(all[i],'P')) allLayers[allLayers.length]=all[i];
}
} }
curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
curDrag.MM_oldZ = MM_getProp(curDrag,'Z');
curLeft = MM_getProp(curDrag,'L');
if (String(curLeft)=="NaN") curLeft=0; curDrag.MM_startL = curLeft;
curTop = MM_getProp(curDrag,'T');
if (String(curTop)=="NaN") curTop=0; curDrag.MM_startT = curTop;
curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop-cU;
curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop+cD;
curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
} else {
var theEvent = ((NS)?objId.type:event.type);
if (theEvent == 'mousedown') {
var mouseX = (NS)?objId.pageX : event.clientX + document.body.scrollLeft;
var mouseY = (NS)?objId.pageY : event.clientY + document.body.scrollTop;
var maxDragZ=null; document.MM_maxZ = 0;
for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
var aLayerZ = MM_getProp(aLayer,'Z');
if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
var isVisible = (MM_getProp(aLayer,'V')).indexOf('hid') == -1;
if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
var parentL=0; var parentT=0;
if (NS) { parentLayer = aLayer.parentNode;
while (parentLayer != null && parentLayer != document && MM_getProp(parentLayer,'P')) {
parentL += parseInt(MM_getProp(parentLayer,'L')); parentT += parseInt(MM_getProp(parentLayer,'T'));
parentLayer = parentLayer.parentNode;
if (parentLayer==document) parentLayer = null;
} } else if (IE) { parentLayer = aLayer.parentElement;
while (parentLayer != null && MM_getProp(parentLayer,'P')) {
parentL += MM_getProp(parentLayer,'L'); parentT += MM_getProp(parentLayer,'T');
parentLayer = parentLayer.parentElement; } }
var tmpX=mouseX-((MM_getProp(aLayer,'L'))+parentL+MM_hLeft);
var tmpY=mouseY-((MM_getProp(aLayer,'T'))+parentT+MM_hTop);
if (String(tmpX)=="NaN") tmpX=0; if (String(tmpY)=="NaN") tmpY=0;
var tmpW = MM_hWidth; if (tmpW <= 0) tmpW += MM_getProp(aLayer,'W');
var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += MM_getProp(aLayer,'H');
if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
|| maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
if (curDrag) {
document.onmousemove = MM_dragLayer;
curLeft = MM_getProp(curDrag,'L');
curTop = MM_getProp(curDrag,'T');
if (String(curLeft)=="NaN") curLeft=0; if (String(curTop)=="NaN") curTop=0;
MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
document.MM_curDrag = curDrag; curDrag.MM_SNAPPED=false;
if(curDrag.MM_toFront) {
var newZ = parseInt(document.MM_maxZ)+1;
eval('curDrag.'+('style.')+'zIndex=newZ');
if (!curDrag.MM_dropBack) document.MM_maxZ++; }
retVal = false; if(!NS) event.returnValue = false;
} } else if (theEvent == 'mousemove') {
if (document.MM_curDrag) with (document.MM_curDrag) {
var mouseX = (NS)?objId.pageX : event.clientX + document.body.scrollLeft;
var mouseY = (NS)?objId.pageY : event.clientY + document.body.scrollTop;
var newLeft = mouseX-MM_oldX; var newTop = mouseY-MM_oldY;
if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
if (MM_bT!=null) newTop = Math.max(newTop ,MM_bT);
if (MM_bB!=null) newTop = Math.min(newTop ,MM_bB);
MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
if (NS){style.left = newLeft + "px"; style.top = newTop + "px";}
else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
if (MM_dragJS) eval(MM_dragJS);
retVal = false; if(!NS) event.returnValue = false;
} } else if (theEvent == 'mouseup') {
document.onmousemove = null;
if (NS) document.releaseEvents(Event.MOUSEMOVE);
if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
if (document.MM_curDrag) with (document.MM_curDrag) {
if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
(Math.pow(MM_targL-(MM_getProp(document.MM_curDrag,'L')),2)+
Math.pow(MM_targT-(MM_getProp(document.MM_curDrag,'T')),2))<=MM_tol) {
if (NS) {style.left = MM_targL + "px"; style.top = MM_targT + "px";}
else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
if(MM_dropBack) {style.zIndex = MM_oldZ;}
retVal = false; if(!NS) event.returnValue = false; }
document.MM_curDrag = null;
}
if (NS) document.routeEvent(objId);
} return retVal;
}
</script>
Et le code de l'affichage des enregistrements doublé php javascript :
<td id="affiche" onClick="MM_showHideLayers('elementconteneur','','show')"><a href="#"><img src="<?php echo $row_rsRecherche['affiche']; ?>" onClick="MM_showHideLayers('elementconteneur','','hide');MM_showHideLayers('elementconteneur','','hide')"><img></a></td>