-
Notifications
You must be signed in to change notification settings - Fork 0
/
fetch.php
107 lines (88 loc) · 3.71 KB
/
fetch.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
<?php
if (!empty($_POST['q']))
{
include "database.php";
$db = new database();//open database connection
$q = $_POST['q'];
$output = '<table class="table table-striped table-dark" id="table">';
//checking if the input is onlu blank spaces
$check = trim($q," ");
//modifying the clone input ($check) into alphanumeric by removing in between spaces in zeros
$check = str_replace(" ","0",$check);
if(ctype_alnum ($check)) //check if value is alphanumeric
{
//More than one words in the input
if (strstr($q, ' ')) //finding out if there is in between spaces
{
$Product_Names = explode(" ", $q); //segmenting the input word bu word
$item = $Product_Names[0];
$mother_query = "";
$query = "SELECT * FROM woolworths WHERE Product_Name LIKE '%".$item."%'";
$mother_query .= $query." UNION ALL ";
$query1 = "SELECT * FROM aldi WHERE Product_Name LIKE '%".$item."%'";
$mother_query .= $query1." UNION ALL ";
$query2 = "SELECT * FROM coles WHERE Product_Name LIKE '%".$item."%'";
$mother_query .= $query2;
$count = 1;
while($count < sizeof($Product_Names))
{
$mother_query = "";
$item = $Product_Names[$count];
$query = $query." AND Product_Name LIKE '%".$item."%' ";
$mother_query .= $query." UNION ALL ";
$query1 = $query1." AND Product_Name LIKE '%".$item."%' ";
$mother_query .= $query1." UNION ALL ";
$query2 = $query2." AND Product_Name LIKE '%".$item."%' ";
$mother_query .= $query2;
$count++;
}
$query = $query." ORDER BY Price ASC";
$query1 = $query1." ORDER BY Price ASC";
$query2 = $query2." ORDER BY Price ASC";
$mother_query = $mother_query."ORDER BY Price ASC";
//echo $mother_query;
$result3 = mysqli_query($db->conn,$mother_query);
while ($out=mysqli_fetch_assoc($result3))
{
//echo '<a>'.$out['Product_Name'].'</a><br>';
$output .= '<tr class="list" ><td>'.$out['Product_Name']."</td><td>$".$out['Price'].'</td><td>'.$out['Shop_Name'].'</td><td>'.$out['Unit_Price'].'</td><td style="display:none;"> '.$out['Product_ID'].'</td><td style="display:none;"> '.$out['Unit'].'</td></tr>';
}
// while ($out=mysqli_fetch_assoc($result1))
// {
// //echo '<a>'.$out['Product_Name'].'</a><br>';
// $output .= '<tr ><td class="list">'.$out['Product_Name']."</td><td>$".$out['Price'].'</td><td>aldi</td><td>'.$out['Unit_Price'].'</td></tr>';
// }
// while ($out=mysqli_fetch_assoc($result2))
// {
// //echo '<a>'.$out['Product_Name'].'</a><br>';
// $output .= '<tr ><td class="list">'.$out['Product_Name']."</td><td>$".$out['Price'].'</td><td>coles</td><td>'.$out['Unit_Price'].'</td></tr>';
// }
}
else
{
$mother_query = "";
// ORDER BY Price ASC
//only one word in the input
$query = "SELECT * FROM woolworths WHERE Product_Name LIKE '%".$q."%' ";
$mother_query .= $query." UNION ALL ";
$query1 = "SELECT * FROM aldi WHERE Product_Name LIKE '%".$q."%' ";
$mother_query .= $query1." UNION ALL ";
$query2 = "SELECT * FROM coles WHERE Product_Name LIKE '%".$q."%' ";
$mother_query .= $query2;
$mother_query .= " ORDER BY Price ASC";
//echo $mother_query;
$result3 = mysqli_query($db->conn,$mother_query);
while ($out=mysqli_fetch_assoc($result3))
{
$output .= '<tr class="list" ><td>'.$out['Product_Name']."</td><td>$".$out['Price'].'</td><td>'.$out['Shop_Name'].'</td><td>'.$out['Unit_Price'].'</td><td style="display:none;"> '.$out['Product_ID'].'</td><td style="display:none;"> '.$out['Unit'].'</td></tr>';
}
}
}
else
{
$output .= '<li>Input should be numbers or letters!!!</li>';
}
$output .= '</table>';
echo $output;
}
?>