bjr a tous le monde
bain je suis en période de réalisation d'un site humanitaire de don du sang
par ex quelqu’un qui cherche du sang il entre sur le site il trouve les champs
département ===== groupe sanguin il choisis ou il cherche du sang et quel est le groupe sanguin cherché
par exemple paris=====B+
le système va faire un tri il cherche les donneurs habité a paris et le sang est du B+ bien sur enregistrer sur la base de donnés
par exemple comme ça le systéme :
jai fait un traitement lorsque je sélection rien tous est nikel
mais le problème est que lorsque je choisi le département et le groupe sanguin la résultat affiche tous les donneurs qu'ils sont enregistrer dans la Base de Données il faut un filtrage si vous pouvez m'aider
une aide humanitaire.
merci
Salut,
Beh le problème doit venir de ta requete sql.
si dans ta base tu as un champ département et un champ groupesanguin alors ta requête doit être
"SELECT id, departement, groupesanguin ( en gros les champs que tu veux recuperer) FROM nomdelatable WHERE departement="choix de l'utilisateur" AND groupesanguin="choix de l'utilisateur" ;
remplace biensur choix de l'utilisateur par la variable PHP suite a la validation de ton formulaire qui de base de trouve dans $_POST'nom de ton input'].
En espérant t'aider.
Bonne continuation
merci dieu et merci a tous j'ai réglé le problème
if(isset($_POST'envoyer'])){
if($_POST'department'] == false ){
echo "<p style=\"color:#F00\"><strong> erreur</strong> séléctionné department</p>";
}
elseif($_POST'blood_type'] == false ){
echo "<p style=\"color:#F00\"><strong> erreur</strong> séléctionné le groupe sanguin</p>";
}
elseif($_POST'department'] && ($_POST'blood_type'] == true )){
$wilaya = $_POST'department'];
$blood_type = $_POST'blood_type'];
echo '<table class="table">
<thead>
<tr>
<th>nom</th>
<th>department</th>
<th>tel</th>
<th>email</th>
<th>groupe sanguin</th>
</tr>
</thead>
<tbody>'; ?>
<?php
try
{
$pdo_options[PDO::ATTR_ERRMODE] = PDO::ERRMODE_EXCEPTION;
$bdd = new PDO('mysql:host=localhost;dbname=sosfr', 'root', '', $pdo_options);
$req = $bdd->prepare('SELECT id, department, blood_type FROM donneurs WHERE department='.$department.' AND blood_type='.$blood_type.'');
foreach ($donneurs as $k => $v):
if(($department== $v->department) && ($blood_type == $v->blood_type)){?>
<tr>
<td><?php echo $v->name; ?></td>
<td><?php echo $v->department; ?></td>
<td><?php echo $v->tel; ?></td>
<td><?php echo $v->email; ?></td>
<td><?php echo $v->blood_type; ?></td>
</tr>
<?php
}
endforeach;
?>
</tbody></table><br />
<?php
}
catch(Exception $e)
{
exit('Erreur : '.$e->getMessage());
}
?>
<?php
}else "<br />";
}
?>
merci yantia
voila mon code
<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '';
$db = 'sosfr';
mysql_connect($dbhost,$dbuser,$dbpass);
mysql_select_db($db);
///////////////////////////////////////////////////
?>
<div class="bg_content">
<form action="index.php" method="post" id="search_bar" style="margin-top:50px;">
<table id="Table_01" width="639" height="78" border="0" cellpadding="0" cellspacing="0" dir="ltr">
<tbody><tr>
<td><input type="submit" class="btn btn-large btn-primary" name="envoyer" value="???????" style="font-family:Droid Arabic Naskh, Tahoma, Geneva, sans-serif; width:120px;" /></td>
<td width="10"><img src="webroot/img/sys/bar_search/center_02.gif" width="10" height="49"></td>
<td width="165" height="49" background="webroot/img/sys/bar_search/center_03.gif" align="right" dir="rtl">
<label for="blood">
<select name="blood_type" id="blood_type" class="selects">
<option value=""> choisissez le groupesanguin </option>
<option value="Op">+O</option>
<option value="Om">-O</option>
<option value="Bp">+B</option>
<option value="Bm">-B</option>
<option value="Ap">+A</option>
<option value="Am">-A</option>
<option value="ABp">+AB</option>
<option value="ABm">-AB</option>
</select>
</label>
</td>
<td width="164" height="49" background="webroot/img/sys/bar_search/center_03.gif" align="right" dir="rtl">
<label for="towns">
<select name="départment" id="départment" class="selects">
<option value="">choisissez</option>
<option value="13">marseille</option>
<option value="75">paris</option>
<option value="25">besançon</option>
<option value="69">lyon</option>
</select>
</label>
</td>
<td width="163" height="49" background="webroot/img/sys/bar_search/center_03.gif" align="right" dir="rtl">
<label>
<select name="country" id="country" class="selects" onchange="get_data('show_town.php?id='+this.value,'towns')">
<option value="">france</option>
</select>
</label>
</td>
<td> <img src="webroot/img/sys/bar_search/center_06.gif" width="14" height="49"></td>
</tr>
<tr><td colspan="6" align="right"><img src="webroot/img/sys/bar_search/center_07.gif"></td></tr>
<tr><td colspan="6" align="center">
<div id="result"> </div>
</td></tr>
</tbody>
</table>
</form>
<br /><br /><br /><br /><br />
<?php
if(isset($_POST'envoyer'])){
if($_POST'department'] == false ){
echo "<p style=\"color:#F00\">erreur selectionné le départment</p>";
}
elseif($_POST'blood_type'] == false ){
echo "<p style=\"color:#F00\">erreur sélection le groupesanguin</p>";
}
elseif($_POST'department'] && ($_POST'blood_type'] == true )){
$wilaya = $_POST'department'];
$blood_type = $_POST'blood_type'];
$result = mysql_query("SELECT id, department, blood_type FROM posts WHERE department=" .$department." AND blood_type=" .$blood_type." ORDER by created DESC");
echo '<table class="table">
<thead>
<tr>
<th>nom du donneur</th>
<th>départment</th>
<th>tel</th>
<th>email</th>
<th>groupe sanguin</th>
</tr>
</thead>';
echo '<tbody>';
foreach($posts as $k=>$v): {
echo '<tr>';
echo '<td>',$department,'</td>';
echo '<td>',$blood_type,'</td>';
echo '</tr>';
}
endforeach;
echo '</tbody></table><br />';
}else "<br />";
}
?>
</div>
Bonjour,
...
$department= $_POST'department'];
$blood_type = $_POST'blood_type'];
$result = mysql_query("SELECT id, department, blood_type FROM posts WHERE department=" .$department." AND blood_type=" .$blood_type." ORDER by created DESC");
...
echo '<tbody>';
while ($row = mysql_fetch_assoc($result)) {
echo '<tr>';
echo '<td>',$row'department'],'</td>';
echo '<td>',$row'blood_type'],'</td>';
echo '</tr>';
}
echo '</tbody></table><br />';
...
N'oublie pas de faire un var_dump() de tes variables pour vérifier qu'elles ont été correctement renseignées.
merci nosVal
le problème :
Warning: mysql_fetch_assoc() expects parameter 1 to be resource, string given in C:\wamp\www\sosfr\view\posts\index.php on line on line 143
line===>143
while ($row = mysql_fetch_assoc($result)) {
;(