Dans un fichier search-engine.php, j'offre la possibilité à l'internaute de sélectionner plusieurs critères de recherche à travers des checkbox.
Les valeurs de ces checkbox sont renvoyées en POST à la page result-request.php.
Et c'est là que j'ai un problème. Je n'arrive pas à faire en sorte d'afficher à la suite les différents résultats trouvés. Ils s'affichent les uns après les autres. Les n effaçant les n-1.
Voici mon code du formulaire :
<script>
function AfficheResult() {
var critInputs = document.criteria.elements;
var myInput;
for ( var i = 0 ; i < critInputs.length ; i++ ) {
myInput = critInputs[i];
if ( myInput.type == 'checkbox' && myInput.checked ) {
var explode = myInput.value.split('/');
var id_cat = explode[0];
var id_crit = explode[1];
getByAjax('result-request.php', document.getElementById('ajax'), 'cat='+id_cat+'&crit='+id_crit);
}
}
}
</script>
<div id="content">
<?
echo "<br /><br />Choose the different criteria which correspond to your request : ";
/*---------------------------------*/
//on ouvre le fichier criteria.xml
$criteriaFile = $cfg['ressources_root'].'criteria.xml';
$domCriteria = new DOMDocument('1.0','UTF-8');
$domCriteria->load($criteriaFile);
$xpCriteria = new DOMXPath($domCriteria);
$cat_criteria = $domCriteria->getElementsByTagName('cat');
$result_find_criteria = $domCriteria->getElementsByTagName('criteria');?>
<form name="criteria">
<?
echo "<table align='center'><tr>";
foreach($cat_criteria as $cat){
$name_cat = $cat->getAttribute('name');
$id_cat = $cat->getAttribute('id');
echo "<td valign='top'><br /><strong>".$name_cat." : </strong>";
foreach ($cat->childNodes as $criteria)
{
if ($criteria->nodeType != XML_ELEMENT_NODE) continue;
if ($criteria->tagName == 'criteria')
{
$name_criteria = $criteria->getAttribute('name');
$id_criteria = $criteria->getAttribute('id');
echo "<ul><input type='checkbox' id='crit' name='crit[]' value='$id_cat/$id_criteria'>$name_criteria</input></ul>";
}
}
}
echo "</tr></table>";
?>
</form>
<div align="center"><button onClick="AfficheResult();">Search</button></div>
<div id="ajax"></div>
Voici mon code pour récupérer les variables et les afficher :
<?php
session_name('SEEC');
session_start(session_name());
include('php-includes/common.php');
/*-----------------------------------------------------*/
//on affiche le résultat en fonction d'un seul critère //
/*-----------------------------------------------------*/
$link_file = $cfg['ressources_root'].'/matrix/criteria-practice.xml';
$xml = simplexml_load_file($link_file);//on ouvre le fichier xml
//on vérifie l'existence des varaibles passées par le formulaire si elle n'existe pas, on lui affecte une valeur vide
if (!isset($_POST['crit'])) { $_POST['crit'] = ''; }
if (!isset($_POST['cat'])) { $_POST['cat'] = ''; }
//si les variables ne sont pas vides
if ( ($_POST['crit'] != '') && ($_POST['cat'] != ''))
{
foreach($xml->link as $value)
{
if( $value->criteria[0]['idcrit'] == $_POST['crit'] and $value->criteria[0]['idcat'] == $_POST['cat'])
{
$practice[]=( (int)$value->practice[0]['id'] );
if (isset($practice[0]))
{
$id_practice = $practice[0];
}
else $id_practice = '';
}
}
if ( (isset($id_practice)) and ($id_practice != '') ) // si $id_practice n'est pas vide
{
//on ouvre le document xml qui correspond à la recherche
$practiceFile = $cfg['ressources_root'].'content/practice/'.$id_practice.'.xml';
$domPractice = new DOMDocument('1.0','UTF-8');
$domPractice->load($practiceFile);
$xpPractice = new DOMXPath($domPractice);
$item_practice = $domPractice->getElementsByTagName('item');
foreach ($item_practice as $item)
{
foreach ($item->childNodes as $child)
{
if($child->nodeType != XML_ELEMENT_NODE) continue;
if($child->tagName == 'title')
{
$titre = utf8_decode($child->firstChild->nodeValue);
}
elseif ($child->tagName == 'short_description')
{
$short_description = utf8_decode($child->firstChild->nodeValue);
}
//$msg = "<table width='600'><tr><th>Title of the practice</th><th>Short description</th><th>Viewed</th><th>Used</th></tr>";
//$msg .= "<tr><td>$titre</td><td>$short_description</td></tr>";
//$msg .= "</table>";
//echo $msg;
}
}
$msg = "<table width='600'><tr><th>Title of the practice</th><th>Short description</th><th>Viewed</th><th>Used</th></tr>";
$msg .= "<tr><td>$titre</td><td>$short_description</td></tr>";
$msg .= "</table>";
}
else
{
$msg = "<p align='center'>There is no practice which correspond to your request. Please refine your search !</p>";
}
echo "<h3>Result of your search : </h3>";
echo "<p>List of practices which correspond to the different criteria you checked : <br /></p>";
echo $msg;
}
?>
Si quelqu'un pouvait m'aider..