Comment ne pas afficher 0

msi79 - Modifié par msi79 le 16/01/2014 à 15:04
 msi79 - 16 janv. 2014 à 16:37
salut à tous et bonne année.
j'ai crée une requête et je voudrais que quand la requête renvoi 0 rien ne s'affiche , donc un résultat doit s'afficher que celui ci est strictement supérieur a 0.
voici ma requête :
$q1 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut <= 3231 AND periode_etabl_bulletin = 'JANVIER' ") or die('Erreur SQL !<br>'.$q1.'<br>'.mysql_error());
$rs1 = mysql_num_rows($q1);
if($rs1 < 0){
echo '';} else { echo $rs1;}

4 réponses

BunoCS Messages postés 15475 Date d'inscription lundi 11 juillet 2005 Statut Modérateur Dernière intervention 23 avril 2024 103
Modifié par BunoCS le 16/01/2014 à 15:13
Hello,
if($rs1 <= 0){ 
du coup?

Edit: ou bien plutôt:
if($rs1 > 0){
  echo $rs1;
}


@+
Buno, Modo CS-CCM
L'urgent est fait, l'impossible est en cours. Pour les miracles, prévoir un délai...
The urgent is done, the impossible is underway. For miracles, envisage a time ...
0
ça marche pas s'affiche toujours 0 en lieu et place du vide
voici le code:


$q1 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut <= 3231 AND periode_etabl_bulletin = 'JANVIER' ") or die('Erreur SQL !<br>'.$q1.'<br>'.mysql_error());
$rs1 = mysql_num_rows($q1);
if($rs1 > 0){ echo $rs1; }
0
jordane45 Messages postés 38144 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 21 avril 2024 344
Modifié par jordane45 le 16/01/2014 à 16:19
Bonjour,

Si ta requête ne retourne rien, la variable numRows n'est normalement pas initialisée...

Donc un truc du genre devrait te permettre de faire ce que tu souhaites :

$q1 = mysql_query("SELECT *
      FROM bulletin 
     WHERE id_get  = '".$id."' 
     AND type_sal = 'Journalier' 
     AND salaire_brut <= 3231  
     AND periode_etabl_bulletin = 'JANVIER' ") 
   or die('Erreur SQL !<br>'.$q1.'<br>'.mysql_error());

$rs1 = mysql_num_rows($q1);

if(isset($rs1) && $rs1 > 0){
    echo $rs1; 
   }

   // PS : Isset seul suffit.. mais bon.




Edit : Pour la comparaison, je t'inviterai plutot à utiliser les comparateurs ternaires.

donc :
if($rs1 === 0){
   // Si rs1 = 0 ou False
}else{
   echo $rs1; 
   }


Avant de poser une question, merci de lire la charte du site.
Cordialement, Jordane
0
je comprend plus rien . ça m'affiche toujours 0
voici le code complet :

<style type="text/css">
<!--
.Style1 {color: #FF0000}
.Style2 {
color: #000000;
font-weight: bold;
}
-->
</style>
<?php
if(isset($_GET['id'])) $id = urldecode($_GET['id']);
// on crée la requête SQL

$sql ="SELECT a.id,nom,a.sigle,a.formeJ,a.regimeF,a.activiteEx,a.adres1,a.adresBP2,a.adressville,a.adress3,a.tel,a.NComptContr,a.said,a.jour,a.mois,a.annee,a.dateSaisie,a.tauxRegRetr,a.nivoTVA,a.cde_etab,a.cde_act,a.num_employeur,a.tauxPestFam,a.tauxAccW,a.id_lo,a.ma_session,b.id_ville,b.nom_ville, c.id_commune,c.nom_commune,d.id_quartier,d.nom_quartier, e.id_lot,e.rue,e.num,e.numLot,e.sectionPartielle FROM declarant a ,ville b, commune c, quartier d ,lot e WHERE a.id_lo = b.id_ville AND b.id_ville = c.id_commune AND c.id_commune = d.id_quartier AND d.id_quartier = e.id_lot AND a.id = '".$id."'";

// on envoie la requête
$req = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
$res = mysql_num_rows($req);
while ($liste_etu=mysql_fetch_assoc($req)) {

?>
<html>
<head>
<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.1.min.js" > </script>
<script type="text/javascript">

function PrintElem(elem)
{
Popup($(elem).html());
}

function Popup(data)
{
var mywindow = window.open('', 'my div', 'height=2100,width=960');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');

mywindow.print();
mywindow.close();

return true;
}

</script>

<script language="javascript">
function ouvre_popup(page) {
window.open(page,"nom_popup","menubar=no, status=no, scrollbars=yes, width=2480, height=3508");
}
</SCRIPT>
</head>
<body>
<!------- voir plus--->
<div style="background-color: #FFF; width: 159px; position: absolute; top: 0px; left: 9px">
<table width="133" border="0">
<tr>
<td width="50"><input type="button" value="Print" onClick="PrintElem('#mydiv')" /></td>
<td width="140"><a href="javascript:ouvre_popup('index.php?page=CNPS_plus_rs&id=<?php echo $liste_etu['id']; ?>')" >Voir plus</a></td>
</tr>
</table>
</div>
<!------- fin voir plus--->
<div id="mydiv" style="background-color: #FFFFFF; width: 1057px; height: 1466px; position: absolute; top: 32px; left: 19px; z-index: -2000; visibility: visible;">
<div style="background-color: #FFFFFF; width: 801px; height: 30px; position: absolute; top: 3px; left: 96px; text-align: center; color: #000075; font-weight: bold; font-size: 22px; visibility: visible;">CAISSE NATIONALE DE PREVOYANCE SOCIALE DE CÔTE D'IVOIRE</div>

<div style="background-color: #FFFFFF; width: 659px; height: 30px; position: absolute; top: 105px; left: 2px; text-align: center; color: #000; font-weight: bold; font-size: 16px; visibility: visible;"><table width="506" height="58" border="0">
<tr>
<td width="85" align="center" style="color:#000071; border: 1px dotted blue">Cde Etab</td>
<td width="77" align="center" style="color:#000071; border: 1px dotted blue">Cde Act</td>
<td width="112" align="center" style="color:#000071; border: 1px dotted blue">N° Employeur</td>
<td width="121" colspan="4" align="center" style="color:#000071; border: 1px dotted blue">Période</td>
</tr>
<tr>
<td align="center" style="color:#000071; border: 1px dotted blue"><input type="text" name="textfield12" value="<?php echo $liste_etu["cde_etab"]; ?>" style="background-color:#E7E7E7;width:70px" /></td>
<td align="center" style="color:#000071; border: 1px dotted blue"><input type="text" name="textfield13" value="<?php echo $liste_etu["cde_act"]; ?>" style="background-color:#E7E7E7;width:70px" /></td>
<td align="center" style="color:#000071; border: 1px dotted blue"><input type="text" name="textfield14" value="<?php echo $liste_etu["num_employeur"]; ?>" style="background-color:#E7E7E7; width:90px" /></td>
<td align="center" style="color:#000071; border: 1px dotted blue">TRIM</td>
<td align="center" style="color:#000071; border: 1px dotted blue"><input type="text" name="textfield2" value="<?php echo $liste_etu["mois"]; ?>" style="background-color:#E7E7E7;width:50px; text-align:center" /></td>
<td align="center" style="color:#000071; border: 1px dotted blue">ANNEE</td>
<td align="center" style="color:#000071; border: 1px dotted blue"><input type="text" name="textfield3" value="<?php echo $liste_etu["annee"]; ?>" style="background-color:#E7E7E7;width:70px; text-align:center" /></td>
</tr>
</table>
</div>
<div style="background-color: #FFFFFF; width: 551px; height: 30px; position: absolute; top: 42px; left: 207px; text-align: center; color: #000071; font-weight: bold; font-size: 16px; visibility: visible;">APPEL DE COTISATION TRMESTRIEL</div>

<div style="background-color: #FFFFFF; width: 566px; height: 30px; position: absolute; top: 74px; left: 376px; text-align: center; color: #000; font-weight: bold; font-size: 16px; visibility: visible;">
<table width="532" border="0">
<tr>
<td width="151" style="color:#000071"> RAISON SOCIAL : </td>
<td width="371"><?php echo '<div style="color:black; font-weight: bold; font-size: 16px; text-align:left">'.$liste_etu["nom"].'</div>'; ?></td>
</tr>
</table>
</div>
<div style="background-color: #FFFFFF; width: 732px; height: 30px; position: absolute; top: 180px; left: 198px; text-align: center; color: #000; font-weight: bold; font-size: 16px; visibility: visible;">
<table width="716" border="0">
<tr>
<td width="114" style="color:#000071"><strong>ADRESSE :</strong></td>
<td width="37"><input name="adres2" type="text" id="adres2" size="10" style="width:30px; background-color:#C0C0C0" value="<?php echo $liste_etu["adres1"]; ?>"/></td>
<td width="36" style="color:#000071">BP</td>
<td width="70"><input name="adresBP" type="text" id="adresBP" style="width:70px;background-color:#C0C0C0" value="<?php echo $liste_etu["adresBP2"]; ?>"/></td>
<td width="100"><input name="adressville2" type="text" id="adressville2" style="width:100px;background-color:#C0C0C0" value="<?php echo $liste_etu["adressville"]; ?>"/></td>
<td width="37"><input type="text" name="adress" style="width:30px;background-color:#C0C0C0" value="<?php echo $liste_etu["adress3"]; ?>"/></td>
<td width="131" style="color:#000071">TELEPHONE:</td>
<td width="157"><input type="text" name="tel2" id="tel2" style="width:150px;background-color:#C0C0C0" value="<?php echo $liste_etu["tel"]; ?>"/></td>
</tr>
</table>
</div>
<?php
if($res > 0){
$sql2 = "SELECT *
FROM operation WHERE get_id = '".$id."' ORDER BY dateopretion DESC LIMIT 0,1
";
// on envoie la requête
$req2 = mysql_query($sql2) or die('Erreur SQL !<br>'.$sql2.'<br>'.mysql_error());
$res2 = mysql_num_rows($req2);
while ($liste_etu2=mysql_fetch_assoc($req2)) {

?>
<div style="background-color: #FFFFFF; width: 746px; height: 30px; position: absolute; top: 214px; left: 200px; text-align: center; color: #000; font-weight: bold; font-size: 16px; visibility: visible;"><table width="693" height="26" border="0">
<tr>
<td width="472" style="color:#000071">TOTAL SALAIRE BRUTE PAYE AU COURS DE LA PERIODE</td>
<td width="162" style="text-align:center; font-size:14px; border: 1px dotted red"><?php echo $liste_etu2["total_sal_brut"]; ?></td>
</tr>
</table>
</div>
<?php
}
}
?>

<div style="background-color: #FFFFFF; width: 252px; height: 45px; position: absolute; top: 327px; left: 0px; text-align: center; color: #000; font-weight: bold; font-size: 16px; border: 1px solid#FFFFFF; visibility: visible; border: 1px dotted red;">CATÉGORIE DE SALAIRES</div>

<div style="position: absolute; top: 511px; left: 0px; width: 268px; height: 45px; border: 1px dotted red;">
Honoraires journaliers et occasionnels supérieurs à 3231 F par jour
</div>

<div style="position: absolute; top: 460px; left: 0px; width: 268px; height: 45px; border: 1px dotted red;">
Horaires, journaliers et occasionnels inférieursou égaux à 3231 F par jour
</div>

<div style="position: absolute; top: 617px; left: -1px; width: 268px; height: 45px; border: 1px dotted red;">
Mensuels supérieurs à 70 000 f. par mois et nférieurs ou égaux à 1.647.315 f par mois</div>



<div style="position: absolute; top: 673px; left: 0px; width: 268px; height: 45px; border: 1px dotted red;">
Mensuels supérieurs à 1.647.315 f par mois
</div>


<div style="position: absolute; top: 727px; left: 0px; width: 268px; height: 45px; text-align: center; font-weight: bold; border: 1px dotted red;">
TOTAL
</div>



<div style="position: absolute; top: 563px; left: -1px; width: 268px; height: 45px; border: 1px dotted red;">
Mensuels inférieurs ou égaux à 70 000 f par mois
</div>
<!-- PREMIER TRIMESTRE MOIS DE JANVIER -->
<?php
if($res > 0){

//PERIODE
$q0 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND periode_etabl_bulletin = 'JANVIER' ") or die('Erreur SQL !<br>'.$q0.'<br>'.mysql_error());

//requète journalier inferieur a 3231
$q1 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut <= 3231 AND periode_etabl_bulletin = 'JANVIER' ") or die('Erreur SQL !<br>'.$q1.'<br>'.mysql_error());
$rs1 = mysql_num_rows($q1);



//requète journalier sup a 3231
$q3 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut >= 3231 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q3.'<br>'.mysql_error());
$rs3 = mysql_num_rows($q3);


//requète journalier somme de salaire brute inf a 3231
$q4 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb1,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut <= 3231 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q4.'<br>'.mysql_error());
$rs4 = mysql_num_rows($q4);
$rw4 = mysql_fetch_assoc($q4);
$rw4["sb1"];
//echo $rw4["sb1"];


//requète journalier somme de salaire brute sup a 3231
$q5 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb2,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut >= 3231 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q5.'<br>'.mysql_error());
$rs5 = mysql_num_rows($q5);
$rw5 = mysql_fetch_assoc($q5);
// echo $rw5["sb2"];

//requète mensuel inf a 70000
$q2 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Mensuel' AND salaire_brut <= 70000 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q2.'<br>'.mysql_error());
$rs2 = mysql_num_rows($q2);

//requète mensuel sup a 70000
$q6 = mysql_query("SELECT *
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Mensuel' AND salaire_brut >= 70000 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q6.'<br>'.mysql_error());
$rs6 = mysql_num_rows($q6);

//requète journalier somme de salaire brute inf a 3231
$q7 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb7,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Mensuel' AND salaire_brut < 70000 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q7.'<br>'.mysql_error());

$rs7 = mysql_num_rows($q7);
$rw7 = mysql_fetch_assoc($q7);
$rw7["sb7"];
//echo $rw4["sb1"];


//requète journalier somme de salaire brute inf a 3231
$q8 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb8,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Mensuel' AND salaire_brut >= 70000 AND salaire_brut <= 1647315 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q8.'<br>'.mysql_error());
$rs8 = mysql_num_rows($q8);
$rs8 = mysql_num_rows($q8);
$rw8 = mysql_fetch_assoc($q8);
$rw8["sb8"];
//echo $rw4["sb1"];


//requète journalier somme de salaire brute inf a 3231
$q10 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb10,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Mensuel' AND salaire_brut >= 1647315 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q10.'<br>'.mysql_error());

$rs10 = mysql_num_rows($q10);
$rw10 = mysql_fetch_assoc($q10);
$rw10["sb10"];
//echo $rw4["sb1"];

// NOMBRE TOTAL DE SALARIES
$rsT = $rs1 + $rs2 + $rs3 + $rs6 + $rs9;
// TOTAL RÉGIME DE RETRAITE Plafond - 1.647.315f Par mois
$TRRP = $row4["sb1"] + $row5["sb2"] + $row7["sb7"] + $row8["sb8"] + $row10["sb10"];
// total 2
$rsT2 = $rw4["sb1"] + $rw5["sb2"] + $rw7["sb7"] + $rw8["sb8"] + $rw10["sb10"];
$rsT3 = $rw4["sb1"] + ($rs2 * 3231) + $rw7["sb7"] + ($rs6 * 70000) + ($rs10 * 70000);
?>
<div style="position: absolute; top: 253px; left: 273px; width: 255px; height: 22px; text-align: center; border: 1px dotted red;">Mois de : <?php while($rw0= mysql_fetch_assoc($q0)){ echo $rw0['periode_etabl_bulletin'].'  '; echo $rw0['periode_etabl_bulletin_annee'];} ?></div>
<div style="position: absolute; top: 278px; left: 272px; width: 258px; height: 113px;">
<table width="258" border="0">
<tr>
<td rowspan="2" style="text-align:center; font-size:14px; border: 1px dotted red">NOMBRE DE SALARIES</td>
<td colspan="2" style="text-align:center; font-size:14px; border: 1px dotted red">SALAIRES BRUTS SOUMIS A COTISATIONS</td>
</tr>
<tr>
<td style="text-align:center; font-size:14px; border: 1px dotted red">RÉGIME DE RETRAITE Plafond - 1.647.315f Par mois</td>
<td style="text-align:center; font-size:12px; border: 1px dotted red">RÉGIMES DES PREST. FAMIL. ET DES ACCID. DU TRAVAIL Plafond - 3231Fpar jour ou 70 000F par mois</td>
</tr>
</table>
</div>
<div style="position: absolute; top: 459px; left: 274px; width: 255px; height: 302px;">
<table width="251" height="316" border="0">
<tr style="text-align:center; font-size:14px; border: 1px dotted red">
<td width="67" style="text-align:center; font-size:14px; border: 1px dotted red">
<?php
//if($rs1 <= 0){echo '';} else{ echo $rs1;}
if(isset($rs1) && $rs1 > 0){
echo $rs1;
}
?>

</td>
<td width="80" style="text-align:center; font-size:14px; border: 1px dotted red">
<?php
echo $rw4["sb1"];
?>

</td>
<td width="90" style="text-align:center; font-size:14px; border: 1px dotted red">
<?php
$q4 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb1,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Journalier' AND salaire_brut <= 3231 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q4.'<br>'.mysql_error());
while($row4 =mysql_fetch_assoc($q4)) {
echo $row4["sb1"];
}
?>
</td>
</tr>
<tr style="width:130px;border:1px dotted red;">
<td style="text-align:center; font-size:14px; border: 1px dotted red">
<?php

echo $rs3;

?>

</td>
<td style="text-align:center; font-size:14px; border: 1px dotted red">
<?php
echo $rw5["sb2"];
?>

</td>
<td style="text-align:center; font-size:14px; border: 1px dotted red">

<?php
$r0 = $rs2 * 3231; echo $r0;
?>
</td>
</tr>
<tr style="width:130px;border:1px dotted red;">
<td style="text-align:center; font-size:14px; border: 1px dotted red"><?php echo $rs2; ?></td>
<td style=" font-size:14px; border: 1px dotted red; " align="center"><?php
echo $rw7["sb7"];
?></td>
<td style="text-align:center; font-size:14px; border: 1px dotted red"><?php
$q7 = mysql_query("SELECT salaire_brut,SUM(salaire_brut) AS sb7,type_sal
FROM bulletin WHERE id_get = '".$id."' AND type_sal = 'Mensuel' AND salaire_brut < 70000 AND periode_etabl_bulletin = 'JANVIER'") or die('Erreur SQL !<br>'.$q7.'<br>'.mysql_error());
while($row7 =mysql_fetch_assoc($q7)) {
echo $row7["sb7"];
}?></td>
</tr>
<tr style="width:130px;border:1px dotted red;">
<td style="text-align:center; font-size:14px; border: 1px dotted red"><?php echo $rs6; ?></td>
<td style="text-align:center; font-size:14px; border: 1px dotted red"><?php
echo $rw8["sb8"];
?></td>
<td style="text-align:center; font-size:14px; border: 1px dotted red"><?php $r = $rs6 * 70000; echo $r; ?></td>
</tr>
<tr style="width:130px;border:1px dotted red;">
<td height="54" style="text-align:center; font-size:14px; border: 1px dotted red">

<?php
echo $rs10;
?>
</td>
<td style="text-align:center; font-size:14px; border: 1px dotted red">
<?php
echo $rw10["sb10"];
?>
</td>
<td style="text-align:center; font-size:14px; border: 1px dotted red"><?php $r = $rs10 * 70000; echo $r; ?></td>
</tr>
<tr style="border:1px dotted red;">
<td style="text-align:center; font-size:14px; border: 1px dotted red"> <input name="adres11" type="text" id="adres11" size="10" style="width:60px; background-color:#E7E7E7; text-align:center" value="<?php echo $rsT; ?>"/></td>
<td style="text-align:center; font-size:14px; border: 1px dotted red"> <input type="text" name="textfield" value="<?php echo $rsT2; ?>" style="background-color:#E7E7E7; width:80px;text-align:center" /></td>
<td style="text-align:center; font-size:14px; border: 1px dotted red"><input type="text" name="textfield10" value="<?php echo $rsT3; ?>" style="background-color:#E7E7E7; width:80px; text-align:center" /></td>
</tr>
</table>
</div>
<?php
}
?>

<!-- FIN PREMIER TRIMESTRE MOIS DE JANVIER -->


<?php
} // 4
?>
</body>
</html>
0
Rejoignez-nous