IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

problème réception ma base de donné sur tableau


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 275
    Par défaut problème réception ma base de donné sur tableau
    bonjour, J'ai un problème avec mon code, je n'arrive pas recevoir les données de la base à donner pour mon tableau
    Voici le code du tableau et des requete
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    <?php
    /* Database connection start */
    $servername = "localhost";
    $username = "root";
    $password = "Mm101010";
    $dbname = "smartphone";
     
    $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
     
    /* Database connection end */
     
     
    // storing  request (ie, get/post) global array to a variable  
    $requestData= $_REQUEST;
     
     
    $columns = array( 
    // datatable column index  => database column name
        0 => 'Or_Affectation', 
    	1 => 'USER_ID', 
    	2 => 'Nom',
    	3 => 'Prenom',
    	4 => 'Num_SIM', 
    	5 => 'PIN_Terminal',
    	6 => 'PIN_SIM', 
    	7 => 'Num_IMEI',
    	8 => 'Date_Debut', 
    	9 => 'Date_Fin',
       10 => 'Vitre', 
       11 => 'Coque',
       12 => 'Support_Vehicule', 
       13 => 'Actif',
       14 => 'Statut'
     
    );
     
    // getting total number records without any search
    $sql = "SELECT Or_Affectation ";
    $sql.=" FROM vu_affect_empl";
    $query=mysqli_query($conn, $sql) or die("Affectation.php: get employees");
    $totalData = mysqli_num_rows($query);
    $totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.
     
     
    $sql = "SELECT Or_Affectation, USER_ID, Nom, Prenom, Num_SIM, PIN_Terminal, PIN_SIM, Num_IMEI, Date_Debut, Date_Fin, Vitre, Coque, Support_Vehicule, Actif,  Statut ";
    $sql.=" FROM vu_affect_empl WHERE 1=1";
    if( !empty($requestData['search']['value']) ) {   // if there is a search parameter, $requestData['search']['value'] contains search parameter
    	$sql.=" AND ( USER_ID LIKE '".$requestData['search']['value']."%' ";    
    	$sql.=" OR Num_SIM LIKE '".$requestData['search']['value']."%' ";
     
    	$sql.=" OR Nom LIKE '".$requestData['search']['value']."%' )";
    }
    $query=mysqli_query($conn, $sql) or die("Affectation.php: get employees");
    $totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
    $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
    /* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc  */	
    $query=mysqli_query($conn, $sql) or die("Affectation.php: get employees");
     
    $data = array();
    $i=1+$requestData['start'];
    while( $row=mysqli_fetch_array($query) ) {  // preparing an array
    	$nestedData=array(); 
     
    	$nestedData[] = "<input type='checkbox'  class='deleteRow' value='".$row['Or_Affectation']."'  /> #".$i ;
    	$nestedData[] = $row["USER_ID"];
    	$nestedData[] = $row["Nom"];
    	$nestedData[] = $row["Prenom"];
    	$nestedData[] = $row["Num_SIM"];
    	$nestedData[] = $row["PIN_Terminal"];
    	$nestedData[] = $row["PIN_SIM"];
    	$nestedData[] = $row["Num_IMEI"];
    	$nestedData[] = $row["Date_Debut"];
    	$nestedData[] = $row["Date_Fin"];
    	$nestedData[] = $row["Vitre"];
    	$nestedData[] = $row["Coque"];
    	$nestedData[] = $row["Support_Vehicule"];
    	$nestedData[] = $row["Actif"];
    	$nestedData[] = $row["Statut"];
     
    	$data[] = $nestedData;
    	$i++;
    }
     
     
     
    $json_data = array(
    			"draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
    			"recordsTotal"    => intval( $totalData ),  // total number of records
    			"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
    			"data"            => $data   // total data array
    			);
     
    echo json_encode($json_data);  // send data as json format
     
    ?>
    index.php
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    <?php
    /* Database connection start */
    $servername = "localhost";
    $username = "root";
    $password = "Mm101010";
    $dbname = "employee";
     
    $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());
     
    /* Database connection end */
     
     
    // storing  request (ie, get/post) global array to a variable  
    $requestData= $_REQUEST;
     
     
    $columns = array( 
    // datatable column index  => database column name
    	0 =>'employee_name', 
    	1 => 'employee_salary',
    	2=> 'employee_age'
    );
     
    // getting total number records without any search
    $sql = "SELECT id ";
    $sql.=" FROM employee";
    $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
    $totalData = mysqli_num_rows($query);
    $totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.
     
     
    $sql = "SELECT id, employee_name, employee_salary, employee_age ";
    $sql.=" FROM employee WHERE 1=1";
    if( !empty($requestData['search']['value']) ) {   // if there is a search parameter, $requestData['search']['value'] contains search parameter
    	$sql.=" AND ( employee_name LIKE '".$requestData['search']['value']."%' ";    
    	$sql.=" OR employee_salary LIKE '".$requestData['search']['value']."%' ";
     
    	$sql.=" OR employee_age LIKE '".$requestData['search']['value']."%' )";
    }
    $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
    $totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
    $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
    /* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc  */	
    $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
     
    $data = array();
    $i=1+$requestData['start'];
    while( $row=mysqli_fetch_array($query) ) {  // preparing an array
    	$nestedData=array(); 
     
    	$nestedData[] = "<input type='checkbox'  class='deleteRow' value='".$row['id']."'  /> #".$i ;
    	$nestedData[] = $row["employee_name"];
    	$nestedData[] = $row["employee_salary"];
    	$nestedData[] = $row["employee_age"];
     
    	$data[] = $nestedData;
    	$i++;
    }
     
     
     
    $json_data = array(
    			"draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
    			"recordsTotal"    => intval( $totalData ),  // total number of records
    			"recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
    			"data"            => $data   // total data array
    			);
     
    echo json_encode($json_data);  // send data as json format
     
    ?>
    pouvez-vous me dire pourquoi je ne recois rien sur mon tableau?
    merci

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Merci pour ce pâté de code

    As-tu fais le debugage basique : afficher la requête, l'executer dans phpmyadmin ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre éclairé
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2016
    Messages
    275
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 35
    Localisation : France, Essonne (Île de France)

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Avril 2016
    Messages : 275
    Par défaut
    sa fonctionne, c'était un soucis d’incrémentation sur phpmyadmin

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. Réponses: 4
    Dernier message: 18/01/2011, 10h08
  2. Réponses: 1
    Dernier message: 05/03/2008, 17h52
  3. Réponses: 8
    Dernier message: 11/10/2006, 17h28
  4. [ODBC] [DB2] Problème de connexion à une base de données sur un as400 via PHP sous Linux
    Par boo64 dans le forum PHP & Base de données
    Réponses: 16
    Dernier message: 19/04/2006, 09h51

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo