Someone who knows about JTable? I´ve tried to create a specfici table with this plugin however I can´t find the right way. I donwloaded the examples and modify it for my needs. But after change the code I have a blank page only in the browser.
Can someone explain to me where is/are the mistake/s?
index.php
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Table of people',
paging: true,
pageSize: 50,
sorting: true,
defaultSorting: 'Name ASC',
actions: {
listAction: 'PersonActionsPagedSorted.php?action=list',
createAction: 'PersonActionsPagedSorted.php?action=create',
updateAction: 'PersonActionsPagedSorted.php?action=update',
deleteAction: 'PersonActionsPagedSorted.php?action=delete'
},
fields: {
PersonId: {
key: true,
create: false,
edit: false,
list: false,
width: '5%',
},
Fecha: {
title: 'Fecha',
width: '10%',
type: 'date',
}
Nombre: {
title: 'Nombre',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3','4': 'Option4' }
},
Turno: {
title: 'Turno',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
Info: {
title: 'Info',
width: '45%',
type: 'textarea'
},
Estado: {
title: 'Estado',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
Criticidad: {
title: 'Criticidad',
width: '10%',
options: { '1': 'Option1', '2': 'Option2', '3': 'Option3'}
},
}
});
//Load person list from server
$('#PeopleTableContainer').jtable('load');
});
</script>
PersonActionsPagedSorted.php
<?php
try
{
//Open database connection
$con = mysql_connect("localhost","root","");
mysql_select_db("jtabletestdb", $con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get record count
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM people;");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM people ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO people(Fecha, Nombre, Turno, Info, Estado, Criticidad) VALUES('" . $_POST["Fecha"] . "', '" . $_POST["Nombre"] . "','" . $_POST["Turno"] . "', '" . $_POST["Info"] . "','" . $_POST["Estado"] . "', '" . $_POST["Criticidad"] . ";");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
//Update record in database
$result = mysql_query("UPDATE people SET Fecha = '" . $_POST["Fecha"] . "', Nombre = '" . $_POST["Nombre"] . "', Turno = '" . $_POST["Turno"] . "', Info = '" . $_POST["Info"] . "',Estado ='" . $_POST["Estado"] . "', Criticidad = '" . $_POST["Criticidad"]. "' WHERE PersonId = " . $_POST["PersonId"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Deleting a record (deleteAction)
else if($_GET["action"] == "delete")
{
//Delete from database
$result = mysql_query("DELETE FROM people WHERE PersonId = " . $_POST["PersonId"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Close database connection
mysql_close($con);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
?>
If you wonder, yeah I´m very novice in this world and I suppose the answer is simple.
Related
Alert line code is not working as I want to show alert on particular condition but code die after that and alert is also not showing. please tell the solution for this.
case "NEW_REC_INSTANCE_PRIPB":
if (!empty($_REQUEST['PRIADCTG']) && !empty($_REQUEST['SEC_CD']) && !empty($_REQUEST['MATCODE']) && empty($_REQUEST['CLIENT_ADD'])) {
$data = array();
$qRSet = $objComm->GET_QUICK_RESULT("SELECT NVL (address_required, 'N') ADDE_REQ FROM " . $_SESSION['DB_USER'] . ".ad_ccpctg WHERE priadctg = '" . $_REQUEST['PRIADCTG'] . "' AND priccpctg = '" . $_REQUEST['SEC_CD'] . "' AND secccpctg = '" . $_REQUEST['MATCODE'] . "'
AND status = 'Y'", 1);
IF ($qRSet['ADDE_REQ'] == 'Y') {
echo '<script type="text/javascript">alert("Client address is required to enter! please check");</script>';
if (!file_put_contents($_SERVER["DOCUMENT_ROOT"] . '/DS/ccpentry_new/AS_PHP/uploadfile/DAA.txt', $qRSet['ADDE_REQ'])) {
echo 'unable to write';
die;
}
$data['ADD_REQ'] = $qRSet['ADDE_REQ'];
} else {
$data['ADD_REQ'] = $qRSet['ADDE_REQ'];
}
}
if ($_REQUEST['actype'] == "FIRST_NEW_REC") {
$newRecInsDet = $objGbl->SET_PUBL_NEWREC_INSTANCE($_REQUEST, "FY");
} else if ($_REQUEST['actype'] == "NEW_REC") {
$newRecInsDet = $objGbl->SET_PUBL_NEWREC_INSTANCE($_REQUEST, "Y");
} else {
$newRecInsDet = $objGbl->savePubData($_REQUEST, '', "", 1, $_REQUEST['INSNUM']);
}
echo json_encode($newRecInsDet);
exit;
break;
case "NEW_REC_INSTANCE_PRIPB":
$new_array = array();
if (!empty($_REQUEST['PRIADCTG']) && !empty($_REQUEST['SEC_CD']) && !empty($_REQUEST['MATCODE']) && empty($_REQUEST['CLIENT_ADD'])) {
$data = array();
$qRSet = $objComm->GET_QUICK_RESULT("SELECT NVL (address_required, 'N') ADDE_REQ FROM " . $_SESSION['DB_USER'] . ".ad_ccpctg WHERE priadctg = '" . $_REQUEST['PRIADCTG'] . "' AND priccpctg = '" . $_REQUEST['SEC_CD'] . "' AND secccpctg = '" . $_REQUEST['MATCODE'] . "' AND status = 'Y'", 1);
IF ($qRSet['ADDE_REQ'] == 'Y') {
$new_array['success'] = false;
$new_array['error'] = 'Client address is required to enter! please check';
if (!file_put_contents($_SERVER["DOCUMENT_ROOT"] . '/DS/ccpentry_new/AS_PHP/uploadfile/DAA.txt', $qRSet['ADDE_REQ'])) {
echo 'unable to write';
die;
}
$data['ADD_REQ'] = $qRSet['ADDE_REQ'];
} else {
$data['ADD_REQ'] = $qRSet['ADDE_REQ'];
}
}
if ($_REQUEST['actype'] == "FIRST_NEW_REC") {
$new_array['success'] = true;
$new_array['data'] = $objGbl->SET_PUBL_NEWREC_INSTANCE($_REQUEST, "FY");
} else if ($_REQUEST['actype'] == "NEW_REC") {
$new_array['success'] = true;
$new_array['data'] =$objGbl->SET_PUBL_NEWREC_INSTANCE($_REQUEST, "Y");
} else {
$new_array['success'] = true;
$new_array['data'] = $objGbl->savePubData($_REQUEST, '', "", 1, $_REQUEST['INSNUM'])
}
echo json_encode($new_array);
exit;
break;
iam using JQuery jTable and PHP for my Website.
While Loading Data from Database work perfectly! but when Update the Data: send POST to
edit the rows doesent update MySQL database, just jtable, but after reload the Page "load from mysql" the data is back to befor update.
Delete data work, only update don`t update
my js:
//Prepare jTable
$('#log').jtable({
title: 'Domains',
toolbar: {
hoverAnimation: true, //Enable/disable small animation on mouse hover to a toolbar item.
hoverAnimationDuration: 60, //Duration of the hover animation.
hoverAnimationEasing: undefined, //Easing of the hover animation. Uses jQuery's default animation ('swing') if set to undefined.
items: [] //Array of your custom toolbar items.
},
paging: true,
sorting: true,
pageSize : 10,
pageSizes : [ 2, 5, 10, 15, 20, 50, 75, 100, 200, 500 ],
defaultSorting: 'domain ASC',
actions: {
listAction: 'actions.php?action=list',
createAction: 'actions.php?action=create',
updateAction: 'actions.php?action=update',
// deleteAction: 'actions.php?action=delete'
},
messages: DeutschMessages,
fields: {
id_domain: {
key: true,
title: 'ID',
create: false,
edit: false,
list: true
},
domain: {
title: 'Domainname',
width: '30%'
},
exclude: {
title: 'Exclude',
defaultValue: 'www,ns,ftp,mail,mx,pop,smtp',
width: '40%'
},
dnsip: {
title: 'DNS Server',
width: '20%'
},
key: {
title: 'Key',
sorting: false,
list: false,
width: '20%'
},
enable_a: {
title: 'A',
options: ['1','0'],
sorting: false,
width: '20%'
},
enable_ns: {
title: 'NS',
options: ['1','0'],
sorting: false,
width: '20%'
},
enable_url: {
title: 'URL',
options: ['1','0'],
sorting: false,
width: '20%'
},
max: {
title: 'MAX',
defaultValue: '-1',
sorting: false,
width: '20%'
}
}
});
//Load person list from server
$('#log').jtable('load');
});
and the php script:
//Open database connection
$con = mysql_connect($mysql_host,$mysql_user,$mysql_pass);
mysql_select_db($mysql_db,$con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
if (empty($_POST['search']))
{
$search = NULL;
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM domains;");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
$result = mysql_query("SELECT * FROM domains ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
}
else
{
$search = mysql_real_escape_string($_POST['search']);
$result = mysql_query("SELECT COUNT(*) AS RecordCount FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%';");
$row = mysql_fetch_array($result);
$recordCount = $row['RecordCount'];
//Get records from database
$result = mysql_query("SELECT * FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%' ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] . ";");
$_SESSION["query"] = "SELECT * FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%' ORDER BY " . $_GET["jtSorting"];
$_SESSION["contador"] = "SELECT COUNT(*) AS RecordCount FROM domains WHERE id_domain LIKE '%".$search."%' or domain LIKE '%".$search."%' or exclude LIKE '%".$search."%' or dnsip LIKE '%".$search."%'";
}
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Records'] = $rows;
$jTableResult['TotalRecordCount'] = $recordCount;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO `domains`(`id_domain`, `domain`, `exclude`, `dnsip`, `key`, `enable_a`, `enable_ns`, `enable_url`, `max`) VALUES ('', '".$_POST["domain"]."','".$_POST["exclude"]."','".$_POST["dnsip"]."','".$_POST["key"]."','".$_POST["enable_a"]."','".$_POST["enable_ns"]."','".$_POST["enable_url"]."','".$_POST["max"]."');");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM domains WHERE id_domain = last_insert_id();"); // WHERE id_domain = last_insert_id();"); // id_domain = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
}
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
$id = $_REQUEST['id_domain'];
//Update record in database
$result = mysql_query("UPDATE domains SET domain = '" . addslashes($_POST["domain"]) . "', exclude = '" . addslashes($_POST["exclude"]) . "', dnsip = '" . addslashes($_POST["dnsip"]) . "', key = '" . addslashes($_POST["key"]) . "', enable_a = '" . addslashes($_POST["enable_a"]) . "', enable_ns = '" . addslashes($_POST["enable_ns"]) . "', enable_url = '" . addslashes($_POST["enable_url"]) . "', max = '" . addslashes($_POST["max"]) . "' WHERE id_domain = $id;");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
else if($_GET["action"] == "listname")
...
after hit Update:
Response is always "ok"
i can´t catch the error ./
any help ?
Have you seen this?
updateAction: 'actions.php?action=update',
// deleteAction: 'actions.php?action=delete'
should be:
updateAction: 'actions.php?action=update'
// deleteAction: 'actions.php?action=delete'
without the comma at the end of the first line (you removed the following row so this is the last one.
Furthermore: you should consider to switch to PDO for mysql safe site.
Last but not least: you are not handling errors in the insert query. Try something like:
if(mysql_query("INSERT INTO `domains`
(`id_domain`, `domain`, `exclude`, `dnsip`, `key`, `enable_a`, `enable_ns`, `enable_url`, `max`)
VALUES
('','".$_POST["domain"]."','".$_POST["exclude"]."','".$_POST["dnsip"]."','".$_POST["key"]."','".$_POST["enable_a"]."','".$_POST["enable_ns"]."','".$_POST["enable_url"]."','".$_POST["max"]."');")){ $jTableResult['Result'] = "OK";
}else{
$jTableResult['Result'] = "KO";
}
It's hard to implement a search method in a jTable.
Codes:
generaterecords.php:
<?php
$page_title = "Generate Reports";
require_once('template/header.php');
require_once('template/navmenu.php');
require_once('template/content-top.php');
?>
<div class="filtering">
<form>
<select name="year" >
<option value="0000">Year</option>
<?php
for($i=date('Y'); $i>2012; $i--) {
echo '<option value="'.$i.'"'.'>'.$i.'</option>'."\n";
}
?>
</select>
<select name="month">
<option value="0">Month</option>
<option value="1">January</option>
<option value="2">February</option>
<option value="3">March</option>
<option value="4">April</option>
<option value="5">May</option>
<option value="6">June</option>
<option value="7">July</option>
<option value="8">August</option>
<option value="9">September</option>
<option value="10">October</option>
<option value="11">November</option>
<option value="12">December</option>
</select>
<button type="submit" id="LoadRecordsButton">Load records</button>
</form>
<div id="PeopleTableContainer" style="width: 850px;"></div>
<script type="text/javascript">
$(document).ready(function () {
//Prepare jTable
$('#PeopleTableContainer').jtable({
title: 'Payment Records',
paging: true,
pageSize: 10,
sorting: true,
defaultSorting: 'payment.paymentdate ASC',
actions: {
listAction: 'payment.php?action=list'
},
fields: {
paymentid: {
key: true,
create: false,
edit: false,
list: false
},
lname: {
title: 'Last Name',
width: '20%',
create: false,
edit: false
},
fname: {
title: 'First Name',
width: '20%',
create: false,
edit: false
},
mname: {
title: 'Middle Name',
width: '20%',
create: false,
edit: false
},
paymenttype: {
title: 'Type',
width: '20%',
create: false,
edit: false
},
paymentdate: {
title: 'Date',
width: '20%',
create: false,
edit: false
},
totalrate: {
title: 'Total Rate',
width: '20%',
create: false,
edit: false
},
paymentamt: {
title: 'Amount',
width: '20%',
create: false
},
balance: {
title: 'Balance',
width: '20%',
create: false,
edit: false
}
}
});
//Load person list from server
//$('#PeopleTableContainer').jtable('load');
//Re-load records when user click 'load records' button.
// Backup
$('#LoadRecordsButton').click(function (e) {
e.preventDefault();
$('#PeopleTableContainer').jtable('load', {
year: $('#year').val(),
month: $('#month').val()
});
});
//Load all records when page is first shown
// $('#LoadRecordsButton').click();
});
</script>
<br>
<br>
<?php
// footer
require_once('template/footer.php');
?>
payment.php:
<?php
include_once ('database_connection.php');
try
{
$con = mysql_connect("localhost","kureido","tnx4standinstillwanker");
mysql_select_db("kureido", $con);
//Getting records (listAction)
if($_GET["action"] == "list")
{
//Get record count
$offresult = mysql_query("SELECT COUNT(*) AS OLRecordCount FROM official;");
$offrow = mysql_fetch_array($offresult);
$allresult = mysql_query("SELECT COUNT(*) AS AllRecordCount FROM lodger;");
$allrow = mysql_fetch_array($allresult);
$resresult = mysql_query("SELECT COUNT(*) AS ResRecordCount FROM reservation;");
$resrow = mysql_fetch_array($resresult);
$recordCount = $allrow['AllRecordCount'] - $offrow['OLRecordCount'] - $resrow['ResRecordCount'];
$year = "";
$month = "";
if (empty($_POST['year']) && empty($_POST['month']))
$year = $month = "";
else
{
$year = $_POST['year'];
$month = $_POST['month'];
}
//Get records from database
$result = mysql_query("SELECT payment.paymentid, lodger.ssn, lodger.lname, lodger.fname, lodger.mname, payment.paymenttype, payment.paymentdate, payment.totalrate, payment.paymentamt, payment.totalrate - payment.paymentamt AS balance FROM payment, lodger WHERE lodger.ssn = payment.lodger_ssn AND YEAR(paymentdate) = '" . $_POST["year"] . "' AND MONTH(paymentdate) = '" . $_POST["month"] . "' ORDER BY " . $_GET["jtSorting"] . " LIMIT " . $_GET["jtStartIndex"] . "," . $_GET["jtPageSize"] .";");
//Add all records to an array
$rows = array();
while($row = mysql_fetch_array($result))
{
$rows[] = $row;
}
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['TotalRecordCount'] = $recordCount;
$jTableResult['Records'] = $rows;
print json_encode($jTableResult);
}
//Creating a new record (createAction)
/* else if($_GET["action"] == "create")
{
//Insert record into database
$result = mysql_query("INSERT INTO people(Name, Age, RecordDate) VALUES('" . $_POST["Name"] . "', " . $_POST["Age"] . ",now());");
//Get last inserted record (to return to jTable)
$result = mysql_query("SELECT * FROM people WHERE PersonId = LAST_INSERT_ID();");
$row = mysql_fetch_array($result);
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
$jTableResult['Record'] = $row;
print json_encode($jTableResult);
} */
//Updating a record (updateAction)
else if($_GET["action"] == "update")
{
//Update record in database
$result = mysql_query("UPDATE official SET room_code = '" . $_POST["room_code"] . "', appliancerate = '" . $_POST["appliancerate"] . "', monthlybal = '" . $_POST["monthlybal"] . "' WHERE lodger_ssn = " . $_POST["ssn"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
//Deleting a record (deleteAction)
else if($_GET["action"] == "delete")
{
//Delete from database
$result = mysql_query("DELETE FROM official WHERE lodger_ssn = " . $_POST["ssn"] . ";");
//Return result to jTable
$jTableResult = array();
$jTableResult['Result'] = "OK";
print json_encode($jTableResult);
}
else if($_GET["action"] == "view")
{
}
//Close database connection
mysql_close($con);
}
catch(Exception $ex)
{
//Return error message
$jTableResult = array();
$jTableResult['Result'] = "ERROR";
$jTableResult['Message'] = $ex->getMessage();
print json_encode($jTableResult);
}
?>
Sometimes the server returns errors. Any ideas on how to get this fixed? generaterecords.php is the client side while payment.php is the server side.
$('#LoadRecordsButton').click(function (e) {
e.preventDefault();
$('#PeopleTableContainer').jtable('load', {
year: $('#year').val(),
month: $('#month').val()
});
});
//remove your comments .. the code below is for running the function above when loadrecords button is clicked
$('#LoadRecordsButton').click();
I have two tables one for user and one for search. When I drag a search over to user it adds entire search list. How do I only insert the item dragged and not the entire search array?
THE PROBLEM IS recordsArray.
<?php
require("db.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
if ($action == "updateRecordsListings"){
$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
$query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, update query failed');
//INSERTS array item that does NOT EXIT in userTable
if (mysql_affected_rows()==0) {
$query = mysql_query("INSERT INTO records1 SELECT * FROM records WHERE recordID = " . $recordIDValue);
$query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, insert/update query failed');
}
$listingCounter = $listingCounter + 1;
}
echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>
Both list arrays id must maintain the same id names in order for the above item to acknowledge and process the list items. Keeping things simple I just used the same code for the Search, User format:
<li id="recordsArray_<?php echo $result['recordID']; ?>"><?php echo $result['recordID'] . ". " . $result['recordText']; ?></li>
Javascript:
$(function() {
$("#contentLeft ul, #main ul").sortable({ accept: '.draggable', connectWith: "#contentLeft ul", opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecordsListings';
$.post("updateDB.php", order, function(theResponse){
$("#contentRight").html(theResponse);
});
}
});
}).disableSelection();
});
How can I call only the recordsArray items from #content ul?
I can only get one insert per refresh with this but it does drag and drop insert...
Still need an if statement for possible errors because +/-1 if
<?php
require("db.php");
$action = mysql_real_escape_string($_POST['action']);
$updateRecordsArray = $_POST['recordsArray'];
$uRA = $updateRecordsArray;
// Get total number of elements in $updateRecordsArray
$ifArray = $updateRecordsArray;
$resultCount = count($ifArray);
//echo '<br />';
//print_r($resultCount);
// Get total number of rows in $records1
$recordTable = array();
$result = mysql_query("SELECT recordListingID FROM records1");
$numRows = mysql_num_rows($result);
while ($row = mysql_fetch_assoc($result)) {
$recordTable = array_merge($recordTable, array_map('trim', explode(",", $row['recordListingID'])));
}
//Gets $id/$val of elements not in both arrays
$results = array_diff($uRA, $recordTable);
//echo '<br />';
//print_r($numRows);
//Give variables for +/- 1 $numRows
$plusNumRows = $numRows + 1;
$minusNumRows = $numRows - 1;
//echo '<br />';
//print_r($minusNumRows);
// Normal jQuery drag and drop ranking found online
if ($action == "updateRecordsListings"){
$listingCounter = 1;
foreach ($updateRecordsArray as $recordIDValue) {
//If statement for for +/- 1 $numRows
If ($resultCount == $numRows -1 || $resultCount == $numRows || $resultCount == $numRows + 1){
$sql = mysql_query("INSERT INTO records1 SELECT * FROM records WHERE recordID = $recordIDValue");
}
$query = "UPDATE records1 SET recordListingID = " . $listingCounter . " WHERE recordID = " . $recordIDValue;
mysql_query($query) or die('Error, update query failed');
$listingCounter = $listingCounter + 1;
}
echo '<pre>';
print_r($updateRecordsArray);
echo '</pre>';
echo 'If you refresh the page, you will see that records will stay just as you modified.';
}
?>
public function GetRoomTotalForDay($room, $date = null) {
if(!isset($date)) {
$date = date("Y-m-d");
}
// This function is going to return the number of shoes processed that day
// First of all work out which scanner number is required for the room
$scanner = $this->GetScannerNumber($room);
// Next generate the SQL
$sql = "SELECT `scanners.KordNo`, `scanners.BundleNumber`
FROM `scanners`
WHERE `scanners.Date` = '" . $date . "'
AND `scanners.Scanner` IN (";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0);";
// And query the database
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$return[] = $row;
}
// It is more complicated for Kettering, Closing & Rushden, we need to filter the list
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanner.BundleNumber'] . "
ORDER BY `scanners.Date` DESC
LIMIT 1,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
// If scanner 7, it's been through bottom stock so need to find previous
if($row[0] == 7) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanners.BundleNumber'] . "
ORDER BY `scanners.Date` DESC
LIMIT 2,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
if($row[0] == 10 && $room == 3) {
$finalReturn[] = $x;
} elseif($row[0] == 11 && $room == 4) {
$finalReturn[] = $x;
} elseif($row[0] == 15 && $room == 5) {
$finalReturn[] = $x;
}
}
$return = $finalReturn;
}
// Now we have a list of tickets, we need to query how many pairs are in each ticket
$total = 0;
foreach($return as $x) {
$sql = "SELECT `QtyIssued`
FROM `ArchiveBundle`
WHERE `ArchiveBundle.KordNo` = '" . $x['scanners.KordNo'] . "'
AND `ArchiveBundle.BundleNumber` = '" . $x['scanners.BundleNumber'] . "';";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$total += $row[0];
}
return $total;
}
I have edited the class above which pulls no results. However the original class below pulls results out. Please can someone help.
public function GetRoomTotalForDay($room, $date = null) {
if(!isset($date)) {
$date = date("Y-m-d");
}
// This function is going to return the number of shoes processed that day
// First of all work out which scanner number is required for the room
$scanner = $this->GetScannerNumber($room);
// Next generate the SQL
$sql = "SELECT `KordNo`, `BundleNumber`
FROM `scanners`
WHERE `Date` = '" . $date . "'
AND `Scanner` IN (";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0);";
// And query the database
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$return[] = $row;
}
// It is more complicated for Kettering, Closing & Rushden, we need to filter the list
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `Scanner`
FROM `scanners`
WHERE `KordNo` = " . $x['KordNo'] . "
AND `BundleNumber` = " . $x['BundleNumber'] . "
ORDER BY `Date` DESC
LIMIT 1,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
// If scanner 7, it's been through bottom stock so need to find previous
if($row[0] == 7) {
$sql = "SELECT `Scanner`
FROM `scanners`
WHERE `KordNo` = " . $x['KordNo'] . "
AND `BundleNumber` = " . $x['BundleNumber'] . "
ORDER BY `Date` DESC
LIMIT 2,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
if($row[0] == 10 && $room == 3) {
$finalReturn[] = $x;
} elseif($row[0] == 11 && $room == 4) {
$finalReturn[] = $x;
} elseif($row[0] == 15 && $room == 5) {
$finalReturn[] = $x;
}
}
$return = $finalReturn;
}
// Now we have a list of tickets, we need to query how many pairs are in each ticket
$total = 0;
foreach($return as $x) {
$sql = "SELECT `QtyIssued`
FROM `ArchiveBundle`
WHERE `KordNo` = '" . $x['KordNo'] . "'
AND `BundleNumber` = '" . $x['BundleNumber'] . "';";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$total += $row[0];
}
return $total;
}
The class above counts the amount of shoes produced. I have had to edit this class so it can exclude certain types of shoes but it does not seem to pull any results for some reason.
UPDATE.
This is the class scanners. This is what its currently at the moment. I'm fairly new to php and this code was writted by my predecessor.
<?php
class CHScanners {
var $conn;
// Constructor, connect to the database
public function __construct() {
require_once "/var/www/reporting/settings.php";
define("DAY", 86400);
if(!$this->conn = mysql_connect(DB_HOST, DB_USERNAME, DB_PASSWORD)) die(mysql_error());
if(!mysql_select_db(DB_DATABASE_NAME, $this->conn)) die(mysql_error());
}
public function ListRoomBundles($room, $date, $dateTo = null) {
// If dateTo hasn't been set, make it now
if(!isset($dateTo) or $dateTo == "") {
$dateTo = $date;
}
// Return an array with each bundle number and the quantity for each day
$scanner = $this->GetScannerNumber($room);
$sql = "SELECT * FROM `scanners` WHERE `Scanner` IN (";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0)
AND `Date` BETWEEN '" . $date . "' AND '" . $dateTo . "'
GROUP BY `KordNo`, `BundleNumber`;";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$sql = "SELECT `BundleReference`, `QtyIssued`, `WorksOrder`
FROM `ArchiveBundle`
WHERE `KordNo` = '" . $row['KordNo'] . "'
AND `BundleNumber` = '" . $row['BundleNumber'] . "';";
$result2 = mysql_query($sql);
while($row = mysql_fetch_array($result2)) {
if($row[0] != "") {
$final[] = $row;
} else {
$final[] = array("Can't find bundle number", "N/A");
}
}
}
return $final;
}
public function GetRoomTotalForDay($room, $date = null) {
if(!isset($date)) {
$date = date("Y-m-d");
}
// This function is going to return the number of shoes processed that day
// First of all work out which scanner number is required for the room
$scanner = $this->GetScannerNumber($room);
// Next generate the SQL
$sql = "SELECT `scanners.KordNo`, `scanners.BundleNumber`
FROM `scanners,TWOrder,Stock`
INNER JOIN TWORDER ON `scanners.KordNo` = `TWOrder.KOrdNo`
AND `scanners.Date` = '" . $date . "'
INNER JOIN Stock ON `TWOrder.Product` = `Stock.ProductCode`
AND `Stock.ProductGroup` NOT BETWEEN 400 AND 650
AND `scanners.Scanner` IN (
ORDER BY `scanners.KordNo' ASC";
foreach($scanner as $x) {
$sql .= $x . ",";
}
$sql .= "0);";
// And query the database
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)) {
$return[] = $row;
}
// It is more complicated for Kettering, Closing & Rushden, we need to filter the list
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanners.BundleNumber'] . "
ORDER BY `scanners.Date` DESC
LIMIT 1,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
// If scanner 7, it's been through bottom stock so need to find previous
if($row[0] == 7) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanners.BundleNumber'] . "
ORDER BY `Date` DESC
LIMIT 2,1;";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
}
if($row[0] == 10 && $room == 3) {
$finalReturn[] = $x;
} elseif($row[0] == 11 && $room == 4) {
$finalReturn[] = $x;
} elseif($row[0] == 15 && $room == 5) {
$finalReturn[] = $x;
}
}
$return = $finalReturn;
}
// Now we have a list of tickets, we need to query how many pairs are in each ticket
$total = 0;
foreach($return as $x) {
$sql = "SELECT `QtyIssued`
FROM `ArchiveBundle`
WHERE `KordNo` = '" . $x['scanners.KordNo'] . "'
AND `BundleNumber` = '" . $x['scanners.BundleNumber'] . "';";
$result = mysql_query($sql);
$row = mysql_fetch_row($result);
$total += $row[0];
}
return $total;
}
// We need a function to select the previous Monday from a given date
public function GetPreviousMonday($timestamp) {
if(date("N", $timestamp) == 1) {
return $timestamp;
} elseif(in_array(date("N", $timestamp), array(2, 3, 4, 5))) {
return $timestamp - (date("N", $timestamp)-1)*DAY;
} elseif(in_array(date("N", $timestamp), array(6, 7))) {
return $timestamp + (date("N", $timestamp)*(-1)+8)*DAY;
} else {
return false;
}
}
public function GetRoomName($room) {
// Return the room name from the room number
switch($room) {
case 1:
return "Skin Room";
case 2:
return "Clicking Room";
case 3:
return "Kettering";
case 4:
return "Closing Room";
case 5:
return "Rushden";
case 6:
return "Assembly Room";
case 7:
return "Lasting Room";
case 8:
return "Making Room";
case 9:
return "Finishing Room";
case 10:
return "Shoe Room";
}
}
public function GetDueDateForWorksOrder($worksOrderNumber) {
$sql = "SELECT `DueDate`
FROM `TWOrder`
WHERE `WorksOrderNumber` = '" . $worksOrderNumber . "';";
mysql_select_db(DB_DATABASE_NAME, $this->conn);
$result = mysql_query($sql, $this->conn);
$row = mysql_fetch_row($result);
return $row[0];
}
private function GetScannerNumber($room) {
// Get the room number from the scanner number
switch($room) {
case 1:
$scanner = array(3);
break;
case 2:
$scanner = array(10,11,15);
break;
case 3:
$scanner = array(5);
break;
case 4:
$scanner = array(5);
break;
case 5:
$scanner = array(5);
break;
case 6:
$scanner = array(6);
break;
case 7:
$scanner = array(9);
break;
case 8:
$scanner = array(8);
break;
case 9:
$scanner = array(12);
break;
case 10:
$scanner = array(14);
break;
default:
$scanner = array(0);
break;
}
return $scanner;
}
}
?>
You have a typo - a letter is missing in the last line of this block of code:
if(in_array($room, array(3,4,5))) {
foreach($return as $x) {
$sql = "SELECT `scanners.Scanner`
FROM `scanners`
WHERE `scanners.KordNo` = " . $x['scanners.KordNo'] . "
AND `scanners.BundleNumber` = " . $x['scanner.BundleNumber'] .
Here the array item should be $x['scanners.BundleNumber'].