I am using Orangehrm 3.2.1(latest build). Below is the php code I am using to display a leave plan calendar for the employees employed with me since its too costly to buy from Orangehrm. When I run this script, I get screen on my browser which shows a part of the code....
".$seeDate.""; ?>
Month: Year:
".$i."
"; } ?> "; $even = 1; while ($row = mysql_fetch_array( $result ) ) { $employee_id = $row['employee_id']; $employee_num = $row['emp_number']; $employee_firstname = $row['emp_firstname']; $employee_lastname = $row['emp_lastname']; echo ""; if ( $even % 2) echo " "; else echo " "; $even++; // echo "$even $numDays
"; for ($i = 1; $i <= $numDays; $i++) { $day = checkDay($employee_num, $i, $month, $year); // echo "$employee_num, $i, $month, $year $day
"; switch ($day) { case 'holiday': echo " "; break; case 'weekend': echo " "; break; case 'absence_full': echo " "; break; case 'absence_partial_m': echo " "; break; case 'absence_partial_a': echo " "; break; default: echo " "; break; }//switch }//for echo ""; }//while ?>
The code which is seen on the screen is a part of my php script. Is there any modification that i need to carry out? I have played a lot around with it but don't seem to get it correct. The code as compared to orangehrm version 2.5 has been changed and they have been marked with // in the script below.
<?php
/*****************/
/* Configuration */
/*****************/
//Database information
$db_host = "localhost";
$db_user = "root";
$db_pwd = "";
$db_name = "main";
$db_port = 3306;
$logoLink = "orangehrm/symfony/web/webres_513fd0981da216.38969927/themes/default/images/login/logo.png";
/******************************/
/* DONT EDIT BELLOW THIS LINE */
/******************************/
//Year
if (isset($_GET['year']))
$year = $_GET['year'];
else
$year = date("Y");
//Month
if (isset($_GET['month']))
$month = $_GET['month'];
else
$month = date("m");
$date_aux = $year . "-" . $month;
$seeDate = date("Y-m", strtotime($date_aux));
/* Number of days in a month/Year */
function monthDays($month, $year) {
return date("t", strtotime($year . "-" . $month . "-01"));
}//
//admin get Years
function getYears($year) {
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
if(!isset($year))
$year = date("Y");
// $sql = "SELECT DISTINCT(EXTRACT(Year FROM leave_date)) FROM hs_hr_leave WHERE 1 ORDER BY leave_date;";
$sql = "SELECT DISTINCT(EXTRACT(Year FROM date)) FROM ohrm_leave WHERE 1 ORDER BY date;";
// Make a MySQL Connection
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
//Query
$result = mysql_query($sql) or die(mysql_error());
while ($row = mysql_fetch_array($result )) {
if ($row['(EXTRACT(Year FROM Date))'] == $year) {/*
echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\" selected>".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";*/
echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\" selected>".$row['(EXTRACT(Year FROM date))']."</option><br>";
} else {
// echo "<option value=\"".$row['(EXTRACT(Year FROM leave_date))']."\">".$row['(EXTRACT(Year FROM leave_date))']."</option><br>";
echo "<option value=\"".$row['(EXTRACT(Year FROM date))']."\">".$row['(EXTRACT(Year FROM date))']."</option><br>";
}
}
}//
function weekDay($date) {
$thisDay = date("D", strtotime($date));
return $thisDay;
}//
function checkDay($employee_id, $i, $month, $year) {
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
$date = $year . "-" . $month . "-" . $i;
// $sql = "SELECT * FROM hs_hr_holidays WHERE date = '$date';";
$sql = "SELECT * FROM ohrm_holiday WHERE date = '$date';";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(msysql_error());
$result_count = mysql_num_rows($result);
if ($result_count > 0)
return "holiday";
if( ( weekDay($date) == "Sat") || ( weekDay($date) == "Sun") ) {
return "weekend";
}
//Get Absences
// $sql = "SELECT leaves.*
// FROM `hs_hr_leave` AS leaves
// WHERE (leaves.employee_id = '$employee_id') AND (leaves.leave_date = '$date') AND (leaves.leave_status > 1)
// ORDER BY leaves.leave_date ASC;";
$sql = "SELECT leaves.*
FROM `ohrm_leave` AS leaves
WHERE (leaves.emp_number = '$employee_id') AND (leaves.date = '$date') AND (leaves.status > 1)
ORDER BY leaves.date ASC;";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(mysql_error());
$result_count = mysql_num_rows($result);
if ( $result_count == 0 ) {
// echo "default<br>";
return "default";
} else {
while ($row = mysql_fetch_array( $result ) ) {
if ($row['leave_length_days'] < 1.0 ) {
if ( ($row['start_time'] >= "08:00:00") && ($row['start_time'] <= "09:00:00") )
return "absence_partial_m";
else if ( ($row['start_time'] >= "13:00:00") && ($row['start_time'] <= "18:00:00") )
return "absence_partial_a";
} else
// echo "full abs<br>";
return "absence_full";
}//
}
}
$numDays = monthDays($month, $year);
?>
<HTML>
<HEAD><TITLE>Vacation Plan</TITLE>
<script type="text/javascript">
function sort(form) {
var Page = "?";
var month = form.listMonth.selectedIndex+1;
var iyear = form.listYear.selectedIndex;
var year = form.listYear.options[iyear].value;
var URL = Page + "month=" + month + "&year=" + year;
window.location = URL;
return false;
}
</script>
<style type="text/css">
<!--
.style2 {font-size: 12px; }
td{ border:solid 1px red;}
-->
</style>
</HEAD>
<BODY>
<?
?>
<?php if (!empty($logoLink))
echo "<img src='$logoLink'/>";
?>
<center>
<div id="sort" style="padding-right: 10%">
<form id="frmSort" name="frmSort" onsubmit="return sort(this); return false;">
<?
$seeDate = date("F Y", strtotime($seeDate));
echo "<h2>".$seeDate."</h2>";
?>
<div align="right">
<strong>Month</strong>:
<?php
$curr_month = $month;
$auxmonth = array (1=>"January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December");
$select = "<select name=\"listMonth\">\n";
foreach ($auxmonth as $key => $val) {
$select .= "\t<option val=\"".$key."\"";
if ($key == $curr_month) {
$select .= " selected>".$val."\n";
} else {
$select .= ">".$val."\n";
}
}
echo $select;
?>
</select>
<img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" /><strong>Year</strong>:
<select name="listYear" id="listYear">
<?php getYears($year); ?>
</select>
<img src="img/pixel.gif" width="1" height="1" /> <img src="img/pixel.gif" width="1" height="1" />
<input type="submit" name="Submit" value="Select" />
</form>
</div>
<div id="table">
<table width="90%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td > </td>
<?
for($i = 1; $i <= $numDays; $i++) {
echo "<td bgcolor=\"#FFFFFF\" width=\"15\"><div align=\"center\"><strong>".$i."</strong></div></td>";
}
?>
</tr>
<?
global $db_host, $db_user, $db_pwd, $db_name, $db_port;
// $sql = "SELECT emp.*
// FROM hs_hr_employee AS emp
// INNER JOIN hs_hr_users AS users ON emp.emp_number = users.emp_number
// WHERE (users.status = 'Enabled')
// ORDER BY emp.emp_firstname ASC";
$sql = "SELECT emp.*
FROM hs_hr_employee AS emp
INNER JOIN ohrm_user AS users ON emp.emp_number = users.emp_number
WHERE (users.status = 1)
ORDER BY emp.emp_firstname ASC";
mysql_connect($db_host, $db_user, $db_pwd) or die(mysql_error());
mysql_select_db($db_name) or die(mysql_error());
$result = mysql_query($sql)or die(mysql_error());
$result_count = mysql_num_rows($result);
// echo "toto:$result_count<br>";
$even = 1;
while ($row = mysql_fetch_array( $result ) ) {
$employee_id = $row['employee_id'];
$employee_num = $row['emp_number'];
$employee_firstname = $row['emp_firstname'];
$employee_lastname = $row['emp_lastname'];
echo "<tr>";
if ( $even % 2)
echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
else
echo " <td bgcolor=\"#FFFFFF\" width=\"10%\"><div align=\"right\">".$employee_firstname . " " . $employee_lastname . "</div></td>";
$even++;
// echo "$even $numDays<br>";
for ($i = 1; $i <= $numDays; $i++) {
$day = checkDay($employee_num, $i, $month, $year);
// echo "$employee_num, $i, $month, $year $day<br>";
switch ($day) {
case 'holiday':
echo " <td bgcolor=\"#0000FF\"></td>";
break;
case 'weekend':
echo " <td bgcolor=\"#999999\"></td>";
break;
case 'absence_full':
echo " <td bgcolor=\"#FF0000\"></td>";
break;
case 'absence_partial_m':
echo " <td bgcolor=\"#FFFF00\"><center>M</center></td>";
break;
case 'absence_partial_a':
echo " <td bgcolor=\"#FFFF00\"><center>A</center></td>";
break;
default:
echo " <td bgcolor=\"##00FF00\"></td>";
break;
}//switch
}//for
echo "</tr>";
}//while
?>
</table>
</div>
</center>
<br/>
<div style="padding-left: 5%">
<table width="25%" border="0" cellspacing="1" cellpadding="1">
<tr>
<td bgcolor="#00FF00"> </td>
<td><div align="left" class="style2">Available</div></td>
</tr>
<tr>
<td width="11%" bgcolor="#FF0000"> </td>
<td width="89%"><div align="left" class="style2">Absence</div></td>
</tr>
<tr>
<td bgcolor="#CCCCCC"> </td>
<td><div align="left" class="style2">WeekEnd</div></td>
</tr>
<tr>
<td bgcolor="#0000FF"> </td>
<td><div align="left" class="style2">Public Holiday </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">M</div></td>
<td><div align="left" class="style2">Partial Absence (Morning) </div></td>
</tr>
<tr>
<td bgcolor="#FFFF00"><div align="center">A</div></td>
<td><span class="style2"> Partial Absence (Afternoon) </span></td>
</tr>
</table>
</div>
<br/>
<div align="center"> </div>
</BODY>
</HTML>
Thanks for sharing the code.
I seem to have got it working with 3.3! :)
I don't get the error you get.
Try adding debug code at the beginning: after
ini_set('display_errors', 'On');
I found that full day absence wasn't showing so I edited the code by removing
the comment at line 137:
} else
// echo "full abs";
return "absence_full";
not sure why I had to leave in semicolon though - thus:
} else
;
return "absence_full";
you need to turn short_tags on in PHP ini if you are going to use <? ?>
Related
I am new in JavaScript i don't know how to do ajax in pagination. is there anyone who can help me out on ajax in pagination. I write normal code of PHP and Ajax .
Thank you for your good support(:
i know that in ajax pagination is work on ClassName is active or not and replace the Inner HTML at the end but I don't know how can i do in my Code
this is my pagination.php file
<script type="text/javascript" src='../project/assets/js/ajax_pegination.js'></script>
<?php
include('../project/header.php');
include('../project/sidebar.php');
?>
<div class="body-contant">
<div class="main">
<table align="center">
<h2>Persnol information</h2>
<tr>
<div class="column">
<th>Id</th>
<th>firstName</th>
<th>lastName</th>
<th>email</th>
<th>mobileNo</th>
<th>gender</th>
<th>hobbies</th>
<th>Prewview</th>
<th>function</th>
</div>
</tr>
<?php
if (check_is_admin($_SESSION['id'])) {
$select = "SELECT * FROM form";
}
else{
$select = "SELECT * FROM form WHERE ID=".$_SESSION['id'];
}
$result= mysqli_query($conn, $select);
$total_rows= mysqli_num_rows($result);
$limit= 3;
$totalPages= ceil ($total_rows/$limit);
if (!isset ($_GET['page']) ) {
$pageNumber= 1;
} else {
$pageNumber= $_GET['page'];
}
$offset= ($pageNumber-1) * $limit;
if (check_is_admin($_SESSION['id'])) {
$select= "SELECT *FROM form LIMIT " . $offset . ',' . $limit;
}
$result= mysqli_query($conn, $select);
while($data = mysqli_fetch_assoc($result)) {
$extract=explode(',',$data['hobbies']);
$hobbies=[];
?>
<tr>
<td><?php echo $data['ID']; ?> </td>
<td><?php echo $data['first_name']; ?> </td>
<td><?php echo $data['last_name']; ?> </td>
<td><?php echo $data['email']; ?> </td>
<td><?php echo $data['mobile_no']; ?> </td>
<td><?php echo $data['gender']; ?> </td>
<?php
foreach($extract as $hobbiesId){
$select1 = "SELECT * from hobbies WHERE `ID` IN ($hobbiesId)";
$result1=mysqli_query($conn,$select1);
while($data1=mysqli_fetch_assoc($result1)){
$hobbies[] = $data1['name'];
}
}
?>
<td><?php echo implode(",", $hobbies); ?> </td>
<td><img src="..\project\assets\uploads\<?php echo $data['file_path'] ?>" id="preview" alt="img"></td>
<div class="btn">
<td>
<a class="button1" type="button" name="edit" href="..\project\edit_user.php?id=<?php echo $data['ID']; ?>">Edit</a>
<a class="button2" type="button" name="delete" href="../project/delete_user.php?id=<?php echo $data['ID']; ?>" onclick="return confirm('are you sure you want to delete??');">Delete</a>
</td>
</div>
</tr>
<?php
}
?>
</table>
<!-- --------------------------------------------------------- -->
<div class="pagination">
<?php
if (check_is_admin($_SESSION['id'])) {
$pageURL = "";
if($pageNumber>=2){
echo "<a class='prev' href='pagination.php?page=".($pageNumber-1)."' onchange='load()'> Prev </a>";
}
for ($i=1; $i<=$totalPages; $i++) {
if ($i == $pageNumber) {
$pageURL .= "<a class = 'active' href='pagination.php?page=" .$i."'>".$i." </a>";
}
else {
$pageURL .= "<a href='pagination.php?page=".$i."'>".$i." </a>";
}
};
echo $pageURL;
if($pageNumber<$totalPages){
echo "<a class='next' href='pagination.php?page=".($pageNumber+1)."'> Next </a>";
}
}
?>
</div>
<!-- ------------------------------------------------------- -->
</div>
</div>
<?php
include('../project/footer.php');
?>
and this my AJAX_pagination.js file
// document.getElementsByClassName("prev").addEventListener("change", (event) => {
// event.preventDefault();
// load();
// });
function load(){
var httpx = new XMLHttpRequest();
httpx.onreadystatechange = function(){
if(this.readyState==4 && this.status==200){
console.log(this);
document.getElementsByClassName("prev").innerHTML=this.responseText;
}
}
httpx.open("POST", "http://localhost/project/pagination.php", true);
httpx.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
httpx.send();
}
I am calling Api : $url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123'; and fetching Status results of all Order IDS & displaying in php page when we refresh php page.
Now i want to select Order IDs through checkbox, than when i click on button "Show Status" , than only i want to Call Api & update the Selected Order IDs status in web page.
<p><button type= "button" class="call">Show Status</button></p>
<table class="tbl-qa" border="1">
<thead>
<tr>
<th class="table-header"></th>
<th class="table-header">ORDERID</th>
<th class="table-header">Status</th>
</tr>
</thead>
<tbody id="table-body">
<?php
$tabindex = 1;
if (!empty($orderrecords))
{
foreach($orderrecords as $k => $v)
{ ?>
<?php
$hide = '';
$data['username'] = 'admin';
$data['password'] = 'admin123';
$url = 'https://plapi.ecomexpress.in/track_me/api/mawbd/?awb=awbnumber&order=' . $orderrecords[$k]["order_id"] . '&username=admin&password=admin123';
$ch = curl_init();
// some curl code
$res = explode("\n", $output);
if (!isset($res[13]))
{
$res[13] = null;
}
$status = $res[13];
?>
<tr class="table-row" id="table-row-<?php echo $orderrecords[$k]["id"]; ?>" tabindex="<?php echo $tabindex; ?>">
<td><input onclick="assignorderids('<?php echo $orderrecords[$k]["order_id"]; ?>')" type="checkbox" name="assigneeid" id="assigneeid-<?php echo $orderrecords[$k]["order_id"]; ?>" value="<?php echo $orderrecords[$k]["order_id"]; ?>"></td>
<td><?php echo $orderrecords[$k]["order_id"]; ?></td>
<td><?php echo $status; ?></td>
</tr>
<?php
$tabindex++;
}
} ?>
</tbody>
</table>
Please help me how i can achieve this ?
Update : assignorderids function
function assignorderids(oid)
{
var checkstatus=$("#assigneeid-"+oid).is(":checked");
var morderId =document.getElementById("orderids").value;
if(checkstatus==false)
{
var arrayorder = JSON.parse("[" + morderId + "]");
document.getElementById("orderids").value='';
for (var i = 0; i < arrayorder.length; i++) {
var orderstatusValue=arrayorder[i];
if(orderstatusValue!=oid){
if (document.getElementById("orderids").value=='')
{
document.getElementById("orderids").value=orderstatusValue;
}
else
{
var newvalue=document.getElementById("orderids").value;
document.getElementById("orderids").value=newvalue+","+orderstatusValue;
}
}
}
}
else
{
if(morderId=='')
{
document.getElementById("orderids").value=oid;
}
else
{
document.getElementById("orderids").value=morderId+","+oid;
}
}
}
Url Output
after enter 3 type of words (alphabetic numeric and alphanumeric in html file. on second page we need to create button and links which will take us to third page. if we click first button it should show us only alphabetic. second button should show only numeric.
someone please help!!
file second:
$sentence = isset($_GET["phrase"]) ? $_GET["phrase"] : $_GET["phrase"];
$w = transformer($sentence);
$sentence = isset($_GET["filter"]) ? $_GET["filter"] : $_GET["filter"];
$w = transformer($sentence);
?>
<table>
<tr>
<th>Word</th>
<th>Length</th>
<th>Type</th>
<tr><td>
<?php
for ($x = 0; $x < count($w); $x++) {
echo "$w[$x] <br>";
}
?> </td>
<td> <?php
for ($x = 0; $x < count($w); $x++) {
$length = strlen($w[$x]);
echo "$length <br>";
}
?>
</td>
<td> <?php
for ($x = 0; $x < count($w); $x++) {
if (ctype_alpha($w[$x])) {
echo "Alphabetic <br>";
} else if(ctype_digit($w[$x])) {
echo "Numeric <br>";
} else {
echo "Alphanumeric <br>";
}
}
?>
</td>
</tr>
</tr>
<?php
function transformer($words){
$w = explode(' ', $words);
return $w;
}
function validation($words){
if($words == null || $words == ""){
echo "Submission will not proceed";
return false;
}
else if(!is_numeric($words)){
echo "Submission will proceed";
return false;
}
return true;
}
?>
<form action="PhraseFilter.php" method="get">
<input type="hidden" name="phrase" value="<?php echo
$_POST["phrase"]?>"/>
<input type="hidden" name="filter" value="TBD"/>
<input type="submit" value="show alpha"
onclick="document.getElementById('filter').value = 'alphabetic';"/>
<input type="submit" value="Show number"
onclick="document.getElementById('filter').value = 'numeric';" />
</form>
</div>
</body>
Second file
$sentence = isset($_POST["phrase"]) ? $_POST["phrase"] : $_GET["phrase"];
$w = transformer($sentence);
$sentence = isset($_POST["filter"]) ? $_POST["filter"] : $_POST["filter"];
$w = transformer($sentence);
?>
<table>
<tr>
<th>Word</th>
<th>Length</th>
<th>Type</th>
<tr><td>
<?php
for ($x = 0; $x < count($w); $x++) {
echo "$w[$x] <br>";
}
?> </td>
<td> <?php
for ($x = 0; $x < count($w); $x++) {
$length = strlen($w[$x]);
echo "$length <br>";
}
?>
</td>
<td> <?php
//for ($x = 0; $x < count($w); $x++) {
if ((ctype_alpha(substr($w[$x])){
echo "Alphabetic <br>";
} else if(ctype_digit(substr($w[$x])) {
echo "Numeric <br>";
}
// }
?>
</td>
</tr></tr>
<?php
function transformer($words){
$w = explode(' ', $words);
return $w;
}
// Validations
function validation($words){
// Validation if Empty
if($words == null || $words == ""){
echo "Submission will not proceed";
return false;
}
// Validation if Valid Number
else if(!is_numeric($words)){
echo "Submission will proceed";
return false;
}
return true;
}
?>
<?php
?>
</div>
</body>
url only updates when pressed button is pressed once and has to be pressed again to show details. The reason I can press it twice is because the div='read' flashes blank the first time and with the details the second time.
Don't know how to fix the div from flashing and how to set url before it opens to div with the results.
PHP AT THE TOP OF ACCOUNT PAGE
$getmessages = "SELECT * FROM messages WHERE messages.receiver='$email' ORDER BY date DESC";
$messageresult = mysqli_query($conn, $getmessages) or die(mysqli_error($conn));
if (isset($_GET['msgid'])) {
$filter = $_GET["msgid"];
$getmessage = "SELECT * FROM messages WHERE messages.message_id ='$filter'";
$getresult = mysqli_query($conn, $getmessage) or die(mysqli_error($conn));
if (mysqli_num_rows($getresult) > 0) {
while ($row = mysqli_fetch_assoc($getresult)) {
$displaysub = $row["subject"];
$displaydate = $row["date"];
$displaysender = $row["sender"];
$displayreceiver = $row["receiver"];
$displaymessageid = $row["message_id"];
$displaymessage = $row["message"];
}
}
} else {
$displaysub = "";
$displaydate = "";
$displaysender = "";
$displayreceiver = "";
$displaymessageid = "";
$displaymessage = "";
}
mysqli_close($conn);
?>
MAIN HTML/PHP
<div id="msginbox">
<h4><strong>Inbox</strong></h4>
<table id="inbox" class="table table-bordered table-responsive ">
<thead>
<tr>
<th>Date</th>
<th>Sender</th>
<th>Subject</th>
<th></th>
</tr>
</thead>
<tbody>
<?php
if (mysqli_num_rows($messageresult) > 0) {
while ($row = mysqli_fetch_assoc($messageresult)) {
$sub = $row["subject"];
$rdate = $row["date"];
$sender = $row["sender"];
$messageid = $row["message_id"];
$message = $row["message"];
echo "<tr>";
echo "<td id='left'><p>" . $rdate . "</p></td>";
echo "<td id='left'><p>" . $sender . "</p></td>";
echo "<td id='left'><p>" . $sub . "</p></td>";
echo "<td>" . "<button value='account.php?msgid=$messageid' class='btn btn-primary replyback'>Reply</button>" . "</td>";
echo "</tr>";
}
}
?>
</tbody>
</table>
</div>
<div id="read">
<p><strong>From: </strong><?php echo $displaysender; ?><br></p>
<br>
<p><strong>Date: </strong><?php echo $displaydate; ?><br></p>
<br>
<p><strong>Subject: </strong><?php echo $displaysub; ?><br></p>
<br>
<p><strong>Message: </strong><?php echo $displaymessage; ?></p>
<br>
<button id="back">Back</button>
</div>
JQUERY
$(document).ready(function () {
$('.replyback').click(function (e) {
e.preventDefault();
$('#read').css('display', 'block');
$('#msginbox').css('display', 'none');
var newurl = $(this).attr("value");
window.location.href = newurl;
});
});
i have a problem that i don't know how to compare the quantity of user input with the quantity in the database so that if the user put the quantity over the quantity in the database it will come one alert that notice the user that the product have out of stock on that quantity.Below is my code:
<?php
$con = mysql_connect('localhost', 'root', '') or die (mysql_error());
mysql_select_db('warda',$con) or die(mysql_error());
$page_title= 'View Your Shooping Cart';
if(isset($_POST['submit']))
{
foreach( $_POST['qty'] as $key => $value)
{
if (is_numeric ($value))
{
if(($value == 0) AND (is_numeric($value)))
{
unset($_SESSION['cart'][$key]);
}
elseif(is_numeric($value)AND($value>0))
{
$_SESSION['cart'][$key]=$value;
}
}
else
{
print '<script type="text/javascript">';
print 'alert("Please insert the a number")';
print '</script>';
echo '<meta HTTP-EQUIV="REFRESH" content="0; url=viewcart.php">';
exit();
}
}
}
$empty = TRUE;
if(isset($_SESSION['cart']))
{
foreach($_SESSION['cart'] as $key=>$value)
{
if(isset($key))
{
$empty=FALSE;
}
}
}
//echo $empty.'nilai';`
if(!$empty)
{
$query ='SELECT * FROM product WHERE code IN (';//coding dalam database
foreach($_SESSION['cart'] as $key => $value)
{
$query.="'".$key."'".',';
}
$query = substr($query,0,-1).')';
$result = mysql_query($query) or die("error");
echo "<form action=\"viewcart.php\" method=\"POST\">";
echo'<table width="800" align="center" cellpadding=4 cellspacing=0 border=0 align="center" class="style25">
<tr>
<td align="center" width="30%"><b>Code</b></td>
<td align="center" width="30%"><b>Name</b></td>
<td align="center" width="10%"><b>Price</b></td>
<td align="center" width="10%"><b>Quantity</b></td>
<td align="center" width="10%"><b>Total</b></td>
</tr>';
echo'<form action="viewcart.php" method="post">';
$total = 0 ;
while($row_Recordset1 = mysql_fetch_array($result, MYSQL_ASSOC))
{
$subtotal = $_SESSION['cart'] [$row_Recordset1['code']]*$row_Recordset1['price'];
$price = $row_Recordset1['price'];
$total+=$subtotal;
echo"<tr>
<td align=\"center\" width=\"30%\">{$row_Recordset1['code']}</td>
<td align=\"center\" width=\"30%\"><input type=\"hidden\"size=\"3\" `name=\"name\" value= \"{$row_Recordset1['name']}\">{$row_Recordset1['name']} </td>`
<td align=\"center\" width=\"10%\">";
echo "RM " . number_format($price,2);
echo"</td>
<td align=\"center\" width=\"10%\"><input type=\"text\"size=\"3\" name=\"qty[{$row_Recordset1['code']}]\" value=\"{$_SESSION['cart'] [$row_Recordset1['code']]}\"</td>";
echo'<td align="center">RM'.number_format($subtotal,2).'</td>
</tr>';
}
echo'<tr>
<td colspan="4" align="right"><b>Total Price:<b></td>
<td align="right">RM'.number_format($total,2).'</td>
</tr>
</table>';
$_SESSION['total'] = $total;
echo " <div align=\"center\"></p>
<input type=\"submit\"class=\"style1\" name=\"submit\"
value=\"Update My Cart\" /> </div>
</form>
<div align=\"center\">
<form name=\"form1\" method=\"post\" action=\"carts.php\">
<input type=\"submit\" class=\"style1\" name=\"checkout\"
value=\"Checkout\"></p>";
`?>`
</form>
Continue Shopping
</div>
<?php
$today = date("d-m-Y");
mysql_close();
}
else
{
echo 'YOUR CART IS EMPTY';
}
?>