-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
107 lines (97 loc) · 3.11 KB
/
index.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
require 'Clothes.php';
$indexName = "WomenClothes";
$objClothes = new Clothes($indexName);
$infoClothes = $objClothes->getInformationClothes("skirt", 10);
$infoClothes = $objClothes->arrayToJSON($infoClothes);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<title> Get clothes </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css"
integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous">
<style>
#livesearch {
color:red;
}
</style>
</head>
<body>
<div class="container">
<h1>Escenario 1 <small>La consulta es "dress". </small></h1>
<?php //echo $infoClothes; ?>
<?php //if ($infoClothes == "Please, try with other option"): ?>
<h3>
<?php echo $infoClothes; ?>
</h3>
<?php /*else: ?>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Price</th>
<th>Designer</th>
</tr>
</thead>
<tbody>
<?php foreach ($infoClothes as $clothes): ?>
<tr>
<th>
<?php echo $clothes["name"]; ?>
</th>
<td>
<?php echo $clothes["price"]; ?>
</td>
<td>
<?php echo $clothes["designer"]; ?>
</td>
</tr>
<?php endforeach ?>
</tbody>
</table>
<?php// endif */?>
<br>
<h1>Escenario 2
<small>Desplegar en una pagina de HTML en formato texto,
el nombre ("name") de las 5 prendas de cualquier consulta
que haga el usuario a través de un campo de texto que
estará en la misma página.</small></h1>
<form>
<h2>Nombre prenda (inglés)</h2>
<input type="text" class="form-control" onkeyup="showResult(this.value)">
<div id="livesearch"></div>
</form>
<br><br><br><br><br>
</div>
<script>
/*
Next code is based:
http://www.tutorialspoint.com/php/php_ajax_autocomplete_search.htm
*/
function showResult(str) {
if (str.length==0) {
document.getElementById("livesearch").innerHTML="";
document.getElementById("livesearch").style.border="0px";
return;
}
if (window.XMLHttpRequest) {
xmlhttp=new XMLHttpRequest();
}
else
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("livesearch").innerHTML=xmlhttp.responseText;
document.getElementById("livesearch").style.border="1px solid #A5ACB2";
}
}
xmlhttp.open("GET","livesearch.php?question="+str,true);
xmlhttp.send();
}
</script>
</body>
</html>