-
Notifications
You must be signed in to change notification settings - Fork 1
/
breakfast.php
87 lines (61 loc) · 2 KB
/
breakfast.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
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
<?php
// $response=array();
// $response['flag']=0;
include("connection.php");
if($_SERVER['REQUEST_METHOD']=='POST')
{
$inputDrinksList=$_POST['ingredients_array'];
$drinksArray=json_decode($inputDrinksList,true);
$arringredient=array();
$arringredientname=array();
$drinksArray = array_column($drinksArray, 'name');
$array_count=array_count_values($drinksArray);
foreach($array_count as $key => $value){
if($value=='2' OR $value=='4' ){
foreach (array_keys($drinksArray, $key, true) as $unsetKey) {
unset($drinksArray[$unsetKey]);
}
}
}
print_r($drinksArray);
foreach ($drinksArray as $key => $value) {
// print_r($value);
// echo "\n";
$sql= "SELECT * from `ingredient` WHERE ingredient_name='$value';";
$result=mysqli_query($con,$sql);
$resultCheck= mysqli_num_rows($result);
if($resultCheck>0)
{
while($row=mysqli_fetch_assoc($result)){ //fetch_assoc fetches the data in an arrAY SO HERE ROW IS AN ARRAY
$id= $row['ingredient_id'];
}
$sql2="SELECT * FROM `can_be_made` WHERE ingredient_id='$id';";
$result2=mysqli_query($con,$sql2);
$resultCheck2= mysqli_num_rows($result2);
if($resultCheck2>0)
{
while($row=mysqli_fetch_assoc($result2)){ //fetch_assoc fetches the data in an arrAY SO HERE ROW IS AN ARRAY
$arr= $row['recipe_id'];
array_push($arringredient, $arr);
//print_r($arr);
}
//echo "\n";
}
}
}
# code...
sort($arringredient);
print_r($arringredient);
$dups = array();
foreach(array_count_values($arringredient) as $val => $c)
if($c > 1) $dups[] = $val;
print_r($dups);
//to print recipe from database:
for($i=0;$i<count($dups);$i++)
{
$sql3= "INSERT into `display` SELECT * from `recipe` WHERE recipe_id='$dups[$i]'&& category='Breakfast';";//&& category='Drinks'
$result3=mysqli_query($con,$sql3);
$resultCheck3= mysqli_num_rows($result3);
}
}
?>