0

I want to make an attendance sheet with jqGrid. I'm using PHP and Mysql

I have two tables, one called MemberInfo and one called Attendance.

From the MemberInfo I want to show in the grid the first name and the last name of the member. Then I want to have a box for every day of the week. I want that when I add some data to those fields, for the data to be saved in the Attendance table and also that if I generate the Attendance grid again, the fields that were already filled up, to show the data.

My question is: How can I add more columns and How can I connect those columns with the Attendance table? Thanks!

EDIT:

I was able to generate new columns and to add the data to the database with cellEdit. Still having problems with generating the grid with the data from 2 tables. Thanks!

I hope this is clear! if its not please let me know! thanks!

(if there is another library for PHP that would make this easier please let me know) EDIT:

<?php
require_once 'jqgrid/jq-config.php';
// include the jqGrid Class
require_once "jqgrid/php/jqGrid.php";
// include the driver class
require_once "jqgrid/php/jqGridPdo.php";
// Connection to the server
$conn = new PDO("mysql:host=localhost;dbname=db;","root",NULL);
// Tell the db that we use utf-8
$conn->query("SET NAMES utf8");

// Create the jqGrid instance
$grid = new jqGridRender($conn);
// Write the SQL Query
$grid->SelectCommand = 'SELECT member_id,  first_name, last_name FROM members_info WHERE member_type !=5';
// set the ouput format to json
$grid->dataType = 'json';
$grid->table ="members_info";
$grid->setPrimaryKeyId("member_id");
// Let the grid create the model

$grid->setColModel();
// Set the url from where we obtain the data
$grid->setUrl('grid.php');
$grid->cacheCount = true;

// Set grid caption using the option caption
$today = date('Y-m-d');

                    if(isset($_POST['past_month'])){
                        $today = date('Y-m-d', strtotime($_POST['past_month']));
                    }

                    if(isset($_POST['next_month'])){
                        $today = date('Y-m-d', strtotime($_POST['next_month']));
                    }
$days = attendance_cal(date('F', strtotime($today)), date('Y', strtotime($today)));  // Gets the days for that month and that year

sort($days); //sort the days

foreach($days as $day){

    $grid->addCol(array(
"name"=>date('m-d', $day)
));

}

$grid->setGridOptions(array(
    "caption"=>"This is custom Caption",
    "rowNum"=>30000,
    "sortname"=>"member_id",
    "hoverrows"=>true,
    "width"=>1000,
    "height"=>1000,
    "cellEdit"=> true,
    "cellsubmit"=>"remote",
    "cellurl"=> "cell_dump.php",
    "rowList"=>array(10,20,50),
    "postData"=>array("grid_recs"=>776)
    ));


// Change some property of the field(s)
$grid->setColProperty("member_id", array("label"=>"ID", "width"=>60, "editable"=>false));
$grid->setColProperty("first_name", array("label"=>"First Name", "width"=>120, "editable"=>false));
$grid->setColProperty("last_name", array("label"=>"Last Name", "width"=>120, "editable"=>false));


// Enjoy
$grid->navigator = false;


// and finaly bind key navigation
// This is way if no events or parameter
//$grid->callGridMethod('#grid', 'bindKeys');
//
//in case of passing events is better this way

$bindkeys =<<<KEYS
$("#grid").jqGrid('bindKeys', {"onEnter":function( rowid ) { alert("You enter a row with id:"+rowid)} } );
KEYS;

$grid->setJSCode($bindkeys);



$grid->renderGrid('#grid','#pager',true, null, null, true,true);
$conn = null;

?>

Let me be more specific:

My table "Members" has the fields "member_id", "first_name", "last_name"

The "Attendance" table has the fields "attendance_id", "member_id", "attendance_date" ,"attendance_value"

My Grid, I want it to look like:

| Member Id | Name | 03-15-2012 | 03-20-2012 | 03-22-2012 |

The "Member Id" column and "Name" column is being generated from the "Members" table with the SelectCommand, the other columns I'm creating them with addCol. I kinda can figure out how to add data to the database via cellEdit, but when I load the sheet, I dont know how to put the data from the database in the grid besides for the ones coming from the Members table. I hope this is clearer! thanks!

raygo
  • 1,348
  • 5
  • 18
  • 40
  • Sorry, but all what you wrote sound more like technical requirement and not as a question. What is your question? (see [FAQ](http://stackoverflow.com/faq)) – Oleg Mar 15 '12 at 21:31
  • How can I add more columns and How can I connect those columns with the Attendance table? Thanks! – raygo Mar 15 '12 at 21:33
  • downvote: please do your homework first. we're here to help you once you've learned the fundamentals first – Walter Stabosz Mar 16 '12 at 14:14
  • I think I kinda did it. I put my code up – raygo Mar 16 '12 at 20:10

1 Answers1

1

I am assuming you have never used jqGrid and you need to get started...

Please have a look at this link, it gives you demos with code for everything you need to know on how to create your grid using PHP.

http://www.trirand.net/demophp.aspx

c0deNinja
  • 3,956
  • 1
  • 29
  • 45
  • Yes, I was checking there but couldn't find what I want to do. I have the jqgrid running getting data from one of my tables. The second part is the problem, to auto generate the columns and to connect them to the database. – raygo Mar 15 '12 at 21:36
  • @raygo: Read [the answer](http://stackoverflow.com/a/2295093/315935) for example about generate the columns dynamically. – Oleg Mar 15 '12 at 21:56
  • Hi! I guess it's because I'm very new with jquery that I dont really understand the example – raygo Mar 16 '12 at 00:12