public function getGridForTable($table, $columns, $showdelete) { global $CFG; // Database connection $conn = mysqli_connect($CFG->db, $CFG->dbuser, $CFG->dbuserpass, $CFG->schema) or die("<data><error>cannot select {$CFG->schema}</error><detail>" . mysqli_error($conn) . "</detail></data>"); // build a mapping of the table for comparison $query = "SHOW COLUMNS FROM `{$table}`"; $result = mysqli_query($conn, $query) or die("<data><error>cannot show columns from records, query was {$query}</error><detail>" . mysqli_error($conn) . "</detail></data>"); $rawfieldsmap = array(); // build a map of existing fields while ($row = mysqli_fetch_array($result)) { $rawfieldsmap[] = $row['Field'] . ',' . $row['Type']; } $result = mysqli_query($conn, "SELECT * FROM {$table} WHERE `editable` = 'true' AND COALESCE (`deleted`, '') <> 'true' ORDER BY ID DESC"); // create a new EditableGrid object $grid = new EditableGrid(); // get the columns $columnsArr = explode(',', $columns); // print_r($columnsArr); /* * Add columns. The first argument of addColumn is the name of the field in the databse. * The second argument is the label that will be displayed in the header */ $grid->addColumn('ID', 'ID', 'integer', NULL, false); foreach ($columnsArr as $column) { foreach ($rawfieldsmap as $fieldsmapelement) { $fieldsmapelementArr = explode(',', $fieldsmapelement); if ($column == $fieldsmapelementArr[0]) { if (stripos($fieldsmapelementArr[0], "int") !== false) { $grid->addColumn($column, $column, 'integer'); } else { $grid->addColumn($column, $column, 'string'); } } } } if ($showdelete) { $grid->addColumn("Delete", 'Delete', 'string', NULL, false); } // send data to the browser return $grid->renderXML($result); }
$grid->addColumn("name", "NAME", "string"); $grid->addColumn("firstname", "FIRSTNAME", "string"); // add an "integer" and a "double" column // you can specifiy the unit: double(m), the precision: double(2), or both: double(m,2) // these will be used in the default renderer NumberCellRenderer $grid->addColumn("age", "AGE", "integer"); $grid->addColumn("height", "HEIGHT", "double(m,2)", null, true, null, false); // add column with predefined values, organized in "option groups" (dropdown list) $grid->addColumn("country", "COUNTRY", "string", array("Europe" => array("be" => "Belgium", "fr" => "France", "uk" => "Great-Britain", "nl" => "Nederland"), "America" => array("br" => "Brazil", "ca" => "Canada", "us" => "USA"), "Africa" => array("ng" => "Nigeria", "za" => "South-Africa", "zw" => "Zimbabwe"))); // add some other columns: email, url, boolean, date $grid->addColumn("email", "EMAIL", "email"); // $grid->addColumn("website", "WEBSITE", "url"); $grid->addColumn("freelance", "FREELANCE", "boolean"); $grid->addColumn("lastvisit", "LAST VISIT", "date"); // action column ("html" type), not editable $grid->addColumn("action", "", "html", NULL, false); // load data from csv $handle = fopen("demo.csv", "r"); $data = array(); while ($row = fgetcsv($handle, 0, ";")) { if (count($row) <= 1 || $row[0] == 'id') { continue; } $data[] = array("id" => $row[0], "name" => $row[1], "firstname" => $row[2], "age" => $row[3], "height" => $row[4], "continent" => $row[5], "country" => $row[6], "email" => str_replace("*****@*****.**", "Nam@quisdiamluctus." . (isset($_GET['json']) ? "json" : "xml") . ".php.org", $row[7]), "freelance" => $row[8] == '1', "lastvisit" => $row[9], "website" => $row[10]); } // render XML or JSON if (isset($_GET['json'])) { $grid->renderJSON($data); } else { $grid->renderXML($data); }
echo "Error in " . $sql . " (" . $mysqliDB->errorCode() . ")"; die; } $pilotos = $resultado->fetchAll(PDO::FETCH_ASSOC); $resultados = array(); foreach ($pilotos as $piloto) { $row = array(); $row['id'] = $piloto['PilotNo'] . ":" . $concurso; $row['Dorsal'] = sprintf("%02d", $piloto['StartNo']); $row['Piloto'] = $piloto['LastName'] . ', ' . $piloto['FirstName']; $sql = "SELECT `RoundNo`, `Time1Mins`,`Landing`, `FlightScoreDeduction`, `Penalty` FROM scores where CompNo=" . $concurso . " and PilotNo = " . $piloto['PilotNo']; $resultado = $mysqliDB->query($sql); if (!$resultado) { echo "Error in " . $sql . " (" . $mysqliDB->errorCode() . ")"; die; } $vuelos = $resultado->fetchAll(PDO::FETCH_ASSOC); $v = 1; foreach ($vuelos as $vuelo) { $row['Time1Mins' . $v] = $vuelo['Time1Mins']; $row['Landing' . $v] = $vuelo['Landing']; $row['FlightScoreDeduction' . $v] = $vuelo['FlightScoreDeduction']; $row['Penalty' . $v] = $vuelo['Penalty']; $v++; } array_push($resultados, $row); } } // send data to the browser $grid->renderXML($resultados);
$targetPageSwitch = $_SESSION['targetPageSwitch']; $targetSemesterWeek = $_SESSION['targetSemesterWeek']; // Database connection $mysqli = mysqli_init(); $mysqli->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5); $mysqli->real_connect($config['db_host'], $config['db_user'], $config['db_password'], $config['db_name']); // create a new EditableGrid object $grid = new EditableGrid(); /* * Add columns. The first argument of addColumn is the name of the field in the databse. * The second argument is the label that will be displayed in the header * The third argument is the display type of grid */ foreach ($GRID_KEY_NAMES_ARRAY[$targetPageSwitch] as $key => $value) { if ($key == 'id') { $grid->addColumn('id', 'ID', 'integer', NULL, false); continue; } $grid->addColumn($key, $value, 'string'); } //Create the SQL Syntax. if ($targetPageSwitch != $COURSE_PERIOD_PAGE_SWITCH && $targetPageSwitch != $WEEKS_SCHEDULE_PAGE_SWITCH) { $sqlSelectSyntax = "SELECT * FROM {$targetDatabaseTableName} WHERE SEMESTER_WEEK = {$targetSemesterWeek}"; } else { $sqlSelectSyntax = "SELECT * FROM {$targetDatabaseTableName}"; } $result = $mysqli->query($sqlSelectSyntax); $mysqli->close(); // send data to the browser $grid->renderXML($result);