Quel est l'opérateur d'inégalté en php

Fermé
supergengi Messages postés 6 Date d'inscription lundi 26 novembre 2007 Statut Membre Dernière intervention 27 novembre 2007 - 27 nov. 2007 à 14:44
Dr Zoidberg Messages postés 529 Date d'inscription jeudi 28 juin 2007 Statut Membre Dernière intervention 12 juin 2015 - 27 nov. 2007 à 15:45
Bonjour,
une question stupide
quel est l'opérateur d'inégalté en php
c'est correct comme ca : $postArea != "ALL";
$postArea contient un string bien sur.
merci d'avance.

3 réponses

Dr Zoidberg Messages postés 529 Date d'inscription jeudi 28 juin 2007 Statut Membre Dernière intervention 12 juin 2015 100
27 nov. 2007 à 15:07
C'est bien != l'opérateur d'inégalité (en général)
$postArea != "ALL" est sémantiquement correcte.

Doc php:
$a != $b TRUE si $a est différent de $b.
$a <> $b TRUE si $a est différent de $b.
$a !== $b TRUE si $a est différent de $b ou bien qu'ils ne sont pas du même type. (introduit en PHP 4)
2
Dr Zoidberg Messages postés 529 Date d'inscription jeudi 28 juin 2007 Statut Membre Dernière intervention 12 juin 2015 100
27 nov. 2007 à 15:45
Je ne sais pas, ca fait quoi ?
En tout cas il te manque des conditions et il manque une quote par la
$sql="SELECT * FROM propreties WHERE Area ='$postArea AND Type='$postType' 


Sinon je pense pas que te méthode de comparaison soit efficace : tu vas te retrouver avec 16 if/elseif mais çà devrait pouvoir marcher.
1
supergengi Messages postés 6 Date d'inscription lundi 26 novembre 2007 Statut Membre Dernière intervention 27 novembre 2007
27 nov. 2007 à 15:20
salut
ben si c'est correct pourquoi ca marche pas ici

<?php
$idConnection= mysql_connect("localhost","root","");
mysql_select_db("test");
if (isset($_POST['Area']) AND isset($_POST['Type'])AND isset($_POST['Bedrooms'])AND isset($_POST['Price']))


{

$postArea = $_POST['Area'];
$postType = $_POST['Type'];
$postBedrooms = $_POST['Bedrooms'];
$postPrice=$_POST['Price'];

if ($postArea =="ALL" AND $postType=="ALL" AND $postBedrooms=="ALL" AND $postPrice=="ALL")
{
$sql="SELECT * FROM propreties ";
}


elseif ($postArea=="ALL" AND $postType !="ALL" AND $postBedrooms!="ALL" AND $postPrice!="ALL" )
{
$sql="SELECT * FROM propreties WHERE Type = '$postType' AND Bedrooms = ' $postBedrooms'AND Price BETWEEN '$pricebefore' AND '$priceafter' " ;
}


elseif ($postType=="ALL" AND $postArea !="ALL" AND $postBedrooms !="ALL" AND $postPrice !="ALL")
{
$sql=" SELECT * FROM propreties WHERE Area = '$postArea' AND Bedrooms = '$postBedrooms' AND Price BETWEEN '$pricebefore' And '$priceafter'" ;
}


elseif ($postBedrooms=="ALL" AND $postType!= "ALL" AND $postArea!="ALL" AND $postPrice!="ALL")
{
$sql="SELECT * FROM propreties WHERE Area ='$postArea AND Type='$postType' AND Price BETWEEN '$pricebefore' AND '$priceafter' " ;
}


elseif ($postArea !="ALL" AND $postType != "ALL" AND $postBedrooms !="ALL" AND $postPrice=="ALL")
{
$sql="SELECT * FROM propreties WHERE Area = '$postArea' AND Type = '$postType' AND Bedrooms = ' $postBedrooms ' " ;
}

else
{
$pricebefore=substr($_POST['Price'],0,strpos($_POST['Price'],"-"));
$pricebefore=str_replace("-","",$pricebefore);
echo ($pricebefore);
echo ("fghfghfgh");
$priceafter=strstr($_POST['Price'],"-");
$priceafter=str_replace("-","",$priceafter);
echo($priceafter);


$sql = "SELECT * FROM propreties WHERE Area = '$postArea' AND Type = '$postType' AND Bedrooms = ' $postBedrooms'AND Price BETWEEN '$pricebefore' AND '$priceafter' ";


}


$result = mysql_query($sql) or die(mysql_error());;
$num_rows = mysql_num_rows($result);
echo $sql;
echo "$num_rows Rows\n";

}
while ($donnees = mysql_fetch_array($result))
{


?>
<H2><font color="orange"size="6" >
Search Results:
</font><div style="color:black; font-size:20">
<p><strong>Area: <?php echo $donnees['Area'];?></strong></br>
<strong>Type:<?php echo $donnees['Type'];?></strong></br>
<strong>Bedrooms:<?php echo $donnees['Bedrooms']; ?></strong></br>
<strong>Price:<?php echo $donnees ['Price']; ?></strong></br></p>

<?php




}

if ($num_rows=='0'){
echo " Sorry Nothing Matched";
}
mysql_close();


?>
merci pour ton aide Dr Zoidberg t'es le seul qui me repond.
0