Comment afficher 0 si champs est null Mysql

Fermé
sinifer Messages postés 312 Date d'inscription mardi 12 février 2008 Statut Membre Dernière intervention 12 mars 2013 - 6 mai 2009 à 15:25
sinifer Messages postés 312 Date d'inscription mardi 12 février 2008 Statut Membre Dernière intervention 12 mars 2013 - 11 mai 2009 à 17:15
Bonjour,

j'ai fait deu requete différente qui ce lie mais j'ai un problème d'affichage car un moment j'ai un resultat null donc sa m'affiche pas et je perd une place donc c'est un autre résultat qui me prend la place du null j'aimerai savoir comment fair pour que sa m'affiche '0'

je vous montre mes deu requete

<?php

$query_vg ="
SELECT substr(customers_from, 1, 3) AS Origin, 
       COUNT(*) AS effectif_vg
FROM customers 

GROUP BY Origin ";
$result_vg = mysql_query($query_vg) ;



	// requete pour chaque ligne "client" (ayant une facture)
	$query = " SELECT substr(customers_from, 1, 3) AS Origin,
       COUNT(DISTINCT cu.customers_id) AS effectif, count(co.commandes_status) AS command,
       AVG(co.commandes_montant) AS Mmc 
FROM customers cu
INNER JOIN commandes co 
ON cu.customers_id=co.customers_id 
WHERE co.commandes_status='1'  
GROUP BY Origin ";
	$result = mysql_query($query) ;
	
 while ($row1 = mysql_fetch_array($result_vg) and $row = mysql_fetch_array($result) ) 
{
?>
		<tr>
			<td style="background-color:#CCCCCC;">  </td>
            <td style="text-align:center;"> <?php echo $row1['Origin'] ?> </td>
			 <td style="text-align:center;"> <?php echo $row1['effectif_vg'] ?> </td>
			<td style="text-align:center;"> <?php echo $row['command'] ?> </td>
            <td style="text-align:center;"> <?php echo round(($row['command']*$row['Mmc'])) ?> euro</td>
              <td style="text-align:center;"> <?php echo round($row['Mmc'] ,2)?> </td>
		</tr>  
<?php
}
?>



Merci

5 réponses

jeangilles Messages postés 816 Date d'inscription samedi 21 juin 2008 Statut Membre Dernière intervention 17 juillet 2012 185
6 mai 2009 à 16:28
Bonjour,
tu peux faire un SELECT ifnull( nom_de_ton_champs , '0')
qui te renverra 0 au lieu de null dans ta requête
4