Erreur de tableau
Résolu/Fermé
valentin
-
Modifié le 30 mai 2018 à 11:34
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 - 30 mai 2018 à 14:02
jordane45 Messages postés 38145 Date d'inscription mercredi 22 octobre 2003 Statut Modérateur Dernière intervention 25 avril 2024 - 30 mai 2018 à 14:02
A voir également:
- Erreur de tableau
- Tableau croisé dynamique - Guide
- Erreur 0x80070643 - Guide
- Tableau ascii - Guide
- Tableau word - Guide
- Le nom du champ de tableau croisé dynamique n'est pas valide ✓ - Forum Excel
4 réponses
jordane45
Messages postés
38145
Date d'inscription
mercredi 22 octobre 2003
Statut
Modérateur
Dernière intervention
25 avril 2024
4 650
Modifié le 30 mai 2018 à 11:38
Modifié le 30 mai 2018 à 11:38
Bonjour,
Où as tu initialisé ton array $matrice ?
De quelle manière ?
Où as tu initialisé ton array $matrice ?
De quelle manière ?
oui : $matrice = array_fill ( 1 , $nbLignes , array(0 , 4 , "0" ));
jordane45
Messages postés
38145
Date d'inscription
mercredi 22 octobre 2003
Statut
Modérateur
Dernière intervention
25 avril 2024
4 650
30 mai 2018 à 11:49
30 mai 2018 à 11:49
Donc... ta matrice ressemble à ça :
.. comme tu peux le voir .. les "indexes" commencent à ZERO et non à 1 .... (et vont jusqu'à 2 )
Donc
Ne peuvent pas fonctionner.... 3 et 4 sont en dehors de la dimension de ton array
Array ( [1] => Array ( [0] => 0 [1] => 4 [2] => 0 ) [2] => Array ( [0] => 0 [1] => 4 [2] => 0 ) [3] => Array ( [0] => 0 [1] => 4 [2] => 0 ) )
.. comme tu peux le voir .. les "indexes" commencent à ZERO et non à 1 .... (et vont jusqu'à 2 )
Donc
if($donneestag==5){ $matrice[$donneeseffect][3] = $matrice [$donneeseffect] [3] +1; } if($donneestag==6){ $matrice[$donneeseffect][4] = $matrice [$donneeseffect] [4] +1;
Ne peuvent pas fonctionner.... 3 et 4 sont en dehors de la dimension de ton array
AssassinTourist
Messages postés
5709
Date d'inscription
lundi 16 janvier 2012
Statut
Contributeur
Dernière intervention
29 février 2024
1 310
30 mai 2018 à 11:38
30 mai 2018 à 11:38
Bonjour,
Tout d'abord, inspire-toi de ça : https://forums.commentcamarche.net/forum/affich-37584947-php-gestion-des-erreurs-debogage-et-ecriture-du-code
Tout d'abord, inspire-toi de ça : https://forums.commentcamarche.net/forum/affich-37584947-php-gestion-des-erreurs-debogage-et-ecriture-du-code
oups dsl lu un peut tros vite : voici l'erreur maintenant :
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Warning: Illegal offset type in /Users/alainmeo/Desktop/base.php on line 65
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 0 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 1 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
Notice: Undefined offset: 2 in /Users/alainmeo/Desktop/base.php on line 94
0
le script en entier :
EDIT : AJout des balises de code (encore.......!!! )
<?php //$pass = "root"; //$user = "root"; //$host = "localhost"; error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); try { $bdd = new PDO('mysql:linux_socket=/Applications/MAMP/tmp/mysql/mysql.sock;host=127.0.0.1;port=8889;dbname=teste','root','root'); //;charset=utf8 //$user = 'root'; //$password = 'root'; //$db = 'teste'; //$host = 'localhost'; //$port = 8889; //$link = mysqli_init(); //$success = mysqli_real_connect( //$link, //$host, //$user, //$password, //$db, // $port //); // $user = 'root'; //$password = 'root'; //$db = 'inventory'; //$host = '127.0.0.1'; //$port = 8889; //$socket = 'localhost:/Applications/MAMP/tmp/mysql/mysql.sock'; //$link = mysqli_init(); //$success = mysqli_real_connect( // $link, //$host, //$user, //$password, //$db, //$port, //$socket //); } catch(Exception $e) { die('Erreur : '.$e->getMessage()); } //$bdd->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); //$compteur = 0; $nbLignes = $bdd->query('select count(*) from maTable'); // ou nb d'effect $matrice = array_fill ( 1 , $nbLignes , array(0 , 4 , "0" )); $reponcetag = $bdd->query('SELECT ID_tag FROM vote_tag_effect'); $reponceuser = $bdd->query('SELECT ID_user FROM vote_tag_effect'); $reponseeffect = $bdd->query('SELECT ID_effect FROM vote_tag_effect'); while ($donneeseffect = $reponseeffect->fetch()){ while ($donneesuser = $reponceuser->fetch()){ while ($donneestag = $reponcetag->fetch()){ $matrice[$donneeseffect][0] = $donneeseffect; if($donneestag==1){ $matrice[$donneeseffect][1] = $matrice [$donneeseffect] [1] +1; } if($donneestag==2){ $matrice[$donneeseffect][2] = $matrice [$donneeseffect] [2] +1; } if($donneestag==5){ $matrice[$donneeseffect][3] = $matrice [$donneeseffect] [3] +1; } if($donneestag==6){ $matrice[$donneeseffect][4] = $matrice [$donneeseffect] [4] +1; } //$compteur = $compteur +1; } } } $bdd = null; $nbdeffect=3; for ($i=0;$i<$nbdeffect;$i++) { for ($j=0;$j<=4;$j++){ printf("%b",$matrice[$i][$j]); } print("\n"); //print_r($matrice) } ?>
EDIT : AJout des balises de code (encore.......!!! )
jordane45
Messages postés
38145
Date d'inscription
mercredi 22 octobre 2003
Statut
Modérateur
Dernière intervention
25 avril 2024
4 650
30 mai 2018 à 11:56
30 mai 2018 à 11:56
Je ne comprend pas l'intéret de faire 3 requêtes sur la même table... alors qu'une seule suffit
$reponcetag = $bdd->query('SELECT ID_tag FROM vote_tag_effect'); $reponceuser = $bdd->query('SELECT ID_user FROM vote_tag_effect'); $reponseeffect = $bdd->query('SELECT ID_effect FROM vote_tag_effect');
$tesDatas = $bdd->query('SELECT ID_tag, ID_user,ID_effect FROM vote_tag_effect');
jordane45
Messages postés
38145
Date d'inscription
mercredi 22 octobre 2003
Statut
Modérateur
Dernière intervention
25 avril 2024
4 650
30 mai 2018 à 12:00
30 mai 2018 à 12:00
regarde donc ce que fait :
while ($donnees = $tesDatas->fetch()){ echo "<br>ID_tag : " . $donnees['ID_tag']; echo " ID_user : " . $donnees['ID_user']; echo " ID_effect: " . $donnees['ID_effect']; }