2016-04-17 29 views
0

我需要一些幫助,因爲我的getRecipe.php沒有顯示像我的其他PHP文件所示的參數或數據:getCourseType。它只是顯示爲空白,並沒有在我的瀏覽器中顯示任何東西。與getRecipe.php它只是顯示空白或什麼都沒有,但我期待輸出像下面的圖像我的getRecipe.php也許你可以修改我的代碼,在下面回答,讓我看看它是否有效。你能幫我從數據庫中顯示getRecipe.php的數據嗎?謝謝 ! PHPMYADMIN方PHP:數據庫內的數據沒有顯示

getCourseType的截圖(這是工作)

enter image description here

getRecipe.php

<?php 
    require_once 'include/DB_Connect.php'; 
    $db = new Db_Connect(); 
    $conn = $db->connect(); 
    if(isset($_GET['recipeId'])){ 
    $id = $_GET['recipeId']; 
    $result = $conn->query("SELECT * FROM recipe where id=$id"); 
    }else{  
     $result = $conn->query("SELECT * FROM recipe"); 
    } 

    if ($result->num_rows > 0) { 
     $list = array(); 
     while($row = $result->fetch_assoc()) { 
      array_push($list, $row); 
     } 
     echo json_encode(array('result' => $list)); 
    } else { 
     echo json_encode("no result"); 
    } 
    ?> 

截圖

呀,它有數據,所以它應該顯示每當我稱之爲......

enter image description here

+0

你可能有一個頁面上的錯誤和關閉錯誤報告。在腳本的開始處打開E_ALL級別,查看它是否告訴了某些事情 - http://php.net/manual/en/function.error-reporting.php – PetrHejda

回答

1

試爲例那樣:

$id_user=$_POST['id_user']; 
$bdd = new PDO('mysql:host=localhost;dbname=db_name', 'root', ''); 
$req = $bdd->prepare('select * from event where id_user = ?'); 
$req->execute(array($id_user)); 
//$_SESSION['id'] 

    $response["events"] = array(); 

    while( $donnees = $req->fetch()){ 
    $endroits = array(); 
    $endroits ['titre']=$donnees['titre']; 
    $endroits ['date']=$donnees['date']; 


    array_push($response["events"], $endroits); 
    } 

print json_encode($response);