Sum 1 to a value by clicking an image - PHP - javascript

I guys, I need yo help for this. I have this code, wich shows me the products I have in my shopping cart:
for($i=0;$i<count($_SESSION['productos']);$i++)
{
$id = $_SESSION['productos'][$i];
$prods = mysql_query('SELECT * from productos where idprod='.$id.'');
$row = mysql_fetch_array($prods);
echo "<tr>";
echo "<td>" . $row['nombre']; echo "</td>";
if($_GET[action]=="suma")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] + 1;
}
elseif($_GET[action]=="resta")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] - 1;
}
echo "<td><input name=".$i." type='text' value=" . $_SESSION['unidades'][$i]; echo " size='5'/></td>";
echo "<td><a href='carro_detalle.php?action=suma'><img src='images/flecharriba.png' width='10x' height='10px'/></a></td>";
echo "<td><a href='carro_detalle.php?action=resta'><img src='images/flechabajo.png' width='10px' height='10px'/></a></td>";
echo "<td>" . $row['precio']; echo "</td>";
echo "<td>" . $row['precio'] * $_SESSION['unidades'][$i]; echo "</td>";
echo "</tr>";
}
I need to sum 1 unity or rest 1 unity to $_SESSION['unidades'][$i] just to the selected product, when I click the two images respectively.
The thing is that when I click, it adds me 1 to all the products. Any easy way of doing this without using $_GET vars? I dont have high knowledge about JavasScript.
Thanks!!

You probably should remove your condition from the loop and put it outside of it:
if($_GET[action]=="suma")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] + 1;
}
elseif($_GET[action]=="resta")
{
$_SESSION['unidades'][$i] = $_SESSION['unidades'][$i] - 1;
}
for($i=0;$i<count($_SESSION['productos']);$i++)
{
$id = $_SESSION['productos'][$i];
$prods = mysql_query('SELECT * from productos where idprod='.$id.'');
$row = mysql_fetch_array($prods);
echo "<tr>";
echo "<td>" . $row['nombre']; echo "</td>";
echo "<td><input name=".$i." type='text' value=" . $_SESSION['unidades'][$i]; echo " size='5'/></td>";
echo "<td><a href='carro_detalle.php?action=suma'><img src='images/flecharriba.png' width='10x' height='10px'/></a></td>";
echo "<td><a href='carro_detalle.php?action=resta'><img src='images/flechabajo.png' width='10px' height='10px'/></a></td>";
echo "<td>" . $row['precio']; echo "</td>";
echo "<td>" . $row['precio'] * $_SESSION['unidades'][$i]; echo "</td>";
echo "</tr>";
}

Related

Need to change tr color in my php mysql table

I have a table where data is fetched from the MYSQLi table, I have a column as 'status' where it has two values of ACTIVE and DEACTIVE. I need deactive in different bg color/font color and active status in the different color, how could I achieve this through if else statement. At least td is changed also no problem.
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM retail";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table js-dynamitable table-bordered table-striped table-condensed'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>operator_name</th>";
echo "<th>zone</th>";
echo "<th>nas_ip</th>";
echo "<th>switch_name</th>";
echo "<th>switch_ip</th>";
echo "<th>switch_port</th>";
echo "<th>connected_port</th>";
echo "<th>vlan</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['operator_name'] . "</td>";
echo "<td>" . $row['zone'] . "</td>";
echo "<td>" . $row['nas_ip'] . "</td>";
echo "<td>" . $row['switch_name'] . "</td>";
echo "<td>" . $row['switch_ip'] . "</td>";
echo "<td>" . $row['switch_port'] . "</td>";
echo "<td>" . $row['connected_port'] . "</td>";
echo "<td>" . $row['status'] . "</td>";
echo "<td>";
echo "<a href='readr.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='updater.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='deleter.php?id=". $row['id'] ."' data-toggle='modal' data-target='#exampleModalLong' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " . mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>
I am Using this script too, which is correct format for header
var $table = $('table');
$table.bootstrapTable({
search: true,
pagination: true,
buttonsClass: 'primary',
minimumCountColumns: 2,
columns: [{
field: 'id',
title: 'ID',
sortable: true,
}, {
field: 'operator_name',
title: 'OPERATOR NAME',
sortable: true,
}, {
field: 'zone',
title: 'zone',
sortable: true,
},
{
field: 'nas_ip',
title: 'nas_ip',
sortable: true,
},
{
field: 'switch_name',
title: 'SWITCH NAME',
sortable: true,
},
{
field: 'switch_ip',
title: 'SWITCH IP',
sortable: true,
},
{
field: 'switch_port',
title: 'SWITCH PORT ',
sortable: true,
},
{
field: 'connected_port',
title: 'connected_port',
sortable: true,
},
{
field: 'vlan',
title: 'VLAN',
sortable: true,
},
{
field: 'operation',
title: 'Action',
},
],
});
So you're using bootstrab table plugin. You need to add rowStyle handler.
In your JS script you can try add.
function rowStyle(row, index) {
var classes = ['success','danger'];
if(row.vlan=="ACTIVE")
return {
classes: classes[0]
};
if(row.vlan=="DEACTIVE")
return {
classes: classes[1]
};
return {};
}
In your PHP file:
Change:
echo "<table class='table js-dynamitable table-bordered table-striped table-condensed'>";
To:
echo "<table data-row-style='rowStyle' class='table js-dynamitable table-bordered table-striped table-condensed'>";
Change:
echo "<th>vlan</th>";
To:
echo "<th data-field='vlan'>vlan</th>";
Demo: http://jsfiddle.net/jyjafk8v/
http://bootstrap-table.wenzhixin.net.cn/documentation/ - search 'rowStyle' if you need more info about it.
I have changed status td (column) . Add inline style and apply background color on if else base. Check the code below.
<?php
// Include config file
require_once 'config.php';
// Attempt select query execution
$sql = "SELECT * FROM retail";
if($result = mysqli_query($link, $sql)){
if(mysqli_num_rows($result) > 0){
echo "<table class='table js-dynamitable table-bordered table-striped table-condensed'>";
echo "<thead>";
echo "<tr>";
echo "<th>#</th>";
echo "<th>operator_name</th>";
echo "<th>zone</th>";
echo "<th>nas_ip</th>";
echo "<th>switch_name</th>";
echo "<th>switch_ip</th>";
echo "<th>switch_port</th>";
echo "<th>connected_port</th>";
echo "<th>vlan</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while($row = mysqli_fetch_array($result)){
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['operator_name'] . "</td>";
echo "<td>" . $row['zone'] . "</td>";
echo "<td>" . $row['nas_ip'] . "</td>";
echo "<td>" . $row['switch_name'] . "</td>";
echo "<td>" . $row['switch_ip'] . "</td>";
echo "<td>" . $row['switch_port'] . "</td>";
echo "<td>" . $row['connected_port'] . "</td>";
echo "<td style='color:white;background-color:".($row['status'] == 'ACTIVE'?'green':'grey').";'>" . $row['status'] . "</td>";
echo "<td>";
echo "<a href='readr.php?id=". $row['id'] ."' title='View Record' data-toggle='tooltip'><span class='glyphicon glyphicon-eye-open'></span></a>";
echo "<a href='updater.php?id=". $row['id'] ."' title='Update Record' data-toggle='tooltip'><span class='glyphicon glyphicon-pencil'></span></a>";
echo "<a href='deleter.php?id=". $row['id'] ."' data-toggle='modal' data-target='#exampleModalLong' title='Delete Record' data-toggle='tooltip'><span class='glyphicon glyphicon-trash'></span></a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
// Free result set
mysqli_free_result($result);
} else{
echo "<p class='lead'><em>No records were found.</em></p>";
}
} else{
echo "ERROR: Could not able to execute $sql. " .
mysqli_error($link);
}
// Close connection
mysqli_close($link);
?>

Undefined offset: 0

I want to get simple fb graph data and load that into a table with php, but somehow i receive 4 same error messages why so ever and I dont know what they mean.
Notice: Undefined offset: 0 in index.php on line 52
Notice: Undefined offset: 0 in index.php on line 55
Notice: Undefined offset: 0 in index.php on line 59
Notice: Undefined offset: 0 in index.php on line 60
Here are the lines where the error / warnings appear ..
echo "<table class='table table-hover table-responsive table-bordered'>";
//count the number of events
$events_count = count($obj['data']);
for($x=0; $x<$events_count; $x++){
//fb events will be here
}
echo"</table>";
$start_date = date( 'l, F d, Y', strtotime($obj['data'][$x]['start_time']));
// in my case, I had to subtract 9 hours to sync the time set in facebook
$start_time = date('g:i a', strtotime($obj['data'][$x]['start_time']) - 60 * 60 * 9);
$pic_big = isset($obj['data'][$x]['cover']['source']) ? $obj['data'][$x]['cover']['source'] : "https://graph.facebook.com/{$fb_page_id}/picture?type=large";
$eid = $obj['data'][$x]['id'];
$name = $obj['data'][$x]['name'];
$description = isset($obj['data'][$x]['description']) ? $obj['data'][$x]['description'] : "";
// place
$place_name = isset($obj['data'][$x]['place']['name']) ? $obj['data'][$x]['place']['name'] : "";
$city = isset($obj['data'][$x]['place']['location']['city']) ? $obj['data'][$x]['place']['location']['city'] : "";
$country = isset($obj['data'][$x]['place']['location']['country']) ? $obj['data'][$x]['place']['location']['country'] : "";
$zip = isset($obj['data'][$x]['place']['location']['zip']) ? $obj['data'][$x]['place']['location']['zip'] : "";
$location="";
if($place_name && $city && $country && $zip){
$location="{$place_name}, {$city}, {$country}, {$zip}";
}else{
$location="Location not set or event data is too old.";
}
echo "<tr>";
echo "<td rowspan='6' style='width:20em;'>";
echo "<img src='{$pic_big}' width='200px' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width:15em;'>What:</td>";
echo "<td><b>{$name}</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>When:</td>";
echo "<td>{$start_date} at {$start_time}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Where:</td>";
echo "<td>{$location}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Description:</td>";
echo "<td>{$description}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Facebook Link:</td>";
echo "<td>";
echo "<a href='https://www.facebook.com/events/{$eid}/' target='_blank'>View on Facebook</a>";
echo "</td>";
echo "</tr>";
?>
Thanks for help and fast answer
Add your code inside loop.
Try
<?php
echo "<table class='table table-hover table-responsive table-bordered'>";
//count the number of events
$events_count = count($obj['data']);
for($x=0; $x<$events_count; $x++)
{
//fb events will be here
$start_date = date( 'l, F d, Y', strtotime($obj['data'][$x]['start_time']));
// in my case, I had to subtract 9 hours to sync the time set in facebook
$start_time = date('g:i a', strtotime($obj['data'][$x]['start_time']) - 60 * 60 * 9);
$pic_big = isset($obj['data'][$x]['cover']['source']) ? $obj['data'][$x]['cover']['source'] : "https://graph.facebook.com/{$fb_page_id}/picture?type=large";
$eid = $obj['data'][$x]['id'];
$name = $obj['data'][$x]['name'];
$description = isset($obj['data'][$x]['description']) ? $obj['data'][$x]['description'] : "";
// place
$place_name = isset($obj['data'][$x]['place']['name']) ? $obj['data'][$x]['place']['name'] : "";
$city = isset($obj['data'][$x]['place']['location']['city']) ? $obj['data'][$x]['place']['location']['city'] : "";
$country = isset($obj['data'][$x]['place']['location']['country']) ? $obj['data'][$x]['place']['location']['country'] : "";
$zip = isset($obj['data'][$x]['place']['location']['zip']) ? $obj['data'][$x]['place']['location']['zip'] : "";
$location="";
if($place_name && $city && $country && $zip){
$location="{$place_name}, {$city}, {$country}, {$zip}";
}else{
$location="Location not set or event data is too old.";
}
echo "<tr>";
echo "<td rowspan='6' style='width:20em;'>";
echo "<img src='{$pic_big}' width='200px' />";
echo "</td>";
echo "</tr>";
echo "<tr>";
echo "<td style='width:15em;'>What:</td>";
echo "<td><b>{$name}</b></td>";
echo "</tr>";
echo "<tr>";
echo "<td>When:</td>";
echo "<td>{$start_date} at {$start_time}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Where:</td>";
echo "<td>{$location}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Description:</td>";
echo "<td>{$description}</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Facebook Link:</td>";
echo "<td>";
echo "<a href='https://www.facebook.com/events/{$eid}/' target='_blank'>View on Facebook</a>";
echo "</td>";
echo "</tr>";
}
echo"</table>";
?>
You should close for correctly.
You can't use $x var out of for.
Your for loop is:
for($x=0; $x<$events_counts; $x++) {
// fb events will be here
}
// other code below
// $x is not available here!
So, basically you have } and you're trying to access $x which is declarated (unless it's global) in scope of for, but it doesn't exists below closing bracket. Put your code in for loop and it should works.

Check bootstrap table row - Javascript

I need to check/uncheck a table checkbox based on a value stored in a database. I'm not an experienced programmer. I've been Google-ing this for a whole day with no luck. Hope someone's going to help me.
Here's the code :
echo "<table data-toggle='table' data-click-to-select='true' id='potable'>";
echo "<thead>";
echo "<tr>";
echo "<th data-field='state' data-checkbox='true'></th>";
echo "<th data-field='code'>Code</th>";
echo "<th data-field='description'>Description</th>";
echo "<th data-field='verb'>Verb</th>";
echo "<th>Actions</th>";
echo "</tr>";
echo "</thead>";
echo "<tbody>";
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
echo "<tr>";
echo "<td>"; ?>
<script>
var select = <?php echo "{$selected}"; ?>;
if (select == 1) {
// INSERT HERE JAVASCRIPT LINE THAT CHECKS THE CURRENT CHECKBOX
else {
//UNCHECK THE CURRENT CHECKBOX
}
</script>
<?php
echo "</td>";
echo "<td>{$code}</td>";
echo "<td>{$description}</td>";
echo "<td>{$verb}</td>";
echo "<a type='button' class='btn btn-primary left-margin' href='po-info.php?id={$id}'>Info</a>";
echo "</td>";
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
Finally managed to make it work
Used
echo "<th data-field='selected' data-checkbox='true' data-formatter='stateFormatter'></th>";
then
<script>
function stateFormatter(value, row, index) {
if (value == 1) {
return {
checked: true
};
} else {
return {
checked: false
};
}
return value;
}
</script>
Try
$("th[data-checkbox='true'] input[type=checkbox]").attr('checked', <?=$selected?'true':'false'?>);
<table>
<?php
while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
extract($row);
$checked_ids = array();
$checked_ids[] = $id;
$chk_str = '<input data-index="%s" name="chk" type="checkbox">';
echo "<tr>";
echo "<td>";
printf($chk_str, $id);
echo "</td>";
echo "</tr>";
}
?>
</table>
<input type="hidden" id="db_checked" value="<?php echo implode(",",$checked_ids); ?>" />
<script>
// need jquery.js
$(function () {
var $table = $('#potable'),
var string = $('#db_checked').val();
var array = string.split(',');
for (var ck_id in array) {
$table.bootstrapTable('check', parseInt(ck_id, 10));
// check or uncheck
}
}
</script>
maybe "data-index" is write at "tr" tags

Get row content to a popup window

I have used this function to pop up a window, when a user clicked the table row
<script type="text/javascript">
$(document).ready(function() {
$("td.abc").click(function() {
var t = 'Ticket ID: ' + $(this).find('td:eq(0)').html()+'\n'+'\n';
var r = 'Subject: ' + $(this).find('td:eq(1)').html()+'\n'+'\n';
var e = 'Messege: ' + $(this).find('td:eq(2)').html()+'\n'+'\n';
var f = 'Developer: ' + $(this).find('td:eq(3)').html()+'\n'+'\n';
var w = 'Current Status: ' + $(this).find('td:eq(4)').html()+'\n'+'\n';
var q = 'Uploaded Date & Time: ' + $(this).find('td:eq(5)').html()+'\n'+'\n';
var o = $("#79").attr("name")+'\n'+'\n';
alert(t+r+e+f+w+q+o);
});
});
</script>
my table is as follows
echo "<br> <table border='0' id='example' width='980' align='center'>
<tr>
<th width='60'>Ticket ID</th>
<th width='150'>Subject</th>
<th width='670'>Messege</th>
<th width='60'>Developer</th>
<th width='70'>Status</th>
<th width='105'>Date - Time</th>
</tr>";
while($row = mysql_fetch_array($result)) {
//echo $row['jobSatus'];
echo "<tr>";
echo "<td class=\"abc\" width='60'>" . $row['id'] . "</td>";
echo "<td class=\"abc\" width='150'>" . $row['subject'] . "</td>";
echo "<td class=\"abc\" width='670'>" . $row['msg'] . "</td>";
echo "<td class=\"abc\" width='60'>" . $row['developer'] . "</td>";
echo "<td class=\"abc\"width='60'>" . $row['jobstatus'] . "</td>";
echo "<td class=\"abc\" width='105'>" . $row['date_time'] . "</td>";
echo "<input class=\"abc\" type='hidden' name=".$row['image']." id=".$row['id'].">";
echo "</tr>";
}
echo "</table>";
Now inside the pop window I don't get any values. It says "undefined". I would be very thankful if someone could show what I have done wrong.
try to change this...
var t = 'Ticket ID: ' + $(this).find('td:eq(0)').html()+'\n'+'\n';
to this
var t = 'Ticket ID: ' +$(this).closest('td:eq(0)').attr('class');
Hope this will help....
You are clicking on a table cell, not a table row
$("td.abc").click(function() {
^^
Change it to look at the table
$("#example").on("click", "tr", function () {
or
$("#example").on("click", "tr:has(td.abc)", function () {
And your HTML markup is invalid since an input element can not be a child element of a tr.
Set onclick on table-row
$("tr.ticker-row").click(function(ev) {
var $this = $(ev.currentTarget);
var t = 'Ticket ID: ' + $this.find('td:eq(0)').html()+'\n'+'\n';
var r = 'Subject: ' + $this.find('td:eq(1)').html()+'\n'+'\n';
var e = 'Messege: ' + $this.find('td:eq(2)').html()+'\n'+'\n';
var f = 'Developer: ' + $this.find('td:eq(3)').html()+'\n'+'\n';
var w = 'Current Status: ' + $this.find('td:eq(4)').html()+'\n'+'\n';
var q = 'Uploaded Date & Time: ' + $this.find('td:eq(5)').html()+'\n'+'\n';
var o = $this.find('input').attr('name') + '\n'+'\n';
alert(t+r+e+f+w+q+o);
});
On php, do not insert any node in tr except td
while($row = mysql_fetch_array($result)) {
//echo $row['jobSatus'];
echo "<tr class=\"ticket-row\" data-row-index=\"".$row['id']."\">";
echo "<td class=\"abc\" width='60'>" . $row['id'] . "<input class=\"abc\" type='hidden' name=".$row['image']." ></td>";
echo "<td class=\"abc\" width='150'>" . $row['subject'] . "</td>";
echo "<td class=\"abc\" width='670'>" . $row['msg'] . "</td>";
echo "<td class=\"abc\" width='60'>" . $row['developer'] . "</td>";
echo "<td class=\"abc\"width='60'>" . $row['jobstatus'] . "</td>";
echo "<td class=\"abc\" width='105'>" . $row['date_time'] . "</td>";
echo "</tr>";
}
echo "</table>";

Remove value on click

I want to create a javascript that will change the value of anotif to 0 once clicked:
Approved:<?php if($anotif<1){
echo 0;
} else {
echo '<a class="anotif" onClick="validator()" href="?anotif">'.$anotif.'</a>';
} ?><br/>
But I am not sure how do that, considering that I'm so new in javascript. I've googled around a bit but I wasn't able to find the answer.
function validator(){
if(document.anotif.clicked){ // I'm not really sure if this is correct.
// if clicked, change value to zero
}
To be more precise, I want it to look like this once clicked:
From:
Approved:3
To:
Approved:0
Approved:<?php if($anotif<1){
echo 0;
} else {
echo '<a class="anotif" onClick="validator()" href="?anotif">'.$anotif.'</a>';
} ?><br/>
This code will lead me to ?anotif for me to view some data from the database in a table. Once approved: is clicked, it must be set to zero at the same time I move to the other page.
The problem is it requires refreshing for it to be set to 0 by the system.
Here is the rest of the code:
$firstname = getuserfield('txtFname');
$lastname = getuserfield('txtLname');
echo 'Hello '.$firstname.' '.$lastname.'.<br/>';
$anotif = 0;
$dnotif = 0;
$anotif = $anotif + getuserfield('approved_notif');
$dnotif = $dnotif + getuserfield('disapproved_notif');
?>
<h3>Notifications:</h3>
Approved:<?php if($anotif<1){echo 0;} else { echo '<a class="anotif" onClick="validator(this);" href="?anotif">'.$anotif.'</a>';}?><br/> //problem is over here
<?php
if(isset($_GET['anotif'])) {
$query = "SELECT * FROM hrf_leave WHERE empid = '$empid' AND formStatus = 1 AND checked = 0";
$query_run = mysql_query($query) or die($query."<br/><br/>".mysql_error());
echo "<table border=1>
<tr>
<th>Type of Leave</th>
<th>Specific Reason</th>
<th>Date From</th>
<th>Date To</th>
<th>Number of Days</th>
</tr>";
echo "<tr>";
while($record = mysql_fetch_array($query_run)){
$leave_id = $record['leave_id'];
echo "<td>" . $record['type_of_leave'] . "</td>";
echo "<td>" . $record['specific_reason'] . "</td>";
echo "<td>" . $record['date_from'] . "</td>";
echo "<td>" . $record['date_to'] . "</td>";
echo "<td>" . $record['num_of_days'] . "</td>";
echo "</tr>";
$query2 = "UPDATE hrf_leave SET checked=1 WHERE leave_id = $leave_id";
if($query_run2 = mysql_query($query2)){
$anotif = 0;
$query3 = "UPDATE hrms_emp_info SET approved_notif=$anotif WHERE empid = $empid";
if($query_run3 = mysql_query($query3)){
}
}
}
echo "</table>";
}
?>
Disapproved:<?php if($dnotif<1){echo 0;} else { echo ''.$dnotif.'<br/>';} ?> //and here
<?php
if(isset($_GET['dnotif'])) {
$query = "SELECT * FROM hrf_leave WHERE empid = '$empid' AND formStatus = 2 AND checked=0";
$query_run = mysql_query($query);
echo "<table border=1>
<tr>
<th>Type of Leave</th>
<th>Specific Reason</th>
<th>Date From</th>
<th>Date To</th>
<th>Number of Days</th>
</tr>";
echo "<tr>";
while($record = mysql_fetch_array($query_run)){
$leave_id = $record['leave_id'];
echo "<td>" . $record['type_of_leave'] . "</td>";
echo "<td>" . $record['specific_reason'] . "</td>";
echo "<td>" . $record['date_from'] . "</td>";
echo "<td>" . $record['date_to'] . "</td>";
echo "<td>" . $record['num_of_days'] . "</td>";
echo "</tr>";
$query2 = "UPDATE hrf_leave SET checked=1 WHERE leave_id = $leave_id";
if($query_run2 = mysql_query($query2)){
$dnotif = $dnotif-1;
$query3 = "UPDATE hrms_emp_info SET disapproved_notif=$dnotif WHERE empid = $empid";
if($query_run3 = mysql_query($query3)){
}
}
}
echo "</table>";
}
You could change your anchor a bit like this:
<a class="anotif" onClick="return validator(this)" href="?anotif">
Then change the validator() function like this:
function validator(element)
{
// element is clicked already, so you can change its value
element.innerHTML = '0';
// prevent click from changing page
return false;
}
However, the real problem here is that the page will be changed to ?anotif and whatever you changed will be wasted effort.
Updated the code with a way to prevent the click from changing the page and just reducing the number to '0'.

Categories

Resources