Gabilach
Messages postés200Date d'inscriptionmercredi 2 mars 2011StatutMembreDernière intervention28 septembre 2014
-
27 sept. 2014 à 23:15
Gabilach
Messages postés200Date d'inscriptionmercredi 2 mars 2011StatutMembreDernière intervention28 septembre 2014
-
28 sept. 2014 à 01:11
Bonjour, voila mon problème est que j'aimerai faire un tableau en MySQLi, autrefois j'avais un tableau en mysql que j'ai refait en mysqli, mais problème j'obtient une erreur : "mysqli_fetch_array() expects parameter 1 to be mysqli_result"
J'ai essayer plusieurs choses en vain. Voici mon code source :
<table id="tableSQL" class="tablesorter vertical_middle extra_columns_table" style="width: 95%"> <thead> <tr> <th style="width: 4%" class="header">ID</th> <th style="width: 5%" class="header">ID Client</th> <th style="width: 10%" class="header">Nom & Prénom</th> <th style="width: 4%" class="header">Téléphone</th> <th style="width: 12%" class="header">Panne</th> <th style="width: 6%" class="header">Matériel</th> <th style="width: 15%" class="header">Travail Effectué</th> <th style="width: 8%" class="header">Date et Heure</th> <th style="width: 4%" class="header">Statut</th> </tr> </thead> <?php $req0 = mysqli_query($dbkb, "SELECT id, clientid, panne, diag, hardware, fait, timestamp, stat, urgent FROM tbl_sav WHERE stat LIKE '0' OR stat LIKE '1' OR stat LIKE '2' OR stat LIKE '3'"); while($dn0 = mysqli_fetch_array($req0)){ $req1 = mysqli_query($dbkb, 'SELECT name, phone FROM tbl_clients WHERE id="'.$dn0['clientid'].'"'); while($dn1 = mysqli_fetch_array($req1)){ ?> <tr> <td><?php echo $dn0['id']; ?></td> <td><?php echo $dn0['clientid']; ?></td> <td><a href="client.php?id=<?php echo $dn0['clientid']; ?>"><?php echo $dn1['name']; ?></a></td> <td><?php echo $dn1['phone']; ?></td> <td><a href="sav.php?id=<?php echo $dn0['id']; ?>"><?php echo substr($dn0['panne'], 0, 40); ?></a></td> <td><?php echo substr($dn0['hardware'], 0, 20); ?></td> <td><?php echo substr($dn0['fait'], 0, 25); ?></td> <?php if ($dn0['urgent'] == "1"){ echo '<td style="color: red">'; } else { echo '<td>';} echo $dn0['timestamp']; ?></td> <?php if ($dn0['stat'] == "0"){ ?> <td>Réceptionné</td> <?php } else if ($dn0['stat'] == "1"){ ?> <td>En cours</td> <?php } else if ($dn0['stat'] == "2"){ ?> <td>Terminé</td> <?php } else if ($dn0['stat'] == "3"){ ?> <td>Appelé</td> <?php } ?> </tr> <?php }} ?> </table>
NHenry
Messages postés15083Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 septembre 2023159 27 sept. 2014 à 23:41
De base, j'utilise la notation objet :
$req0 = $dbkb->mysqli_query("SELECT ...");
Sinon, la bonne pratique conseil de mettre la requête dans une variable intermédiaire pour pouvoir si possible l'afficher en cas de debug.
stat est un champ de type texte ?
Pourquoi utiliser LIKE alors que tu test une égalité ?
Dans ton test, tu peux aussi faire WHERE stat IN ('0','1','2','3')
jordane45
Messages postés37718Date d'inscriptionmercredi 22 octobre 2003StatutModérateurDernière intervention22 septembre 2023342 28 sept. 2014 à 00:12
J'ajouterai également.. qu'avant de lancer tes "boucles" il vaut mieux tester que la requête a retourné quelque chose...
$sql0 = "SELECT id, clientid, panne, diag, hardware, fait, timestamp, stat, urgent
FROM tbl_sav
WHERE stat IN ('0','1','2','3')";
$req0 = mysqli_query($sql0) ;
if($req0){
while($dn0 = mysqli_fetch_array($req0)){
$sql1 = 'SELECT name, phone
FROM tbl_clients
WHERE id="'.$dn0['clientid'].'"';
$req1 = mysqli_query($sql1);
if($req1){
while($dn1 = mysqli_fetch_array($req1)){
// le reste de ton code....
} // Fin while $dn1
}//fin IF req1
} // Fin while $dn0
} // Fin if $req0
Par contre... tu fais DEUX requêtes... alors que je pense que tu pourrais n'en faire qu'une avec une jointure...?
SELECT *
FROM tbl_sav S
,tbl_clients C
WHERE S.clientid = C.id
AND S.stat IN ('0','1','2','3')";
Ou encore :
SELECT *
FROM tbl_sav S
LEFT JOINT tbl_clients C ON S.clientid = C.id
WHERE S.stat IN ('0','1','2','3')";
J'obtient cette erreur : "Call to undefined method mysqli_result::mysqli_fetch_array()"
Je ne suis pas sur d'avoir fait sa correctement :
$req0 = mysqli_query($dbkb, "SELECT id, clientid, panne, diag, hardware, fait, timestamp, stat, urgent FROM tbl_sav WHERE stat LIKE '0' OR stat LIKE '1' OR stat LIKE '2' OR stat LIKE '3'"); while($dn0 = $req0->mysqli_fetch_array()){ $req1 = mysqli_query($dbkb, 'SELECT name, phone FROM tbl_clients WHERE id="'.$dn0['clientid'].'"'); while($dn1 = $req1->mysqli_fetch_array()){
NHenry
Messages postés15083Date d'inscriptionvendredi 14 mars 2003StatutModérateurDernière intervention19 septembre 2023159 28 sept. 2014 à 00:30
Problème résolu, une erreur très idiote de ma part, je me suis tromper de colonne, et je faisait les tests SQL sur la mauvaise base...
Grosse erreur d'inattention de ma part, désoler !
Merci pour l'aide apporter !
28 sept. 2014 à 00:12
Par contre... tu fais DEUX requêtes... alors que je pense que tu pourrais n'en faire qu'une avec une jointure...?
Ou encore :