My controller (I want to select records based on some conditions) :
public function promotion()
{
if(!$this->user_permission->check_permission())return;
$data['startDate'] = $this->input->post('input_date_from');
$data['endDate'] = $this->input->post('input_date_to');
$email = $this->input->post('email');
var_dump($email);
var_dump($data['startDate']);
var_dump($data['endDate']);
$this->db->select('a.booking_id as booking_id, a.from_email as from_email, a.booking_date as booking_date, a.status as status, b.vendor_airway_bill as awb, b.tariff as tariff');
$this->db->where('from_email', $email);
$this->db->where('booking_date >=', date('Y-m-d',strtotime($data['startDate'])));
$this->db->where('booking_date <=', date('Y-m-d',strtotime($data['endDate'])));
$this->db->where('status = 1');
$this->db->or_where('status = 2');
$this->db->from('booking as a');
$this->db->join('shipment as b','a.booking_id = b.booking_id','left');
$query = $this->db->get();
$data['result'] = $query->result_array();
$this->template->render('admin/promotion',$data,'admin');
}
My view (I want to show booking shipment based on from_email from the user input. I set the table to display:none, and when the user input something in from_email input then click view, it shows the datatable) :
<form action="" method="post" id="cashback">
User Email :
<input type="text" name="email" id="email">
Booking Date :
<div id="daterange" style="background: #fff; cursor: pointer; padding: 5px 10px; border: 1px solid #ccc; display:inline">
<span></span> <b class="caret"></b>
</div>
<input type="hidden" name="input_date_from" id="input_date_from" value="">
<input type="hidden" name="input_date_to" id="input_date_to" value="">
<button type="button" class="btn btn-primary" onclick="promotion();">View
</button>
</form>
<table class="table table-bordered table-striped table-condensed" id="promotion" style="display:none">
<thead>
<tr>
<th>BookingDate</th>
<th>UserEmail</th>
<th>AirwayBill</th>
<th>Tariff</th>
<th>Status</th>
</tr>
</thead>
<tbody>
<?php foreach ($result as $r) : ?>
<tr>
<td>
<?php echo $r['booking_date'];?>
</td>
<td>
<?php echo $r['from_email'];?>
</td>
<td>
<?php echo $r['awb'];?>
</td>
<td>
<?php echo $r['tariff'];?>
</td>
<td>
<?php echo $r['status'];?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</template>
<template block="custom_js">
<script type="text/javascript" src="https://cdn.datatables.net/r/bs/dt-1.10.9/datatables.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/momentjs/2.15.1/moment.min.js"></script>
<script type="text/javascript" src="https://cdn.jsdelivr.net/bootstrap.daterangepicker/2.1.24/daterangepicker.js"></script>
<script src="<?php echo base_url('asset/js/typeahead.bundle.min.js') ?>"></script>
<script type="text/javascript">base_url='<?php echo base_url()?>'</script>
<script>
<?php if(isset($startDate) && isset($endDate)): ?>
var startDate = '<?php echo $startDate ?>';
var endDate = '<?php echo $endDate ?>';
<?php endif; ?>
$(function() {
$('#promotion').DataTable();
var start = typeof(startDate) === 'string' ? moment(startDate) : moment().startOf('month');
var end = typeof(endDate) === 'string' ? moment(endDate) : moment();
$('#input_date_from').val(start.format('YYYY-MM-DD'));
$('#input_date_to').val(end.format('YYYY-MM-DD'));
function cb(start, end) {
$('#daterange span').html(start.format('MMMM D, YYYY') + ' - ' + end.format('MMMM D, YYYY'));
}
$('#daterange').daterangepicker({
startDate: start,
endDate: end,
ranges: {
'Today': [moment(), moment()],
'Yesterday': [moment().subtract(1, 'days'), moment().subtract(1, 'days')],
'Last 7 Days': [moment().subtract(6, 'days'), moment()],
'Last 30 Days': [moment().subtract(29, 'days'), moment()],
'This Month': [moment().startOf('month'), moment().endOf('month')],
'Last Month': [moment().subtract(1, 'month').startOf('month'), moment().subtract(1, 'month').endOf('month')]
}
}, cb);
cb(start, end);
$('#daterange').on('apply.daterangepicker', function(ev, picker) {
$('#input_date_from').val(picker.startDate.format('YYYY-MM-DD'));
$('#input_date_to').val(picker.endDate.format('YYYY-MM-DD'));
});
});
function promotion() {
input_date_to = $('#input_date_to').val();
input_date_from = $('#input_date_from').val();
email = $('#email').val();
$.ajax
({
url: "<?php echo site_url('admin/promotion')?>",
type: "POST",
dataType: "text",
data: {email: email, input_date_from: input_date_from, input_date_to: input_date_to},
success: function(data)
{
$('#promotion').show();
console.log(email);
console.log(input_date_from);
console.log(input_date_to);
}
})
}
</script>
I try to filter data based on from_email, date_range_from and date_range_to. When I var_dump the input post, it showing the value as I expected, but it didn't run the this->db->where('from_email',$email), so I get all result..
Try to replace
$this->db->where('status = 1');
$this->db->or_where('status = 2');
into something like:
$this->db->where('(status = 1 OR status = 2)');
note parenthesis is important to make OR operator get higher presedence than AND operator. Also turn on your query log and check what actual SQL is sent to database server to better understand why.
[SOLVED]. Use where_in() instead of or_where
Related
Hello, so I prettty much copied this code and it doesn't work for me, but does for other people (the entire html and php)
When I try the query in SQL Management it works, so I don't think it's the database
When I try to read from the database it's just blank, no errors in the console
Here is my select.php:
<?php
//select.php
$connect = mysqli_connect("den1.mssql5.gear.host", "testiranje", "nijebitno#", "testiranje");
$output = array();
$query = "SELECT * FROM dbo.tbl_user";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
echo json_encode($output);
}
?>
And here is my index.html:
<!DOCTYPE html>
<!-- index.php !-->
<html>
<head>
<title>Webslesson Tutorial | AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
</head>
<body>
<br /><br />
<div class="container" style="width:500px;">
<h3 align="center">AngularJS Tutorial with PHP - Fetch / Select Data from Mysql Database</h3>
<div ng-app="myapp" ng-controller="usercontroller" ng-init="displayData()">
<label>First Name</label>
<input type="text" name="first_name" ng-model="firstname" class="form-control" />
<br />
<label>Last Name</label>
<input type="text" name="last_name" ng-model="lastname" class="form-control" />
<br />
<input type="submit" name="btnInsert" class="btn btn-info" ng-click="insertData()" value="ADD"/>
<br /><br />
<table class="table table-bordered">
<tr>
<th>First Name</th>
<th>Last Name</th>
</tr>
<tr ng-repeat="x in names">
<td>{{x.first_name}}</td>
<td>{{x.last_name}}</td>
</tr>
</table>
</div>
</div>
</body>
</html>
<script>
var app = angular.module("myapp",[]);
app.controller("usercontroller", function($scope, $http){
$scope.insertData = function(){
$http.post(
"insert.php",
{'firstname':$scope.firstname, 'lastname':$scope.lastname}
).success(function(data){
alert(data);
$scope.firstname = null;
$scope.lastname = null;
$scope.displayData();
});
}
$scope.displayData = function(){
$scope.names = new Array;
$http.get("select.php")
.success(function(data){
console.log("sranje");
$scope.names = data;
console.log(data);
});
}
});
</script>
You can try adding
header('Content-type: application/json');
before your echo in php function. In this way you "tell" that your php function return json data.
<?php
//select.php
$connect = mysqli_connect("den1.mssql5.gear.host", "testiranje", "nijebitno#", "testiranje");
$output = array();
$query = "SELECT * FROM dbo.tbl_user";
$result = mysqli_query($connect, $query);
if(mysqli_num_rows($result) > 0)
{
while($row = mysqli_fetch_array($result))
{
$output[] = $row;
}
header('Content-type: application/json');
echo json_encode($output);
}
?>
I have this kind of JSON data. This data is fetched from MongoDB. I want to print that on EJS page.
[ { _id: 59157619e9bcd218d9dd4dba,
que: 'Overall how satisfied are you with the product?',
type: 'radio',
options: [ 'Not at all satisfied', 'satisfied', 'Very much satisfied ' ] } ]
options would be radio button.
suppose you have get api like this.
app.get('/testing', function (req, res) {
var array = [{
_id: '59157619e9bcd218d9dd4dba',
que: 'Overall how satisfied are you with the product?',
type: 'radio',
options: ['Not at all satisfied', 'satisfied', 'Very much satisfied ']
}]
res.render('load', array);
//load is the ejs file (load.ejs) and array is the array of object.
});
Suppose this is your ejs file and you want to send this array in ejs file.like...
<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<style>
table, td, th {
padding: 8px;
border: 1px solid #ddd;
text-align: left;
}
</style>
</head>
<body>
<h2><%= HeadLine %></h2>
<table>
<tr style='background-color: gainsboro;'>
<th>Id</th>
<th>question</th>
<th>type</th>
<th>options</th>
</tr>
<% array.forEach(function(data) { %>
<tr>
<td >
<p><%= data.seq %></p>
</td >
<td>
<p><%= data.id %></p>
</td>
<td >
<p> <%= data.question %></p>
</td >
<td >
<p><%= data.type %></p>
</td >
<td >
<p> <%= data.options %></p>
</td >
</tr>
<% }); %>
</table>
</body>
</html>
You need to pass the json data to the ejs file from the router file, this might help-
router.js
router.get('/radio', function(req, res) {
var data = [ { _id: 59157619e9bcd218d9dd4dba, que: 'Overall how satisfied are you with the product?', type: 'radio', options: [ 'Not at all satisfied', 'satisfied', 'Very much satisfied ' ] } ]; //replace this with the service getting data
res.render('radio/show', data);
})
ejs file - radio.js
<form>
<input type="radio" checked><%= data.options[0] %><br>
<input type="radio"><%= data.options[1] %><br>
<input type="radio"><%= data.options[2] %><br>
</form>
I build dynamic input by add row table, and user input by autocomplete, then I store PRODUCT_ID in <input name="idp" value="">
E.g User input twice times (HP & Computer)
Name Product | PRODUCT_ID
HP = 2945
COMPUTER = 8654
Should be in array is = (2945,8654)
This is for Controller:
class ControllerItemItem extends Controller { //Controller/Item/Item.php
private $error = array();
public function index() {
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('item/item');
$this->getList();
}
protected function getList(){
if (isset($this->request->get['head_text_field'])){
$head_text_field = $this->request->get['head_text_field'];
} else {
$head_text_field = null;
}
if (isset($this->request->get['title_text_field'])){
$title_text_field = $this->request->get['title_text_field'];
} else {
$title_text_field = null;
}
if (isset($this->request->get['max'])){
$max = $this->request->get['max'];
} else {
$max = null;
}
if(isset($this->request->get['idp'])){
$product = $this->request->get['idp'];
$product2 = array();
foreach($product as $p)
{
$product2[] = $p;
}
}else {
$product = null;
}
// BREADCRUMBS //
$this->data['breadcrumbs'] = array();
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_home'),
'href' => $this->url->link('common/home', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => false
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('text_module'),
'href' => $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
$this->data['breadcrumbs'][] = array(
'text' => $this->language->get('heading_title'),
'href' => $this->url->link('module/item', 'token=' . $this->session->data['token'], 'SSL'),
'separator' => ' :: '
);
// END //
// Call Language //
$this->data['heading_title'] = $this->language->get('heading_title');
$this->data['entry_head'] = $this->language->get('entry_head');
$this->data['entry_title'] = $this->language->get('entry_title');
$this->data['entry_product'] = $this->language->get('entry_product');
$this->data['entry_max_item'] = $this->language->get('entry_max_item');
$this->data['button_save'] = $this->language->get('button_save');
$this->data['button_cancel'] = $this->language->get('button_cancel');
// END //
$this->data['cancel'] = $this->url->link('extension/module', 'token=' . $this->session->data['token'], 'SSL');
$this->data['action'] = $this->url->link('item/item/insert', 'token=' . $this->session->data['token'], 'SSL');
$this->data['token'] = $this->session->data['token'];
$data = array(
'head_text_field' => $head_text_field,
'title_text_field' => $title_text_field,
'max' => $max
);
$this->template = 'item/item.tpl';
$this->children = array(
'common/header',
'common/footer'
);
$this->response->setOutput($this->render());
}
public function insert()
{
$this->language->load('item/item');
$this->document->setTitle($this->language->get('heading_title'));
$this->load->model('item/item');
if (($this->request->server['REQUEST_METHOD'] == 'POST') && $this->validateForm()) {
//$this->model_item_item->insert_head($this->request->post);
$this->model_item_item->insert_detail($this->request->post);
//$this->session->data['success'] = $this->language->get('text_success');
//$this->redirect($this->url->link('item/item', 'token=' . $this->session->data['token'], 'SSL'));
}
}
protected function validateForm() {
if (!$this->user->hasPermission('modify', 'item/item')) {
$this->error['warning'] = $this->language->get('error_permission');
}
if ((utf8_strlen($this->request->post['head_text_field']) < 1) || (utf8_strlen($this->request->post['head_text_field']) > 64)) {
$this->error['head'] = $this->language->get('error_head');
}
if (!$this->request->post['title_text_field']) {
$this->error['title'] = $this->language->get('error_title');
}
if (!$this->error) {
return true;
} else {
return false;
}
}
This is for Model :
class ModelItemItem extends Model {
public function insert_head($data)
{
$this->db->query("INSERT INTO " . DB_PREFIX . "show_product SET head_text = '" . $this->db->escape($data['head_text_field']) . "', title_text = '" . $this->db->escape($data['title_text_field']) . "', max_item = '" . $this->db->escape($data['max']) . "'");
}
public function insert_detail($product2)
{
foreach($product2 as $detail)
{
//$this->db->query("INSERT INTO " . DB_PREFIX . "show_product_detail SET product_id = '". $this->db->escape($detail['product']) . "'");
}
echo $detail[0];
}
}
This is for view :
<?php echo $header; ?>
<div id="content">
<div class="breadcrumb">
<?php foreach ($breadcrumbs as $breadcrumb) { ?>
<?php echo $breadcrumb['separator']; ?><?php echo $breadcrumb['text']; ?>
<?php } ?>
</div>
<?php if ($error_warning) { ?>
<div class="warning"><?php echo $error_warning; ?></div>
<?php } ?>
<?php if ($success) { ?>
<div class="success"><?php echo $success; ?></div>
<?php } ?>
<div class="box">
<div class="heading">
<h1><img src="view/image/product.png" alt="" /> <?php echo $heading_title; ?></h1>
<div class="buttons"><a onclick="$('#form').submit();" class="button"><?php echo $button_save; ?></a><?php echo $button_cancel; ?></div>
</div>
<div class="content">
<form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="form">
<table class="form">
<tr>
<td><span class="required">*</span> <?php echo $entry_head; ?></td>
<td><input type="text" name="head_text_field" value="" placeholder="Input Head Text" size="40"/>
<?php if ($error_head) { ?>
<span class="error"><?php echo $error_head; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><span class="required">*</span> <?php echo $entry_title; ?></td>
<td><textarea name="title_text_field" placeholder="Input Title Text" style="width:230px;"/></textarea>
<?php if ($error_title) { ?>
<span class="error"><?php echo $error_title; ?></span>
<?php } ?>
</td>
</tr>
<tr>
<td><?php echo $entry_max_item; ?></td>
<td>
<select name="max" id="maxitem">
<?php
for($i=1; $i<=6; $i++)
{
if($i == 1)
echo "<option selected='selected' value=".$i.">".$i."</option>";
else
echo "<option value=".$i.">".$i."</option>";
}
?>
</select>
</td>
</tr>
<tr>
<td><?php echo $entry_product; ?></td>
<td><input type="text" id="product" name="product" value="" placeholder="Input Product" size="40"/></td>
<td><input type="hidden" id="idp" name="idp" value="" /></td>
</tr>
<tr>
<td></td>
<td>
<table>
<tr>
<td><input type="button" id="ADD" value="Add Item"></td>
<td><input type="reset" id="RESET" value="Reset"></td>
</tr>
</table>
</td>
</tr>
<tr>
</tr>
</table>
<table border="1" id="tblname" cellpadding="5" cellspacing="5">
<thead>
<tr>
<td>
Total Item
</td>
<td>
Id Item
</td>
<td>
Name Item
</td>
<td>
DELETE
</td>
<tr>
</thead>
<tbody align="center">
</tbody>
</table>
</form>
</div>
</div>
</div>
<script type="text/javascript"><!--
$('input[name=\'product\']').autocomplete({
delay: 100,
source: function(request, response) {
$.ajax({
url: 'index.php?route=catalog/product/autocomplete&token=<?php echo $token; ?>&filter_name=' + encodeURIComponent(request.term),
dataType: 'json',
success: function(json) {
response($.map(json, function(item) {
return {
label: item.name,
value: item.product_id
}
}));
}
});
},
select: function(event, ui) {
$('input[name=\'product\']').val(ui.item.label);
$('input[name=\'idp\']').val(ui.item.value);
return false;
},
focus: function(event, ui) {
return false;
}
});
//--></script>
<Script type="text/javascript">
$(document).ready(function(){
var item = 1;
var isAllowed = 3;
var isSet = 0;
$('#ADD').click(function(){
var maxitem = parseInt($("#maxitem").val(), 10); //from max item in html
var iCount = 0;
if($('#product').val()){ // check input product
if( item <= maxitem )
{
iCount = $('#tblname tbody tr').length + 1;
szTr = "<tr><td>";
szTr = szTr + iCount + "</td>";
szTr = szTr + "<td>" +$('#idp').val() +"</td>";
szTr = szTr + "<td>" +$('#product').val() +"</td>";
szTr = szTr + "<td><input type='button' class='DEL' value='DELETE'></td>";
szTr = szTr + "</tr>";
$('#tblname tbody').append(szTr);
item +=1;
isSet = 1;
restFormOpts();
}
else
{
alert ("Max Limit !!!");
}
}else{alert('Enter Product !!! ');}
});
// for delete row
$('body').on('click','#RESET', function() {
item = 1;
isAllowed = 3;
isSet = 0;
$("#maxitem").attr("disabled",false);
$('.DEL').parents('tr').remove();
});
$('body').on('click', 'input.DEL', function() {
$(this).parents('tr').remove();
item -= 1;
});
function restFormOpts()
{
if(isSet === isAllowed) {
$("#ADD").attr("disabled",true);
$("#maxitem").attr("disabled",false);
}
else {
$("#ADD").attr("disabled",false);
$("#maxitem").attr("disabled",true);
}
}
});
</script>
<?php echo $footer; ?>
When I try insert query to my database, value only 1 number.
Then I try Echo for make sure variable is correct but it's wrong, the result is the last user input (Computer, in array(8,6,5,4))? it's should be (2945,8654) not (8,6,5,4)?
Can some one help me for fix this?? I already try fix this problem for 1 week still no hope :(
If you want to insert array variables in database, First you need encode them and then insert them .
Ex. $abc = array(3,45,6,78,89) ;
Query : "INSERT INTO " . DB_PREFIX . "show_product_detail SET product_id = '". $this->db->escape(json_encode($abc)) . "'
Firstly install Nagios on your machine with with Mysql server(LAMP on Linux).
Then download the Nagios plugin from this link.
Nagios Plugin URL
Add the downloaded files in the directory of nagios where you install.
and the code is in the Temperature.php file.just change the database name and table name according to your database info.
the code given below.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Temprature</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
table-layout: fixed;
margin-left:8%;
}
th, td {
padding: 15px;
text-align:center;
}
</style>
<script type="text/javascript">
setTimeout(function(){
document.getElementById('refresh').innerHTML="Refreshing....";
},35000)
setTimeout(function(){
location = ''
},40000)
</script>
<?PHP
$maxdattemp="Todays";
$link = mysqli_connect('localhost', 'nagios', 'nagios12345', 'Temperature');
if (!$link) {
die('Not connected : ' . mysql_error());
}
if (!$link) {
die ('Can\'t use foo : ' . mysql_error());
}
else {
if(!isset($_REQUEST['date']))
{
$sql = "SELECT * FROM Temp ORDER BY date DESC , time DESC";
}else
{
$dat=$_REQUEST['date'];
$sql="SELECT * FROM Temp where date='".$dat."' ORDER BY date DESC , time DESC";
}
$arr=array();
$tim=array();
$time=array();
if ($result = mysqli_query($link , $sql)) {
for ($row_no = 0; $row_no <= $result->num_rows - 1; $row_no++) {
$result->data_seek($row_no);
$row = $result->fetch_assoc();
//echo " centigrade = " . $row['centigrade'] . "\n";
$arr[] = floatval($row['centigrade']);
$d=strtotime($row['time']);
$hour = date("H", $d);
$min = date("i", $d);
$sec = date("s", $d);
// $tim[]=
$tim[]= "'".$row['date']." , ".$hour.":".$min.":".$sec."'";
//echo "Created date is " . date("h:i:sa", $d);
//array_push($tim, $row['time']);
//echo $tim[$row_no];
}
}
}
?>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Graph'
},
subtitle: {
text: 'Temperature'
},
xAxis: {
categories: [<?php echo $temp= implode(",", $tim); ?>],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Centigrade',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' °C'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 20,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Temperature',
data: [<?php echo $tempa= implode(",", $arr); ?>]]
}]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; max-width: 700px; height: 400px;"></div>
<h3 id="refresh" style="color:#090;margin-left:28%;position:absolute"></h3>
<?php
mysql_connect('localhost','nagios','nagios12345');
mysql_select_db('Temperature') or die( "Unable to select database");
?>
<table style="width:100% !important; border:none !important;">
<col width="40%" />
<col width="50%" />
<tr>
<td style="border:none !important;position:fixed;top:10px;right:5px">
<h3 style="color:#600 ">Latest Temperature Reading:</h3> <?php
$query="SELECT * FROM Temp ORDER BY date DESC , time DESC";
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows>0)
{
$f1=mysql_result($result,0,"centigrade");
$f2=mysql_result($result,0,"farenheit");
$f3=mysql_result($result,0,"date");
$f4=mysql_result($result,0,"time");
}
//echo $f1.' C'.' , '.$f2.' F'.' , '.' Time: '.$f4.' Date: '.$f3;
if(isset($_REQUEST['date']))
{
$dat=$_REQUEST['date'];
$result1 = mysql_query("SELECT MAX(centigrade) AS cent, MAX(farenheit) AS farh FROM Temp WHERE DATE(date) = '".$dat."'");
$num_rows = mysql_num_rows($result1);
if($num_rows>0)
{
$max=mysql_result($result1,0,"cent");
$farh=mysql_result($result1,0,"farh");
}
$maxtimeresult = mysql_query("SELECT time as tim from Temp WHERE centigrade = '".$max."' AND DATE(date) = '".$dat."' ORDER BY time DESC");
$num_rows = mysql_num_rows($maxtimeresult);
if($num_rows>0)
{
$time=mysql_result($maxtimeresult,0,"tim");
}
$maxdattemp= $dat;
}
else
{
$result1 = mysql_query("SELECT MAX(centigrade) AS cent, MAX(farenheit) AS farh FROM Temp WHERE DATE(date) = CURDATE()");
$num_rows = mysql_num_rows($result1);
if($num_rows>0)
{
$max=mysql_result($result1,0,"cent");
$farh=mysql_result($result1,0,"farh");
}
$maxtimeresult = mysql_query("SELECT time as tim from Temp WHERE centigrade = '".$max."' AND DATE(date) = CURDATE() ORDER BY time DESC");
$num_rows = mysql_num_rows($maxtimeresult);
if($num_rows>0)
{
$time=mysql_result($maxtimeresult,0,"tim");
}
} ?>
<h4 style="color:#090">Date: <?php echo $f3 ?></h4>
<h4 style="color:#090">Time: <?php echo $f4 ?></h4>
<h3 style="color:#00F"><?php echo $f1 ?> °C</h3>
<h3 style="color:#00F"><?php echo $f2 ?> °F</h3>
<?PHP
if(mysql_result($result1,0,"cent")){
?>
<h3 style="color:#F00"><?php echo $maxdattemp; ?> Maximum Temperature:</h3>
<h4 style="color:#090">Time: <?PHP echo $time ?></h4>
<h3 style="color:#F00"><?php echo round($max, 2);?> °C </h3>
<h3 style="color:#F00"><?php echo round($farh, 2);?> °F </h3>
<?PHP }else
{?>
<h3 style="color:#F00">Todays Maximum Temprature:</h3>
<h4 style="color:#090">No Entry for Today</h4>
<?PHP }?>
<form action="Temperature.php" method="post" >
<input type="hidden" id="All" name="All">
<input type="submit" value="Show All">
</form><br/>
<form action="Temperature.php" method="post" style="width:30%;right:1%;position:fixed;">
<span style="color:#090">Select Date:</span>
<input type="date" id="date" name="date">
<input type="submit">
</form>
</td>
</tr>
</table>
<br /> <br /> <br />
<table style="width:50%">
<col width="40%" />
<col width="40%" />
<col width="40%" />
<col width="40%" />
<tr>
<th>Centigrade</th>
<th>Farenheit</th>
<th>Date </th>
<th>Time </th>
</tr>
</table>
<?php
if(isset($_REQUEST['date']))
{
$dat=$_REQUEST['date'];
$query="SELECT * FROM Temp where date='".$dat."' ORDER BY date DESC , time DESC";
$result=mysql_query($query);
}else{
$query="SELECT * FROM Temp ORDER BY date DESC , time DESC";
$result=mysql_query($query);
}
$num=mysql_numrows($result);
mysql_close();
if(mysql_numrows($result)>0){
$i=0;while ($i < $num) {
$f1=mysql_result($result,$i,"centigrade");
$f2=mysql_result($result,$i,"farenheit");
$f3=mysql_result($result,$i,"date");
$f4=mysql_result($result,$i,"time");
?>
<table style="width:50%">
<col width="40%" />
<col width="40%" />
<col width="40%" />
<col width="40%" />
<tr>
<td headers="Centigrade">
<font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font>
</td>
<td headers="farenheit">
<font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font>
</td>
<td headers="date">
<font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font>
</td>
<td headers="time">
<font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font>
</td>
</tr>
</table>
<?php $i++;
}
}else
{?>
<h4 style="margin-left:27%"><font face="Arial, Helvetica, sans-serif"><?php echo 'No Record Found'; ?></font>
</h4>
<?PHP
}
?>
</body>
</html>
You will find a side bar on the in Nagios and the option Mysql Report under reports and there is the Graph and the temperature data with latest Temperature Reading and Today's Maximum Temperature.
Thanks!.
You may need to SSH if your trying to access another localhost.
http://www.sequelpro.com/docs/connecting_to_a_mysql_server_on_a_remote_host
You will have to enable remote MySQL access on your mysql server for your other PC and use your MySQL server IP instead of localhost in your scripts.
Firstly install Nagios on your machine with with Mysql server(LAMP on Linux).
Then download the Nagios plugin from this link.
Nagios Plugin URL
Add the downloaded files in the directory of nagios where you install.
and the code is in the Temperature.php file.just change the database name and table name according to your database info.
the code given below.
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Temprature</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<style type="text/css">
${demo.css}
table, th, td {
border: 1px solid black;
border-collapse: collapse;
table-layout: fixed;
margin-left:8%;
}
th, td {
padding: 15px;
text-align:center;
}
</style>
<script type="text/javascript">
setTimeout(function(){
document.getElementById('refresh').innerHTML="Refreshing....";
},35000)
setTimeout(function(){
location = ''
},40000)
</script>
<?PHP
$maxdattemp="Todays";
$link = mysqli_connect('localhost', 'nagios', 'nagios12345', 'Temperature');
if (!$link) {
die('Not connected : ' . mysql_error());
}
if (!$link) {
die ('Can\'t use foo : ' . mysql_error());
}
else {
if(!isset($_REQUEST['date']))
{
$sql = "SELECT * FROM Temp ORDER BY date DESC , time DESC";
}else
{
$dat=$_REQUEST['date'];
$sql="SELECT * FROM Temp where date='".$dat."' ORDER BY date DESC , time DESC";
}
$arr=array();
$tim=array();
$time=array();
if ($result = mysqli_query($link , $sql)) {
for ($row_no = 0; $row_no <= $result->num_rows - 1; $row_no++) {
$result->data_seek($row_no);
$row = $result->fetch_assoc();
//echo " centigrade = " . $row['centigrade'] . "\n";
$arr[] = floatval($row['centigrade']);
$d=strtotime($row['time']);
$hour = date("H", $d);
$min = date("i", $d);
$sec = date("s", $d);
// $tim[]=
$tim[]= "'".$row['date']." , ".$hour.":".$min.":".$sec."'";
//echo "Created date is " . date("h:i:sa", $d);
//array_push($tim, $row['time']);
//echo $tim[$row_no];
}
}
}
?>
<script type="text/javascript">
$(function () {
$('#container').highcharts({
chart: {
type: 'line'
},
title: {
text: 'Graph'
},
subtitle: {
text: 'Temperature'
},
xAxis: {
categories: [<?php echo $temp= implode(",", $tim); ?>],
title: {
text: null
}
},
yAxis: {
min: 0,
title: {
text: 'Centigrade',
align: 'high'
},
labels: {
overflow: 'justify'
}
},
tooltip: {
valueSuffix: ' °C'
},
plotOptions: {
bar: {
dataLabels: {
enabled: true
}
}
},
legend: {
layout: 'vertical',
align: 'right',
verticalAlign: 'top',
x: -40,
y: 20,
floating: true,
borderWidth: 1,
backgroundColor: ((Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'),
shadow: true
},
credits: {
enabled: false
},
series: [{
name: 'Temperature',
data: [<?php echo $tempa= implode(",", $arr); ?>]]
}]
});
});
</script>
</head>
<body>
<script src="../../js/highcharts.js"></script>
<script src="../../js/modules/exporting.js"></script>
<div id="container" style="min-width: 310px; max-width: 700px; height: 400px;"></div>
<h3 id="refresh" style="color:#090;margin-left:28%;position:absolute"></h3>
<?php
mysql_connect('localhost','nagios','nagios12345');
mysql_select_db('Temperature') or die( "Unable to select database");
?>
<table style="width:100% !important; border:none !important;">
<col width="40%" />
<col width="50%" />
<tr>
<td style="border:none !important;position:fixed;top:10px;right:5px">
<h3 style="color:#600 ">Latest Temperature Reading:</h3> <?php
$query="SELECT * FROM Temp ORDER BY date DESC , time DESC";
$result=mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows>0)
{
$f1=mysql_result($result,0,"centigrade");
$f2=mysql_result($result,0,"farenheit");
$f3=mysql_result($result,0,"date");
$f4=mysql_result($result,0,"time");
}
//echo $f1.' C'.' , '.$f2.' F'.' , '.' Time: '.$f4.' Date: '.$f3;
if(isset($_REQUEST['date']))
{
$dat=$_REQUEST['date'];
$result1 = mysql_query("SELECT MAX(centigrade) AS cent, MAX(farenheit) AS farh FROM Temp WHERE DATE(date) = '".$dat."'");
$num_rows = mysql_num_rows($result1);
if($num_rows>0)
{
$max=mysql_result($result1,0,"cent");
$farh=mysql_result($result1,0,"farh");
}
$maxtimeresult = mysql_query("SELECT time as tim from Temp WHERE centigrade = '".$max."' AND DATE(date) = '".$dat."' ORDER BY time DESC");
$num_rows = mysql_num_rows($maxtimeresult);
if($num_rows>0)
{
$time=mysql_result($maxtimeresult,0,"tim");
}
$maxdattemp= $dat;
}
else
{
$result1 = mysql_query("SELECT MAX(centigrade) AS cent, MAX(farenheit) AS farh FROM Temp WHERE DATE(date) = CURDATE()");
$num_rows = mysql_num_rows($result1);
if($num_rows>0)
{
$max=mysql_result($result1,0,"cent");
$farh=mysql_result($result1,0,"farh");
}
$maxtimeresult = mysql_query("SELECT time as tim from Temp WHERE centigrade = '".$max."' AND DATE(date) = CURDATE() ORDER BY time DESC");
$num_rows = mysql_num_rows($maxtimeresult);
if($num_rows>0)
{
$time=mysql_result($maxtimeresult,0,"tim");
}
} ?>
<h4 style="color:#090">Date: <?php echo $f3 ?></h4>
<h4 style="color:#090">Time: <?php echo $f4 ?></h4>
<h3 style="color:#00F"><?php echo $f1 ?> °C</h3>
<h3 style="color:#00F"><?php echo $f2 ?> °F</h3>
<?PHP
if(mysql_result($result1,0,"cent")){
?>
<h3 style="color:#F00"><?php echo $maxdattemp; ?> Maximum Temperature:</h3>
<h4 style="color:#090">Time: <?PHP echo $time ?></h4>
<h3 style="color:#F00"><?php echo round($max, 2);?> °C </h3>
<h3 style="color:#F00"><?php echo round($farh, 2);?> °F </h3>
<?PHP }else
{?>
<h3 style="color:#F00">Todays Maximum Temprature:</h3>
<h4 style="color:#090">No Entry for Today</h4>
<?PHP }?>
<form action="Temperature.php" method="post" >
<input type="hidden" id="All" name="All">
<input type="submit" value="Show All">
</form><br/>
<form action="Temperature.php" method="post" style="width:30%;right:1%;position:fixed;">
<span style="color:#090">Select Date:</span>
<input type="date" id="date" name="date">
<input type="submit">
</form>
</td>
</tr>
</table>
<br /> <br /> <br />
<table style="width:50%">
<col width="40%" />
<col width="40%" />
<col width="40%" />
<col width="40%" />
<tr>
<th>Centigrade</th>
<th>Farenheit</th>
<th>Date </th>
<th>Time </th>
</tr>
</table>
<?php
if(isset($_REQUEST['date']))
{
$dat=$_REQUEST['date'];
$query="SELECT * FROM Temp where date='".$dat."' ORDER BY date DESC , time DESC";
$result=mysql_query($query);
}else{
$query="SELECT * FROM Temp ORDER BY date DESC , time DESC";
$result=mysql_query($query);
}
$num=mysql_numrows($result);
mysql_close();
if(mysql_numrows($result)>0){
$i=0;while ($i < $num) {
$f1=mysql_result($result,$i,"centigrade");
$f2=mysql_result($result,$i,"farenheit");
$f3=mysql_result($result,$i,"date");
$f4=mysql_result($result,$i,"time");
?>
<table style="width:50%">
<col width="40%" />
<col width="40%" />
<col width="40%" />
<col width="40%" />
<tr>
<td headers="Centigrade">
<font face="Arial, Helvetica, sans-serif"><?php echo $f1; ?></font>
</td>
<td headers="farenheit">
<font face="Arial, Helvetica, sans-serif"><?php echo $f2; ?></font>
</td>
<td headers="date">
<font face="Arial, Helvetica, sans-serif"><?php echo $f3; ?></font>
</td>
<td headers="time">
<font face="Arial, Helvetica, sans-serif"><?php echo $f4; ?></font>
</td>
</tr>
</table>
<?php $i++;
}
}else
{?>
<h4 style="margin-left:27%"><font face="Arial, Helvetica, sans-serif"><?php echo 'No Record Found'; ?></font>
</h4>
<?PHP
}
?>
</body>
</html>
You will find a side bar on the in Nagios and the option Mysql Report under reports and there is the Graph and the temperature data with latest Temperature Reading and Today's Maximum Temperature.
Thanks!.
I think you need to tell the entity framework that your class has changed:
h.quantity = t.quantity;
context.DB.Entry(h).State = EntityState.Modified;
context.DB.SaveChanges();