Problème d'affichage

Statut
N'est pas ouverte pour d'autres réponses.
D

derkomai

ex membre
voilà, le script qui suit me permet d'afficher les commandes en cours. L'affichage se fait gràce à ma table neworder mais lorsque je dois afficher le nom du client ou le nom de la socièté il ne veux pas me les afficher les 2 en même temps. Soit j'ai droit au nom des particuliers soit au noms des sociètés?

<html>
<head>
<title>In Order</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
<table width="98%" border="1" align="center" cellspacing="1" cellpadding="3">
<tr bordercolor="#FFFFFF">
<td>
<table width="95%" border="1" align="center" cellspacing="0" cellpadding="3">
<tr bgcolor="#F0F0F0" bordercolor="#FFFFFF">
<td width="19%"><div align="center"><strong>Client</strong></div></td>
<td width="8%"><div align="center"><strong>sku</strong></div></td>
<td width="59%"><div align="center"><strong>Description</strong></div></td>
<td width="6%"><div align="center"><strong>Prix</strong></div></td>
<td width="8%"><div align="center"><strong>Date</strong></div></td>
</tr>

<?
require 'config.php';
$sql = 'SELECT * FROM neworder ORDER BY date DESC';
$result = mysql_query($sql) or die('Erreur SQL !<br>'.$sql.'<br>'.mysql_error());
while($row=mysql_fetch_array($result)) {

$proquery="select description from produit where sku='".$row["sku"]."'";
$proresult=mysql_query($proquery);

$userquery="select nom, prenom from client where user_id='".$row["user_id"]."'";
$userresult=mysql_query($userquery);
$user=mysql_fetch_array($userresult);

$socquery="select nomsoc, perscont from societe where soc_id='".$row["soc_id"]."'";
$socresult=mysql_query($socquery);
$soc=mysql_fetch_array($socresult);

if($pro=mysql_fetch_array($proresult)) {

echo "<tr bordercolor=\"#FFFFFF\" bgcolor=\"#DEDFD7\">";

echo "<td ><font size=\"2\">".$user["nom"]." ".$user["prenom"]."</font></td> ";
//echo "<td ><font size=\"2\">".$soc["nomsoc"]." - ".$soc["perscont"]."</font></td> ";

echo " <td ><font size=\"2\">".$row["sku"]."</font></td> ";
echo " <td ><font size=\"2\">".$pro["description"]."</font></td> ";
echo " <td ><font size=\"2\">".$row["price"]."</font></td> ";

$date = $row["date"];
sscanf($date, "%4s-%2s-%2s", &$an, &$mois, &$jour);
echo " <td ><font size=\"2\">".$jour.'/'.$mois.'/'.$an."</font></td> ";
echo "</tr>";
}
}
?>
</table>
</table>
</body>
</html>

merci d'avance :D
 

Bingo

Beer Addict
Et avec une seule query ?

SELECT neworder.*, produit.description, client.nom, client.prenom, societe.nomsoc, societe.perscont
FROM neworder
LEFT JOIN produit ON (produit.sku=neworder.sku)
LEFT JOIN client ON (client.user_id=neworder.user_id)
LEFT JOIN societe ON (societe.soc_id=neworder.soc_id)
ORDER BY neworder.date DESC

En admettant que sku, user_id et soc_id sont des clés uniques.
 
1er
OP
D

derkomai

ex membre
meric au moins ça me racourcis mes querry mais ça n'affiche tjs que soit l'un soit l'autre :cry:
 

Bingo

Beer Addict
Bah oui, mais la ligne qui doit t'afficher le om de la société est en commentaire... (précédée de '//')
 
1er
OP
D

derkomai

ex membre
oui je l'ai mis en commentaire parce que j'arrivais pas à faire fonctionner l'affichage correctement. Même quand je met des conditions il m'affiche en priorité les particuliers et pas les sociètés.

Merci de votre aide :wink:
 
Statut
N'est pas ouverte pour d'autres réponses.
Haut