Files
2026-02-17 12:44:37 -06:00

167 lines
5.2 KiB
PHP

<?php
mysql_connect("192.168.0.14", "corey", "41945549") or die("Error connecting to database: ".mysql_error());
mysql_select_db("controls") or die(mysql_error());
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Search results</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="style.css"/>
</head>
<body>
<table style="margin: 0px auto;" class="stat">
<tr>
<th><a href="index.php">RESET SEARCH</a></th>
<th><a href="../overview.php">BACK TO OVERVIEW</a></th>
</tr>
<tr>
<th colspan="2">Search Results</th>
</tr>
<!--
<tr>
<th><a href="edit" id="edit">Toggle Columns On/Off</a></th>
</tr>
-->
</table>
<table id="table" style="margin: 0px auto;" class="stat">
<thead>
<tr>
<th>Timestamp</th>
<th>PPH/Ton</th>
<th>Prev Tons</th>
<th>Prev Run</th>
<th>MCC Spd</th>
<th>K1 Spd</th>
<th>K2 Spd</th>
<th>K3 Spd</th>
<th>M1 Spd</th>
<th>M2 Spd</th>
<th>M3 Spd</th>
<th>M4 Spd</th>
<th>M5 Spd</th>
<th>M6 Spd</th>
<th>M1 Lvl</th>
<th>M2 Lvl</th>
<th>M3 Lvl</th>
<th>M4 Lvl</th>
<th>M5 Lvl</th>
<th>M6 Lvl</th>
</tr>
</thead>
<tbody>
<?php
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to &gt;
$query = mysql_real_escape_string($query);
// makes sure nobody uses SQL injection
$raw_results = mysql_query("SELECT * FROM milling
WHERE (`Z_TIMESTAMP` LIKE '%".$query."%')") or die(mysql_error());
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysql_num_rows($raw_results) > 0){ // if one or more resultss are returned do following
while($results = mysql_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
echo "<tr>";
echo "<td>".$results [ 'Z_TIMESTAMP' ]."</td>";
echo "<td>".$results [ 'LBSPERHR' ]."</td>";
echo "<td>".$results [ 'PREVTONS' ]."</td>";
echo "<td>".$results [ 'PREVTIME' ]."</td>";
echo "<td>".$results [ 'MAINSPD' ]."</td>";
echo "<td>".$results [ 'KNIFE1SPD' ]."</td>";
echo "<td>".$results [ 'KNIFE2SPD' ]."</td>";
echo "<td>".$results [ 'KNIFE3SPD' ]."</td>";
echo "<td>".$results [ 'MILL1SPD' ]."</td>";
echo "<td>".$results [ 'MILL2SPD' ]."</td>";
echo "<td>".$results [ 'MILL3SPD' ]."</td>";
echo "<td>".$results [ 'MILL4SPD' ]."</td>";
echo "<td>".$results [ 'MILL5SPD' ]."</td>";
echo "<td>".$results [ 'MILL6SPD' ]."</td>";
echo "<td>".$results [ 'MILL1LVL' ]."</td>";
echo "<td>".$results [ 'MILL2LVL' ]."</td>";
echo "<td>".$results [ 'MILL3LVL' ]."</td>";
echo "<td>".$results [ 'MILL4LVL' ]."</td>";
echo "<td>".$results [ 'MILL5LVL' ]."</td>";
echo "<td>".$results [ 'MILL6LVL' ]."</td>";
echo "</tr>";
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching resultss do following
echo "No results";
}
}
else{ // if query length is less than minimum
echo "Minimum length is ".$min_length;
}
?>
</body>
<script type="text/javascript">
$('#edit').click(function() {
var headers = $('#table th').map(function() {
var th = $(this);
return {
text: th.text(),
shown: th.css('display') != 'none'
};
});
var h = ['<div id=tableEditor><button id=done>Done</button><table><thead>'];
$.each(headers, function() {
h.push('<tr><th><input type=checkbox',
(this.shown ? ' checked ' : ' '),
'/> ',
this.text,
'</th></tr>');
});
h.push('</thead></table></div>');
$('body').append(h.join(''));
$('#done').click(function() {
var showHeaders = $('#tableEditor input').map(function() { return this.checked; });
$.each(showHeaders, function(i, show) {
var cssIndex = i + 1;
var tags = $('#table th:nth-child(' + cssIndex + '), #table td:nth-child(' + cssIndex + ')');
if (show)
tags.show();
else
tags.hide();
});
$('#tableEditor').remove();
return false;
});
return false;
});
</script>
</html>