Reputation: 118
I need some help because my getRecipe.php is not showing the parameters or data shown like my other PHP files: getCourseType. It just appears blank and doesn't show anything in my browser.With the getRecipe.php it just display blank or nothing but I'm expecting the output like the image below for my getRecipe.php Perhaps you can modify my codes, answer it below and let me check it out if it works. Can you help me display those data of getRecipe.php from the database? thanks !
<?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");
}
?>
Yeah, it has data so it should display whenever I call it....
Upvotes: 0
Views: 93
Reputation:
try exemple like that :
$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);
Upvotes: 1