Added Editablegrid to an exsisting php project. When logged in as admin the member can edit the grid and the dropdown fields show the value . but when log out and an normal user views the page (non editable). the php-Mysql display show the ID # where the value should be . how to get grid to save the value not the ID in mysql from a dropdown menu?
This is the Grid showing the value
the loaddata code
<?php
session_start();
/*
* examples/mysql/loaddata.php
*
* This file is part of EditableGrid.
* http://editablegrid.net
*
* Copyright (c) 2011 Webismymind SPRL
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://editablegrid.net/license
*/
/**
* This script loads data from the database and returns it to the js
*
*/
require_once('config.php');
require_once('EditableGrid.php');
/**
* fetch_pairs is a simple method that transforms a mysqli_result object in an array.
* It will be used to generate possible values for some columns.
*/
function fetch_pairs($mysqli,$query){
if (!($res = $mysqli->query($query)))return false;
$rows = array();
while ($row = $res->fetch_assoc()) {
$first = true;
$key = $value = null;
foreach ($row as $val) {
if ($first) { $key = $val; $first = false; }
else { $value = $val; break; }
}
$rows[$key] = $value;
}
return $rows;
}
// 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
*/
$grid->addColumn('asset_hardware_id', 'ID', 'integer', NULL, false);
$grid->addColumn('location', 'Location', 'string', fetch_pairs($mysqli,'SELECT id, location FROM location'),true);
$grid->addColumn('cube', 'Room', 'string');
$grid->addColumn('asset_type', 'Type', 'string', fetch_pairs($mysqli,'SELECT id, assets_hardware_type FROM assets_hardware_type'),true);
$grid->addColumn('vendor', 'Vendor', 'string', fetch_pairs($mysqli,'SELECT vendor_id, vendor FROM vendors'),true );
$grid->addColumn('model', 'Model', 'string');
$grid->addColumn('asset_tag', 'Asset Tag', 'string');
$grid->addColumn('serialnumber', 'Serial Number', 'string');
$grid->addColumn('delltag', 'Dell Tag', 'string');
$grid->addColumn('user', 'Name', 'string');
$grid->addColumn('physically_inventoried', 'Inv?', 'boolean');
$mydb_tablename = (isset($_GET['db_tablename'])) ? stripslashes($_GET['db_tablename']) : 'assets_hardware';
$result = $mysqli->query("SELECT * FROM ".$mydb_tablename. " WHERE location = '". $_SESSION['loc'] ."' and cube = '". $_SESSION['room'] ."'");
$mysqli->close();
// send data to the browser
$grid->renderJSON($result);
this is the PHP website output after using the editablegrid dropdown.
Added Editablegrid to an exsisting php project. When logged in as admin the member can edit the grid and the dropdown fields show the value . but when log out and an normal user views the page (non editable). the php-Mysql display show the ID # where the value should be . how to get grid to save the value not the ID in mysql from a dropdown menu?
This is the Grid showing the value
the loaddata code
this is the PHP website output after using the editablegrid dropdown.