Extraction du nom de la table

Résolu/Fermé
Stevenp - 20 mars 2012 à 11:15
 le père - 20 mars 2012 à 11:51
Bonjour,

Je voudrais savoir comment est-il possible dans une requete php d'extraire le nom de la table ou provient cette donnée ?

Je m'explique. J'ai une requête SQL qui tape dans 2 tables :


$sql = 'SELECT id_produit,type_produit,ros,client,adresse,adresseb,ville,codepostal,villeb,codepostalb,clientb FROM histo WHERE UPPER(histo.client) LIKE \'%' . $_GET['clienta'] . '%\'
UNION
SELECT id_produit,type_produit,ros,client,adresse,adresseb,ville,codepostal,villeb,codepostalb,clientb FROM encours WHERE UPPER(encours.client) LIKE \'%' . $_GET['clienta'] . '%\'';
$qry = mysql_query($sql);
while($row = mysql_fetch_assoc($qry)) {
   $dataHisto[] = $row;
}


Le $_GET['clienta'] provient d'un
<INPUT type="text" value="" name="clienta">


Plus bas je l'affiche dans un tableau :

<p>
			<!-- Données de la table
			************************************************************-->
			<table>
			  <thead>
				 <tr>
					<th>Produit</th>
					<th>Type</th>
					<th>Client</th>
					<th>Adresse A</th>
					<th>Adresse B</th>
					<th>ROS</th>
				 </tr>
			  </thead>
			  <tbody>
				 <?php foreach($dataHisto as $row): ?>
				 <tr>
					<td><?php echo $hsc($row['id_produit']); ?></td>
					<td><?php echo $hsc($row['type_produit']); ?></td>
					<td><?php echo $hsc($row['client']); ?></td>
					<td><?php echo $hsc($row['adresse']); ?> <?php echo $hsc($row['codepostal']); ?> <?php echo $hsc($row['ville']); ?></td>
					<td><?php echo $hsc($row['adresseb']); ?> <?php echo $hsc($row['codepostalb']); ?> <?php echo $hsc($row['villeb']); ?></td>
					<td><?php echo $hsc($row['ros']); ?></td>
				 </tr>
				 <?php endforeach; ?>
			  </tbody>
			</table>	
			</p>


Je voudrais savoir, comment peut-on faire pour que dans la dernière colonne de ce tableau, il y soit affiché si cette entrée provient de ma table "histo" ou de ma table "encours".

Merci d'avance :)

1 réponse

Bonjour

Il suffit d'ajouter le nom de la table dans le SELECT, en tant que constante et pas en tant que champ bien sûr

$sql = 'SELECT id_produit,type_produit,ros,client,adresse,adresseb,ville,codepostal,villeb,codepostalb,clientb,'histo' as nomtable FROM histo WHERE UPPER(histo.client) LIKE \'%' . $_GET['clienta'] . '%\'
UNION
SELECT id_produit,type_produit,ros,client,adresse,adresseb,ville,codepostal,villeb,codepostalb,clientb,'encours' as nomtable FROM encours WHERE UPPER(encours.client) LIKE \'%' . $_GET['clienta'] . '%\'';
0