Skip to content

Instantly share code, notes, and snippets.

@edprince
Created August 21, 2014 13:53
Show Gist options
  • Save edprince/3328a45478b93ccbd463 to your computer and use it in GitHub Desktop.
Save edprince/3328a45478b93ccbd463 to your computer and use it in GitHub Desktop.
UDP PACKET PRESENTATION #1
<?php
#session_start();
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css"
<link href="index.html">
<link href="displaydatatest.php">
<script>
var MT4000 = False;
var AllData = True;
//Go to W3Schools for example with "q"
function loadXMLDoc(int)
{
var xmlhttp;
var url = "displaydatatest.php?q="
if (window.XMLHttpRequest)
{// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp=new XMLHttpRequest();
}
else
{// code for IE6, IE5
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange=function()
{
if (xmlhttp.readyState==4 && xmlhttp.status==200)
{
document.getElementById("displayData").innerHTML=xmlhttp.responseText;
}
}
xmlhttp.open("GET", url + int + MT4000,true);
xmlhttp.send();
}
function MT4000 {
MT4000 = True;
AllData = False;
}
function AllData {
MT4000 = False;
AllData = True;
}
</script>
<!--Number of results form-->
<body>
<p class='title'>Presenting udp packet data</p><hr />
<div class="selectDevice">
<input type="button" id="MT4000" value="MT4000" onclick="MT4000()">
<input type="button" id="allData" value="All Data" onclick="AllData()">
</div>
<center><div class='data-window'>
<form action="getData.php" method="GET" id="getSearchNumber">
<input type="text" name="NumberOfResults" id="noOfResults" placeholder="Number of desired results..." equied="required" autocomplete="off" onkeyup="loadXMLDoc(this.value)">
<!--<input type="submit" name="submitSearch" onclick="loadXMLdoc(document.getElementById('noOfResults'))">-->
</form>
<div id="displayData">
</div>
<?php
#$currentHighest = $_SESSION['currentHighest'];
#echo $currentHighest;
?>
</body>
</html>
<?php
#session_start();
?>
<html>
<head>
<link href="displaydata.php"></link>
</head>
<?php
//Set variable $noOfResults
//Display errors
ini_set('display_errors' ,1);
error_reporting(E_ALL);
if ($_GET['q'] !== "") {
try {
$noOfResults = $_GET["q"];
} catch(Exception $e) {
echo $e;
}
if (isset($noOfResults)) {
echo "";
} else {
echo"Variable setting failed";
}
$dbcnx = mysql_connect('localhost', 'ed', 'simpleiot');
if (!$dbcnx) {
echo 'Unable to connect at this time...';
exit();
}
echo "";
#Select Database
mysql_select_db('udp', $dbcnx);
if (!@mysql_select_db('udp')) {
exit('Unable to locate the udp ' . 'database at this time.');
}
echo "";
#Set query
$result = mysql_query("SELECT * FROM data ORDER BY id DESC LIMIT $noOfResults");
if (!$result) {
exit('Error performing query: ' . mysql_error());
}
# $_SESSION['currentHighest'] = mysql_query("SELECT MAX(id) FROM data");
#Display results
while ($row = mysql_fetch_array($result)) {
$data = json_encode($row['date'] . $row['id'] . base64_decode( $row['packetdata']));
echo trim($data);
}
# echo "<hr align='center' width='90%' />";
}
# echo "</div></center>";
#}
?>
</html>
<?php
session_start();
?>
<html>
<head>
<link href="displaydata.php"></link>
</head>
<?php
//Set variable $noOfResults
//Display errors
ini_set('display_errors' ,1);
error_reporting(E_ALL);
if ($_GET['q'] !== "") {
try {
$noOfResults = $_GET["q"];
} catch(Exception $e) {
echo $e;
}
if (isset($noOfResults)) {
echo "";
} else {
echo"Variable setting failed";
}
$dbcnx = mysql_connect('localhost', 'root', '');
if (!$dbcnx) {
echo 'Unable to connect at this time...';
exit();
}
echo "";
#Select Database
mysql_select_db('udp', $dbcnx);
if (!@mysql_select_db('udp')) {
exit('Unable to locate the udp ' . 'database at this time.');
}
echo "";
#Set query
$result = mysql_query("SELECT * FROM data ORDER BY id DESC LIMIT $noOfResults");
if (!$result) {
exit('Error performing query: ' . mysql_error());
}
$_SESSION['currentHighest'] = mysql_query("SELECT MAX(id) FROM data");
#Display results
while ($row = mysql_fetch_array($result)) {
echo '<p class="display-date">' . $row['date'] . '</p><p class="display">' . $row['id'] . ' - ' . base64_decode( $row['packetdata']) . '</p>';
echo "<hr align='center' width='90%' />";
}
echo "</div></center>";
}
?>
</html>
body {
background-color: #1E1E1E;
}
.title {
color: #FFF;
text-align: center;
letter-spacing: 0.2em;
font-size: 40px;
}
.data-window {
background-color: #000;
width: 80%;
border-radius: 8px;
height: 700px;
overflow: scroll;
color: #CCFF33;
}
.display {
text-align: left;;
color: #CCFF33;
margin-left: 5%;
}
.display-date {
text-align: right;
color: #FFF;
margin-right: 5%;
}
.nav {
display: inline;
color: #FFF;
}
.selectDevice {
text-align: center;
color: #FFF;
}
.selectDeviceButton {
width: 70px;
height: 40px;
background-color: #1E1E1E;
color: #FFF;
border-radius: 3px;
border: solid 2px #000;
}
.Search {
text-align: center;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment