Problèmed'affichagedeplus de 10enregistrements(pagesuivante)

Fermé
Utilisateur anonyme - 19 août 2014 à 14:39
Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022 - 19 août 2014 à 15:16
Bonjour à tous !
Je développe une application PHP qui gère les différents achats de produits effectués et leur stockage au magasin. Les objectifs sont d'afficher la liste de tous les achats effectués de façon générale et la liste des achats au cours d'une période donnée par l'utilisateur. J'ai limité les listes à 10 enregistrements par page. Lorsque les enregistrements sont inférieurs ou égaux à 10 pas de problème, l'affichage est parfait. Mais lorsque les enregistrements sont supérieurs à 10, sur la page suivante il affiche des erreurs et ne renvoie pas les enregistrements qui son sensés suivre. Voici les messages d'erreurs qu'il affiche :
* Notice: Undefined index: ok in C:\wamp\www\suremanager\rapportachat1.php on line 52
* Notice: Undefined variable: note in C:\wamp\www\suremanager\rapportachat1.php on line 104
* Notice: Undefined variable: rek in C:\wamp\www\suremanager\rapportachat1.php on line 108
* Warning: mysql_num_rows() expects parameter 1 to be resource, boolean given in C:\wamp\www\suremanager\rapportachat1.php on line 111
Aucun Achat Effectué à cette période
NB : J'utilise un calendrier pour saisir la date dans le deuxième cas et des boutons radios pour chaque cas.
Voici le code source du fichier rapportachat1.php
<?php
include ("sql/sqlfonction.php");
$type=$_POST['ok'];
if($type=='all'){
$type1=$_POST['ok1'];
if($type1=='gen'){
$id_magasin= ' ';
$rek="select * from achat";
$note="Achat Global de Produits";
$re=mysql_query("select nom_magasin from magasin where magasin.id_magasin='$id_magasin'");
$ta=mysql_fetch_array($re);
}
elseif($type1=='comp'){
$id_magasin= '';
$datedeb=$_POST['dat1'];
$datefin=$_POST['dat2'];
$rek="select * from achat where achat.date_achat>='$datedeb' and achat.date_achat<='$datefin'";
$datedeb=date("d-m-Y", strtotime($datedeb));
$datefin=date("d-m-Y", strtotime($datefin));
$note="Achat Global de Produits Effectué du <b>$datedeb au <b>$datefin";
$re=mysql_query("select nom_magasin from magasin where magasin.id_magasin='$id_magasin'");
$ta=mysql_fetch_array($re);
}
}
elseif($type=='choix'){
$type1=$_POST['ok1'];
if($type1=='gen'){
$id_magasin=$_POST['id_magasin'];
$datedeb=$_POST['dat1'];
$datefin=$_POST['dat2'];
$rek="select * from achat,pisteur,magasin where magasin.id_magasin='$id_magasin' and pisteur.id_pisteur=achat.id_pisteur and magasin.id_magasin=achat.id_magasin";
$re=mysql_query("select nom_magasin from magasin where magasin.id_magasin='$id_magasin'");
$ta=mysql_fetch_array($re);
$note=$ta['nom_magasin'];
$note="Achats Effectués par le $note";
}
elseif($type1=='comp'){
$id_magasin=$_POST['id_magasin'];
$datedeb=$_POST['dat1'];
$datefin=$_POST['dat2'];
$rek="select * from achat,pisteur,magasin where magasin.id_magasin='$id_magasin' and pisteur.id_pisteur=achat.id_pisteur and magasin.id_magasin=achat.id_magasin and achat.date_achat>='$datedeb' and achat.date_achat<='$datefin'";
$datedeb=date("d-m-Y", strtotime($datedeb));
$datefin=date("d-m-Y", strtotime($datefin));
$re=mysql_query("select nom_magasin from magasin where magasin.id_magasin='$id_magasin'");
$ta=mysql_fetch_array($re);
$tino=$ta['nom_magasin'];
$note="Achats Effectués par le $tino du <b>$datedeb au <b>$datefin";
}
}
echo "<br />";
echo "<h1>Rapport des Achats </h1> ";
echo "<table align='center' class='tab_cadre'>
<tr class='tab_bg_1'><td align='center' colspan='6'>";
echo $note;
echo "</td></tr>
<tr class='tab_bg_1'><TD align='center'>Produit Acheté</TD><TD align='center'>Qté Acheté (Kg)</TD> <td align='center'>Nbre Sacs</TD><td align='center'>Date d'Achat</TD><TD align='center'>Nom Pisteur</TD><TD align='center'>Nom Paysan</TD></tr>";
$rek.=" ORDER BY achat.id_achat DESC ";
$resco=mysql_query($rek);
$res=ymysql_query($rek,$deb,$nbre);
$result=mysql_num_rows($resco);
if($result){
while($tab=mysql_fetch_array($res)){
$prdt_achat=$tab['prdt_achat'];
$qte_achat=$tab['qte_achat'];
$nbre_sac=$tab['nbre_sac'];
$date_achat=$tab['date_achat'];
$date_achat=date("d-m-Y", strtotime($date_achat));
$pisteur=$tab['id_pisteur'];
$pist=id2namepisteur($pisteur);
$nom_paysan=$tab['nom_paysan'];
echo "<tr class='tab_bg_2' align='left'><td align='left'>$prdt_achat</td><td align='center'>$qte_achat</td><td align='center'>$nbre_sac</td><td align='center'>$date_achat</td><td align='left'>$pist</td><td align='left'>$nom_paysan</td></tr>";
}
}else{
echo "<tr class='tab_bg_3' align='center'><td colspan='6'><h2>Aucun Achat Effectué à cette période</h2></td></tr>";
}
echo "<tr align='center'><td colspan='6' align='center'>";
if ($result!=0){
if ($result>$nbre-1){?>
(Enregistrement de <?php echo $deb+1;?> à <?php echo $fin;?> sur <?php echo $result?>)   
<?php }else { if (($result<=$nbre-1) && ($result>0)){?>
(Enregistrement de 1 à <?php echo $result?>)   
<?php }else {?> (Pas d'enregistrement)    <?php }}
if($result>$nbre) { ?>
<a title="Première Page" href="rapportachat1.php?deb=0&fin=<?php echo $nbre;?>"><img src="./images/first.png" alt="premier" border="0"></a> premier   
<?php $dif=$deb-$nbre;
if($dif >=0){?>
<a title="Page Prédente" href="rapportachat1.php?deb=<?php echo $deb -$nbre;?>&fin=<?php echo $deb;?>"><img src="./images/prev.png" alt="precedent" border="0"></a>  precedent   
<?php }
else{?><a title="debut de page"><img src="./images/prev.png" alt="precedent" border="0">  precedent   </a><?php }?>
<?php $dif=$result-$fin;
if( $dif >=$nbre){?>
<a title="Page Suivante" href="rapportachat1.php?deb=<?php echo $fin;?>&fin=<?php echo $fin+$nbre;?>"><img src="./images/next.png" alt="suivant" border="0"></a> suivant   
<?php } else
if(( $dif >0) &&($dif<$nbre)){?><a title="Page Suivante" href="rapportachat1.php?deb=<?php echo $fin;?>&fin=<?php echo $fin+$dif;?>"><img src="./images/next.png" alt="suivant" border="0"></a> suivant   
<?php }else{?><a title="Fin de page"><img src="./images/next.png" alt="suivant" border="0">  suivant   </a><?php }?>
<?php $dif=$result-$nbre;
if( $dif >=0){
if(($dif % $nbre)==0){?>
<a title="Dernière Page" href="rapportachat1.php?deb=<?php echo $result -$nbre;?>&fin=<?php echo $result;?>"><img src="./images/last.png" alt="dernier" border="0"></a> dernier   
<?php }else{ ?><a title="Dernière Page" href="rapportachat1.php?deb=<?php echo $result -$nbre+1;?>&fin=<?php echo $result;?>"><img src="./images/last.png" alt="dernier" border="0"></a> dernier   
<?php }
} else { ?><a title="Fin de page"><img src="./images/last.png" alt="dernier" border="0">  dernier   </a><?php }?>
<?php } else { ?>
<a title="Première Page"><img src="./images/first.png" alt="premier" border="0"></a> premier   
<a title="debut de page"><img src="./images/prev.png" alt="precedent" border="0">  precedent   </a>
<a title="Fin de page"><img src="./images/next.png" alt="suivant" border="0">  suivant   </a>
<a title="Dernière Page"><img src="./images/last.png" alt="dernier" border="0"></a> dernier    <?php } }
echo "</TD></tr></table>";
?>
Voici la table achat:
CREATE TABLE IF NOT EXISTS 'achat' (
'id_achat' int(11) NOT NULL AUTO_INCREMENT,
'prdt_achat' varchar(255) NOT NULL DEFAULT '0',
'nbre_sac' varchar(255) NOT NULL DEFAULT '',
'qte_achat' varchar(25) NOT NULL DEFAULT '',
'moisie_mitee' varchar(10) NOT NULL,
'ardoisee' varchar(10) NOT NULL,
'grainage' varchar(10) NOT NULL,
't_humidite' varchar(10) NOT NULL,
'dechet' varchar(10) NOT NULL,
'matiere_etrangere' varchar(10) NOT NULL,
'date_achat' date NOT NULL,
'nom_paysan' varchar(255) NOT NULL DEFAULT '',
'id_pisteur' int(11) NOT NULL DEFAULT '0',
'id_magasin' int(11) NOT NULL DEFAULT '0',
PRIMARY KEY ('id_achat'),
KEY 'id_pisteur' ('id_pisteur'),
KEY 'id_magasin' ('id_magasin')
) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=25 ;

INSERT INTO 'achat' ('id_achat', 'prdt_achat', 'nbre_sac', 'qte_achat', 'moisie_mitee', 'ardoisee', 'grainage', 't_humidite', 'dechet', 'matiere_etrangere', 'date_achat', 'nom_paysan', 'id_pisteur', 'id_magasin') VALUES
(2, 'Café', '32', '700', '31', '7', '1', '5', '1', '2', '2014-06-27', 'KOUAKOU Kan Victor', 3, 12),
(3, 'Cacao', '28', '500', '5', '3', '1', '6', '1', '2', '2014-04-06', 'YAPO Isidore', 1, 9),
(5, 'Cacao', '96', '754', '4', '7', '6', '3', '20', '14', '2014-04-30', 'KOFFI Albert', 3, 11),
(7, 'Cacao', '80', '467', '8', '5', '4', '10', '24', '6', '2014-05-12', 'MEITE Abdoul', 2, 10),
(8, 'Cacao', '81', '187', '10', '12', '18', '9', '7', '13', '2014-04-30', 'MEITE Aboubacar', 2, 8),
(9, 'Coton', '31', '1548', '9', '7', '6', '10', '20', '14', '2014-02-28', 'SORO Mama', 3, 9),
(11, 'Cacao', '307', '157', '8', '10', '13', '9', '5', '11', '2014-08-05', 'CLOFFIE Adama', 4, 11),
(12, 'Hévéa', '250', '17400', '8', '9', '10', '13', '7', '11', '2014-07-11', 'OUATTARA Fousséni', 6, 9),
(13, 'Café', '31', '3100', '9', '7', '5', '4', '6', '10', '2014-08-08', 'YOBOUET Frederic', 7, 8),
(14, 'Café', '25', '1020', '7', '8', '7', '8', '7', '9', '2014-01-15', 'KOUAME Yao Anderson', 4, 9),
(15, 'Cacao', '63', '6300', '7.5', '4.2', '10.4', '9.4', '10.13', '8.4', '2014-08-11', 'GNAMIEN Koukou Fulgence', 7, 11),
(16, 'Palmier à Huile', '90', '85900', '7.5', '6.4', '3.4', '2.7', '10.11', '21.08', '2014-08-14', 'YAPI Alain', 6, 10),
(17, 'Banane', '80', '80000', '7.5', '10.1', '5.04', '6.4', '7.8', '10.5', '2014-08-14', 'OUEDRAOGO Alpha', 8, 8),
(18, 'Hévéa', '30', '45200', '3.1', '2.0', '10.4', '11', '19', '7.57', '2014-04-16', 'MAMBE Georges', 2, 9),
(19, 'Cacao', '65', '632400', '2', '10', '4.4', '13.2', '4.9', '10.5', '2014-03-04', 'GOGOUA Denorse', 3, 9),
(20, 'Palmier à Huile', '36', '31400', '5.4', '3.10', '4.7', '4.9', '2.6', '7.4', '2014-04-29', 'KALOU Fregus', 4, 9),
(21, 'Cacao', '67', '68400', '8.4', '6.7', '10.2', '15.4', '3.78', '4.5', '2014-01-23', 'DIANGONE Bi Israel', 9, 9),
(22, 'Café', '60', '6500', '10', '11.2', '3.7', '8.7', '9.40', '30.4', '2014-02-28', 'SERYKPA Olivier', 8, 9),
(23, 'Cacao', '29', '2900', '7.4', '6.4', '2.4', '3.1', '9.10', '9.34', '2014-05-14', 'KOFFI Crépin', 4, 9),
(24, 'Coton', '80', '8000', '8.4', '9.7', '4.6', '3.2', '7.1', '8.4', '2014-06-10', 'ISSOUFOU Moussa', 3, 9);

Aidez- moi svp, Coordialement

1 réponse

Pitet Messages postés 2826 Date d'inscription lundi 11 février 2013 Statut Membre Dernière intervention 21 juillet 2022 524
19 août 2014 à 15:16
Undefined index : ok -> la clé 'ok' dans le tableau n'existe pas (en effect, $_POST['ok'] n'existe pas si ton formulaire n'est pas renvoyé)

Undefined variable : note -> tu utilises une variable qui n'est pas initialisé

mysql_num_rows() expects parameter 1 to be resource, boolean given -> ta requête sql est incorrect (surement à cause des erreurs précédentes). Affiche ta requête pour la corriger plus facilement

C'est plus facile de t'aider si tu ne multiplie pas tes sujets : https://forums.commentcamarche.net/forum/affich-30675133-probleme-d-affichage#p30678262
0