-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetRecipes.php
39 lines (33 loc) · 889 Bytes
/
getRecipes.php
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
<?php
/**
* Created by IntelliJ IDEA.
* User: micha
* Date: 2/26/2018
* Time: 3:03 AM
*/
session_start();
require 'database.php';
$username = 'michael';
$stmt = $mysqli->prepare("SELECT recipe_name, recipe_ingredients, recipe_steps FROM recipes WHERE username=?");
if(!$stmt){
printf("Query Prep Failed: %s\n", $mysqli->error);
exit;
}
$stmt->bind_param('s', $username);
$stmt->execute();
$stmt->bind_result($recipe_name, $recipe_ingredients, $recipe_steps);
//$stmt->fetch();
$arr = array();
$cnt = 1;
while($stmt->fetch()){
// array_push($arr, "recipe" . $cnt, $recipe_name);
// array_push($arr, "steps" . $cnt, $recipe_steps);
$arr["recipe"][] = $recipe_name;
$arr["ingredients"][] = $recipe_ingredients;
$arr["steps"][] = $recipe_steps;
// $arr["ingredients"] = $recipe_ing;
// $cnt = $cnt + 1;
}
$stmt->close();
echo json_encode($arr);
?>