I have a JSON file that I have parsed using PHP. I take the JSON data and output it into a table. Below is a screenshot of what the output looks like:
What I'm trying to accomplish is for a user to enter the room number, press "SEARCH" and then have the data in the table auto scroll to whatever room number the user entered.
Here is what the JSON data looks like:
"apiVersion" : "0.1",
"data" : {
"roomCount" : 105,
"rooms" : [
{
"room_number" : "104",
"services" : [
{
"adult" : {
"enabled" : false
},
"room_charges" : {
"enabled" : true
}
}
],
"status" : "UNOCCUPIED"
},
{
"room_number" : "105",
"services" : [
{
"adult" : {
"enabled" : true
},
"room_charges" : {
"enabled" : false
}
}
],
"status" : "OCCUPIED"
And here is my code, that parses the JSON file, and outputs it into a table.
<?php
$response = file_get_contents("response.json");
$data = json_decode($response, true);
?>
<head>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<div>
<form id="response_form" action="#" method="POST" name="mainform"><br>
<label for="text"> Enter Room Number</label><br>
<input type="text" name="response_search" id="text" rows="1" cols="47"> </textarea><br>
<input type="submit" value="Search">
</form>
</div>
<div id="response_data">
<table>
<thead>
<tr>
<th width="188px">Room Number: </th>
<th width="193px">Adult:</th>
<th width="193px">Room Charges: </th>
<th width="212px">Status: </th>
</tr>
</thead>
<tbody>
<?php foreach($data['data']['rooms'] as $info): ?>
<tr id="scroll_through">
<td><?php echo $info['room_number']; ?></td>
<?php $services = reset($info['services']); ?>
<td><?php echo ($services['adult']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></td>
<td><?php echo ($services['room_charges']['enabled'] == 1) ? 'ENABLED' : 'DISABLED'; ?></td>
<td><?php echo $info['status']; ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
You'll notice in my code above that I have a form
where I'd like to make this happen. The steps that I have taken are as follows:
- I have tried changing the
action
of theform
, to<action='<?=$_SERVER['PHP_SELF']?>
and then writing anif
statement that attempts to match the text from the form to$info['room_number'];
but that didn't work at all... To be honest, I'm not even sure if I am doing it correctly. Any help would be appreciated.