jQuery UI Widgets › Forums › Grid › Working script fails under PHP: 5.4.45 + MySQL: 5.7.12
Tagged: angular grid, grid, jquery grid, jqxgrid, mysql, mysqli, no data to to display, php, PHP integration
This topic contains 4 replies, has 2 voices, and was last updated by Dimitar 8 years, 3 months ago.
-
Author
-
I use grid forms, created in jQWidgets as add-on for our Moodle.
(it works, my only wish in the grid is that the calculated columns contacthours and workload are showing that you cannot edit them “dimmed” ?)Now my problem
it works here:
Moodle Version: 2.6.11+ (2013111811.01)
PHP: 5.3.13
MySQL: 5.1.57
jQWidgets 1.11.1.min.jsBut here I get in the grid the message “no data to to display”
Moodle Version: 3.1+ (2016052300.01)
PHP: 5.4.45
MySQL: 5.7.12
jQWidgets 1.11.1.min.jsWhat should I change to get it working again? is it PHP or is it mySQL (mySQLi ?)
These are the files.
First datastudyloud2.php:
<?php
include(‘connect.php’);
include (‘../../config.php’);
$module_id = optional_param(‘module_id’,0, PARAM_INT);
$connect = mysql_connect($hostname, $username, $password)
or die(‘Could not connect: ‘ . mysql_error());
$bool = mysql_select_db($database, $connect);
if ($bool === False){
print “can’t find $database”;
}
$query = “SELECT * FROM mdl_handbook_studyload where module_id=”.$module_id.” ORDER BY rank ASC”;
if (isset($_GET[‘update’]))
{
$update_query = “UPDATEmdl_handbook_studyload
SET
rank
='”.mysql_real_escape_string($_GET[‘rank’ ]).”‘,
visual_nr
='”.mysql_real_escape_string($_GET[‘visual_nr’ ]).”‘,
topic_name
='”.mysql_real_escape_string($_GET[‘topic_name’ ]).”‘,
lecture
='”.mysql_real_escape_string($_GET[‘lecture’ ]).”‘,
exercise
='”.mysql_real_escape_string($_GET[‘exercise’ ]).”‘,
workshop
='”.mysql_real_escape_string($_GET[‘workshop’ ]).”‘,
labwork
='”.mysql_real_escape_string($_GET[‘labwork’ ]).”‘,
fieldwork
='”.mysql_real_escape_string($_GET[‘fieldwork’ ]).”‘,
design
='”.mysql_real_escape_string($_GET[‘design’ ]).”‘,
lecturer
='”.mysql_real_escape_string($_GET[‘lecturer’ ]).”‘
WHERErank
='”.mysql_real_escape_string($_GET[‘rank’]).”‘
AND module_id=”.$module_id.””;$result = mysql_query($update_query) or die(“SQL Error 1: ” . mysql_error());
echo $result;
}
else
{
$result = mysql_query($query) or die(“SQL Error 1: ” . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
$request_form[] = array(
‘rank’ => $row[‘rank’],
‘visual_nr’ => $row[‘visual_nr’],
‘topic_name’ => $row[‘topic_name’],
‘lecture’ => $row[‘lecture’],
‘exercise’ => $row[‘exercise’],
‘workshop’ => $row[‘workshop’],
‘labwork’ => $row[‘labwork’],
‘fieldwork’ => $row[‘fieldwork’],
‘design’ => $row[‘design’],
‘contacthrs’ => $row[‘lecture’] + $row[‘workshop’] + $row[‘labwork’] + $row[‘fieldwork’] + $row[‘design’],
‘studyloadhrs’ => $row[‘lecture’]*3 + $row[‘exercise’] + $row[‘workshop’]+ $row[‘labwork’]*2 + $row[‘fieldwork’] + $row[‘design’]*3 ,
‘lecturer’ => $row[‘lecturer’]
);
}
echo json_encode($request_form);
}
?>And next the edit.php script:
<?php
require_once(‘../../config.php’);
include (“lib_calls2.php”);
require_login();
$module_id = required_param(‘module_id’, PARAM_INT);?>
<!DOCTYPE html>
<html lang=”en”>
<head>
<title id=’Description’>Contact Hours and Workload Hours form</title>
<link rel=”stylesheet” href=”./jqwidgets/styles/jqx.energyblue.css” type=”text/css” />
<script type=”text/javascript”>
$(document).ready(function () {
var data = {};
var theme = ‘energyblue’;
var source =
{
datatype: “json”,
datafields: [
//{ name: ‘module_id’, type: ‘number’ },
//{ name: ‘rank’, type: ‘number’ },
{ name: ‘visual_nr’, type: ‘string’ },
{ name: ‘topic_name’, type: ‘string’ },
{ name: ‘lecture’, type: ‘number’ },
{ name: ‘exercise’, type: ‘number’ },
{ name: ‘workshop’, type: ‘number’ },
{ name: ‘labwork’, type: ‘number’ },
{ name: ‘fieldwork’, type: ‘number’ },
{ name: ‘design’, type: ‘number’ },
{ name: ‘contacthrs’, type: ‘number’ },
{ name: ‘studyloadhrs’, type: ‘number’ },
{ name: ‘lecturer’, type: ‘string’ }
],
cache: false,
id: ‘id’,
url: ‘data_studyload2.php?module_id=<?php echo($module_id);?>’,
updaterow: function (rowid, rowdata, commit) {
// synchronize with the server – send update command
var data = “update=true”
//+ “&module_id=” + rowdata.module_id
//+ “&rank=” + rowdata.rank
+ “&visual_nr=” + rowdata.visual_nr
+ “&topic_name=” + rowdata.topic_name
+ “&lecture=” + rowdata.lecture
+ “&exercise=” + rowdata.exercise
+ “&workshop=” + rowdata.workshop
+ “&labwork=” + rowdata.labwork
+ “&fieldwork=” + rowdata.fieldwork
+ “&design=” + rowdata.design
+ “&lecturer=” + rowdata.lecturer
;
$.ajax({
dataType: ‘json’,
url: ‘data_studyload.php?module_id=<?php echo($module_id);?>’,
data: data,
success: function (data, status, xhr) {
// update command is executed.
commit(true);
}
});
}
};var dataAdapter = new $.jqx.dataAdapter(source);
$(“#jqxgrid”).jqxGrid(
{
theme: ‘energyblue’,
source: dataAdapter,
width: 1146,
height: 479,
sortable: false,
altrows: true,
showstatusbar: true,
statusbarheight: 25,
showaggregates: true,
editable: true,
autorowheight: true,
autoheight: true,
selectionmode: ‘singlecell’,
columns: [
// { text: ‘module_id’, datafield: ‘module_id’, width: 40},
// { text: ‘rank’, datafield: ‘rank’, width: 40},
{ text: ‘#.#’, datafield: ‘visual_nr’, width: 45},
{ text: ‘topic_name’, datafield: ‘topic_name’, width:336},
{ text: ‘lecture’, datafield: ‘lecture’, width: 58, aggregates: [‘sum’]},
{ text: ‘assignment’, datafield: ‘exercise’, width: 85, aggregates: [‘sum’]},
{ text: ‘workshop’, datafield: ‘workshop’, width: 70, aggregates: [‘sum’]},
{ text: ‘labwork’, datafield: ‘labwork’, width: 65, aggregates: [‘sum’]},
{ text: ‘fieldwork’, datafield: ‘fieldwork’, width: 70, aggregates: [‘sum’]},
{ text: ‘design’, datafield: ‘design’, width: 60, aggregates: [‘sum’]},
{ text: ‘contacthrs’, datafield: ‘contacthrs’, width: 75, aggregates: [‘sum’]},
{ text: ‘workload’, datafield: ‘studyloadhrs’, width: 70, aggregates: [‘sum’]},
{ text: ‘lecturer’, datafield: ‘lecturer’, width: 222}
]
});
});
</script>
</head>
<body class=”default” bgcolor=”#EDF2F4″>
<div id=”jqxgrid”></div>
</div>
</body>
</html>Sorry, correction: I am using jQWidgets v4.1.2 (2016-Apr)
I meant using JQuery 1.11.1.min.js
By the way, using JQuery 1.12.4.min.js or jQuery 3.0.0.min.js didn’t solbe the problem either.
Any hep nwelcome.
regards, Ger
Hello Ger,
Please share if there are any errors thrown in your browser’s console. Please also note that we have several PHP integration help topics that can be found in the PHP Integration section of the documentation.
As for applying a “dimmed” effect to grid cells – this can be achieved by using cellsrenderer, as in the following demo: http://www.jqwidgets.com/jquery-widgets-demo/demos/jqxgrid/disableeditingofrows.htm?light.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/Hi Dimitar, the point is that I do not get an error but an empty grid.
Thanks for the dim reference, it works great on the old server after a change to select the columns:
var cellbeginedit = function (row, datafield, columntype, value) {
if (datafield == ‘contacthrs’ || datafield == ‘studyloadhrs’ ) return false;
}var cellsrenderer = function (row, datafield, value, defaultHtml) {
if (datafield == ‘contacthrs’ || datafield == ‘studyloadhrs’ ) {
var element = $(defaultHtml);
element.css(‘color’, ‘lightblue’);
return element[0].outerHTML;
}return defaultHtml;
}Hi Ger,
You can check if data is retrieved from the database at all in the data adapter’s loadComplete callback function. More information about it can be found in the jqxDataAdapter help topic. If no records are loaded, this might mean that the issue originates on your server side.
Best Regards,
DimitarjQWidgets team
http://www.jqwidgets.com/ -
AuthorPosts
You must be logged in to reply to this topic.