Reputation: 133
In the following code i want value of $dischargeDate
variable as it is after refreshing page.
My problem is in this code sorting code is included and for every column click for sorting by user page is refreshed and value of $dischargeDat
getting null and it affects output.
<?php
include_once("session_check.php");
?>
<html>
<head>
<title>Date Wise Report</title>
<link rel="stylesheet" type="text/css" href="css/first.css" />
<link rel="stylesheet" type="text/css" href="css/NewCss.css" />
<link href="font-awesome-4.2.0/font-awesome-4.2.0/css/font-awesome.css" rel="stylesheet">
<link rel="stylesheet" href="css/jquery-ui.min.css" />
<link rel="stylesheet" href="css/jquery-ui.theme.min.css" />
<script type="text/javascript" src="js/jquery.min.js"></script>
<script type="text/javascript" src="js/jquery-ui.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#searchTerm_id').keyup(function() {
if ($(this).val().length > 3)
searchTable($(this).val());
else if ($(this).val().length < 3)
searchTable("");
});
});
function searchTable(inputVal) {
$.ajax({
type: "GET",
url: "report_admitdatewise.php",
data: ({
search_keyword: inputVal
}),
success: function(success) {
window.location.href = "report_admitdatewise.php?search_keyword=" + inputVal;
}
});
}
/////datepicker code
$(document).ready(function() {
$('#reportdate_id').datepicker({
dateFormat: 'dd/mm/yy',
changeMonth: true,
changeYear: true,
yearRange: '1900:2060',
///maxDate: new Date()
});
$("#datawtable").hide();
$("#show").click(function() {
$("#datawtable").show();
});
});
/*function formsubmit()
{
if(true)
{
document.getElementById('form_id').submit();
}
}*/
</script>
</head>
<body >
<div class="row-fluid">
<div class="area-top clearfix">
<div class="header">
<h3 class="title"><i class="fa fa-info-circle"></i> Date Wise Report</h3>
</div>
</div>
</div>
<div class="box">
<div class="container">
<form id="form_id" action="report_admitdatewise.php" method="GET" >
<input type="text" id="reportdate_id" name="admitDate" placeholder="Select date" >
<input type="submit" id="show"value="Display Records" />
<label id="search_lbl_id">Search:</label>
<input id="searchTerm_id" Type="text" class="search_box" placeholder="Search"
value = <?php echo $_GET['search_keyword'] ?>>
</form>
<!------------datewise search code---------->
<?php
include("db.php");
$sortingCode = "";
if (isset($_REQUEST['sort_element']) && $_REQUEST['sort_element'] != "") {
$sort_element = " ORDER BY ".$_REQUEST['sort_element']." ";
}
if (isset($_REQUEST['sort_type']) && $_REQUEST['sort_type'] != "") {
$sort_type = " ".$_REQUEST['sort_type']." ";
}
$sortingCode = "$sort_element $sort_type";
?>
<table class="draw_table" id="datawtable" border="1" width="100%" cellspacing="0" cellpadding="0">
<th>
<a href="report_admitdatewise.php?sort_element=admit_pat_id&sort_type=<?php echo
($_REQUEST["sort_element"] == "admit_pat_id" && $_REQUEST["sort_type"] == "asc") ? "desc" : "asc"; ?>">Patient ID
<?php if ($_REQUEST["sort_element"] == "admit_pat_id" ) { if($_REQUEST["sort_type"] == "desc" ) { ?>
<img class="sorting" src="images2/downarrow.png" alt="asc">
<?php } else { ?>
<img class="sorting" src="images2/uparrow.png" alt="desc">
<?php } } ?>
</a>
</th>
<th>
<a href="report_admitdatewise.php?sort_element=admit_pat_name&sort_type=<?php echo
($_REQUEST["sort_element"] == "admit_pat_name" && $_REQUEST["sort_type"] == "asc") ? "desc" : "asc"; ?>">Patient Name
<?php if ($_REQUEST["sort_element"] == "admit_pat_name" ) { if($_REQUEST["sort_type"] == "desc" ) { ?>
<img class="sorting" src="images2/downarrow.png" alt="asc">
<?php } else { ?>
<img class="sorting" src="images2/uparrow.png" alt="desc">
<?php } } ?>
</a>
</th>
<th >
<a href="report_admitdatewise.php?sort_element=admit_pat_doctor&sort_type=<?php echo
($_REQUEST["sort_element"] == "admit_pat_doctor" && $_REQUEST["sort_type"] == "asc") ? "desc" : "asc"; ?>">Doctor Name
<?php if ($_REQUEST["sort_element"] == "admit_pat_doctor" ) { if($_REQUEST["sort_type"] == "desc" ) { ?>
<img class="sorting" src="images2/downarrow.png" alt="asc">
<?php } else { ?>
<img class="sorting" src="images2/uparrow.png" alt="desc">
<?php } } ?>
</a>
</th>
<th>Department Name</th>
<?php
$where_clause ='';
$datewise=$_GET['admitDate'];
$date1 = str_replace('/', '-', $datewise);
//$dischargeDate= '';
$dischargeDate= date('Y-m-d', strtotime($date1));
if($_GET['admitDate']!='')
{
$where_clause = "where admit_pat_date='$dischargeDate'";
}
$searchKeyword = $_GET['search_keyword'];
if ($_GET['search_keyword'] != '')
{
$where_clause = " where admit_pat_id like '%" . $searchKeyword . "%' or admit_pat_name like '%" .$searchKeyword . "%' or admit_pat_doctor like '%" . $searchKeyword . "%' or admit_pat_dept like '%" .$searchKeyword . "%'";
}
if(isset($_GET['page']))
{
$page=$_GET['page'];
$page=mysql_real_escape_string($page);
} else {
$page=1;
}
$per_page = 10;
$page1=($page*10)-$per_page;
$result=mysql_query("SELECT admit_pat_id,admit_pat_name,admit_pat_doctor,admit_pat_dept, admit_pat_date FROM admit_patient_details $where_clause $sortingCode limit $page1,$per_page")or die(mysql_error());
/*if(mysql_num_rows($result)==0)
{
echo "<script>alert('No Record found for this date')</script>";
//return false;
}*/
while($row=mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['0'];?></td>
<td><?php echo $row['1'];?></td>
<td><?php echo $row['2'];?></td>
<td><?php echo $row['3'];?></td>
</tr>
<?PHP
}
?>
<tr>
<td colspan="4" >
<div class="link">
<?php
$result =mysql_query("select admit_pat_id,admit_pat_name,admit_pat_doctor,admit_pat_dept, admit_pat_date from admit_patient_details $where_clause $sortingCode ");
$count = mysql_num_rows($result);
$pages = ceil($count/$per_page);
if($page != 1)
{
echo "<a href='report_admitdatewise.php?page=1&search_keyword=$searchKeyword'><img src='images2/First.png'></a>";
$prev = $page - 1;
echo "<a href='report_admitdatewise.php?page=$prev&search_keyword=$searchKeyword'><img src='images2/Prev.png'></a>";
}
if($page != $pages)
{
$next = $page + 1;
echo "<a href='report_admitdatewise.php?page=$next&search_keyword=$searchKeyword'><img src='images2/Next.png'></a>";
echo "<a href='report_admitdatewise.php?page=$pages&search_keyword=$searchKeyword'><img src='images2/Last.png'></a>";
}
?>
</td>
</tr>
</table>
</div>
</body>
<?php mysql_close($con); ?>
Upvotes: 0
Views: 1310
Reputation: 1074385
If you want to store it on the client (as appears to be the case), you can use web storage for that. If you just need to persist the variable during a page refresh, use session storage. If you need to persist it even if the user closes the window and opens a new one, use local storage.
Saving to local storage:
localStorage.setItem("keyname", "string to store");
(localStorage
is a global pre-defined on browsers that support web storage.)
Getting from local storage:
var value = localStorage.getItem("keyname");
Note that web storage stores strings. To store complex data, or just to (mostly) retain the data type, you can use JSON:
// Setting
localStorage.setItem("keyname", JSON.stringify(valueToStore));
// Getting
var value = JSON.parse(localStorage.getItem("keyname") || "null");
...which on get will give you null
if the value wasn't there (or if you stored null
).
Upvotes: 1