2016-05-09 11 views
-1

私はjsonで結果を与えるphpのコードを持っています。ここではブラウザ上でPHPスクリプトを試しても結果はありません。ここにphpファイルとmysqlテーブルがありますjson dosn'tの結果とPHPで表示されないエラー

<?php 
    //Importing Database Script 
    require_once('dbConnect.php'); 

    //Creating sql query 
    $sql = "SELECT * FROM EnfantVaccin"; 

    //getting result 
    $r = mysqli_query($con,$sql); 

    //creating a blank array 
    $result = array(); 

    //looping through all the records fetched 
    while($row = mysqli_fetch_array($r)){ 

     //Pushing name and id in the blank array created 
     array_push($result,array(
      "enfant_vacc_id"=>$row['enfant_vacc_id'], 
      "enfant_id"=>$row['enfant_id'], 
      "nomVaccin"=>$row['nomVaccin'], 
      "ageApproprie"=>$row['ageApproprie'], 
      "etat"=>$row['etat'], 
      "date_vaccin"=>$row['date_vaccin'] 
     )); 
    } 

    //Displaying the array in json format w samineh result itableau fi json format 5ater valeur mta3 notre TAG_JSON_ARRAY hia result 
    echo json_encode(array('resultVaccinEnf'=>$result)); 

    mysqli_close($con); 

、それはMySQLのテーブルの 'EnfantVaccin'

CREATE TABLE `EnfantVaccin`(
`enfant_vacc_id` bigint(50) unsigned NULL DEFAULT NULL AUTO_INCREMENT, 
`enfant_id` bigint(50) unsigned NULL DEFAULT NULL , 
`nomVaccin` varchar(20) NOT NULL, 
`ageApproprie` int(10) NOT NULL, 
`etat` boolean NOt null ,/*ca indique si ce vaccin particulier est fait pour cet enfant particulier ou pas */ 
`date_vaccin` date not null,/*indique la date de ce vaccin pour cet enfant*/ 
PRIMARY KEY (`enfant_vacc_id`) , 
CONSTRAINT `FK_enf2` FOREIGN KEY (`enfant_id`) REFERENCES `enfant` (`enfant_id`) 
)ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8; 

、それは

enter image description here

テーブルに私が持っている行です

私は

+0

が何も出力、または単に白い画面い本当に混乱していますヘルプを見つけることができると思います。あなたが提供したコードから、私は少なくともいくつかの出力を期待しています。 –

+0

白い画面 – bigginerEngeneer

+0

がfetch_arrayの構文で 'while($ row = mysqli_fetch_array($ r、MYSQLI_ASSOC)){'これが動作しない理由でMYSQLI_ASSOCを追加しようとすると結果を送ることができます。私は準備文を使って提案します。 –

答えて

0
if($stmt = mysqli_prepare($con, $sql)){ 
     //execute query 
     mysqli_stmt_execute($stmt); 
     //bind results 
     mysqli_stmt_bind_result($stmt, $enfant_vacc_id, $enfant_id, $nomVaccin, $ageApproprie, $etat, 
     $date_vaccin); 
     //store result so num rows can be counted 
     $r = mysqli_stmt_store_result($stmt); 
     $result = array(); 
     //fetch results 
     while (mysqli_fetch_array($r)) { 
     //Pushing name and id in the blank array created 
     array_push($result,array(
      "enfant_vacc_id"=>$enfant_vacc_id, 
      "enfant_id"=>$enfant_id, 
      "nomVaccin"=>$nomVaccin, 
      "ageApproprie"=>$ageApproprie, 
      "etat"=>$etat, 
      "date_vaccin"=>$date_vaccin 
     )); 
     } 
     //Displaying the array in json format w samineh result itableau fi json format 5ater valeur mta3 notre TAG_JSON_ARRAY hia result 
    echo json_encode(array('resultVaccinEnf'=>$result)); 
    mysqli_close($con); 
    } 
    else { 
    // Error 
    printf("Prepared Statement Error: %s\n", $db->error); 
    } 
+0

あなたが提供したスクリプトを試しました。エラーが 'Prepared Statement Error:'で始まる場合、このエラーは – bigginerEngeneer

+0

でした。 –

+0

no @Peter Darmisそれは、エラー警告:mysqli_fetch_array()は、パラメータ1がmysqli_result、C:\ wamp \ www \ myChild \ adminPages \ affiche \ affVaccinEnfant.phpで指定されたブール値を期待しています。スクリーンショットを入れる – bigginerEngeneer

関連する問題