Building Administrator Manager for Table Relation Using PHP and jQuery

Hello my friends, this tutorial will explain about how to building complete Administrator Manager, Using PHP and jQuery. At the begining of tutorial you will explained about designing interface for our Administrator Page, then will continue with steps about how to make it as ready application.
Well, actually I don’t know how to create good tutorial, but I feel, I must share this tutorial. Based on my recent project last month, this tutorial will guide you to be a webmaster. I am sure, you know about what is webmaster 🙂 Because in this tutorial you will see technic from first designing till hand code your application. Enjoy it friends !

On this tutorial, we need several important thing to complete our work today 🙂
Designing and layout

  1. Adobe Photoshop
  2. Adobe Dreamweaver

Programming

  1. PHP
  2. HTML + CSS
  3. Javascript
  4. jQuery
  5. jQuery ThickBox Plugin
  6. jQuery HighlightFade Plugin
  7. MySQL Server
  8. Apache Server
  9. phpMyAdmin

So, just start from First Step: Designing

Step 1 » Designing

Start with your new document of Adobe Photoshop. You may use free size for new document.
Use your shapping tool to grab a new rounded rectangle. Remember that this is for your header of Administrator Page.

Add simple inner glow, gradient style and stroke for your header

And the result is….

Add your title at front of header layer. To make it better, I use small icon from crystalxp.net for the logo

Next, Create several rectangle at the bottom of header for a little bit welcome text and menus. To make it beautifull menu, I use two icon again.

Grab new rectangle again for your main content, feel free to add some style. For nice design, you may create the other amazing styles.

Well, your basic layout has done! It’s time to illustrate the form for your application. In this case, I will show about illustrate edit form page as a part of your hand code at the next step.
Grab some label and rectangle. For the button, I use simple reflection effect by duplicate button layer and transform it vertical then erase half of button layer copy. So you will see a simple reflection for your button.

To manage relation data at the future, add some icon that will used for manage relation data

Enough! 🙂 now you may slice your design to save it as image. Be carefull, slice for needed area only.

This is screen shoot of my setting of Save For Web Window

Save only selected sliced

The result of images

Step 2 » Converting from PSD Design to HTML and CSS

This step will show to you about how to convert our previous psd design to hand code of HTML and CSS. Let’s open your Adobe Dreamweaver to begin!
In this part, we need two main file, consist of HTML and CSS file.
Create new CSS Document, with this simple hand code:

@charset "utf-8";
/* CSS Document */
html,body{
margin:0;
padding:0;
border:0;
height:100%;
}
body{
background:#ffffff;
color:#2a2a2a;
min-width:697px;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
a:link {
color: #99CC00;
text-decoration: none;
}
a:visited {
text-decoration: none;
color: #99CC00;
}
a:hover {
text-decoration: underline;
color: #FF9900;
}
a:active {
text-decoration: none;
color: #FF9900;
}
#ajax_display {
position: fixed; top: 49%; left: 35%; border:0px; z-index: 50; width: 110px; height: 100px; margin: auto 0;
}
#mainPan {
width:697px;
position:relative;
margin:0 auto;
}
#bodyPan {
width:697px;
margin:0 auto;
}
.clear {
clear:both;
height:1px;
overflow:hidden;
line-height:1%;
font-size:0px;
margin-bottom:-1px;
}
.spacer { margin-bottom:10px; }
/*HEADER*/
#header {
margin-top: 10px;
height: 54px;
width: 697px;
background:url(images/header.gif) 0 0 no-repeat;
}
/*MENU*/
#menu {
margin-top: 10px;
height: 36px;
width: 697px;
}
#menu a:link {
color: #2a2a2a;
text-decoration: none;
}
#menu a:visited {
text-decoration: none;
color: #2a2a2a;
}
#menu a:hover {
text-decoration: none;
color: #006600;
}
#menu a:active {
text-decoration: none;
color: #2a2a2a;
}
#menu #welcome {
height: 36px;
width: 401px;
background:url(images/bg-welcome.gif) 0 0 no-repeat;
padding-left: 22px;
padding-top: 8px;
margin-right: 10px;
font-size:16px;
float:left;
}
#menu #addnew {
height: 36px;
width: 83px;
background:url(images/bg-addnew.gif) 0 0 no-repeat;
padding-left: 40px;
padding-top: 8px;
margin-right: 10px;
font-size:16px;
float:left;
cursor: pointer; cursor: hand;
}
#menu #list {
height: 36px;
width: 75px;
background:url(images/bg-list.gif) 0 0 no-repeat;
padding-left: 50px;
padding-top: 8px;
font-size:16px;
float:left;
cursor: pointer; cursor: hand;
}
/*CONTENT*/
#content {
margin-top: 10px;
width: 697px;
}
#content #top-content {
height: 6px;
width: 697px;
background:url(images/bg-top-content.gif) 0 0 no-repeat;
}
#content #center-content {
min-height: 350px;
width: 697px;
background:url(images/bg-center-content.gif) 0 0 repeat-y;
}
#content #bottom-content {
height: 6px;
width: 697px;
background:url(images/bg-bottom-content.gif) 0 0 no-repeat;
}
#content #text {
padding:20px;
color: #b4cff2;
background:none;
}
#content #text #maintable {
color: #2a2a2a;
}
#content #text p {
margin:0px;
padding:0px;
color: #b4cff2;
background:none;
}
#content #text p.msg {
margin-bottom:10px;
padding:10px;
color: #b4cff2;
text-align:center;
background: #6699FF;
border:solid 1px #000066;
-moz-border-radius: 4px;
}
#content #text p.msg span {
background: url(images/exclamation.png) 0 -10px no-repeat;
padding-left:30px;
}
/* FORM BOX */
#formM { padding:10px;}
#formM p { padding-left:72px;padding-top:10px; font-size:11px;padding-bottom:10px; }
#formM .inputM{
border:none;
color:#2a2a2a;
background:url(images/bg-field.gif) 0 0 no-repeat;
width:327px;
height:26px;
padding:2px;
font-size:14px;
margin-bottom:10px;
cursor: pointer; cursor: hand;
}
#formM #fieldBox {
width:367px;
float:right;
margin-right:4px;
margin-top:-10px;
margin-bottom:20px;
}
#formM #submenu {
width:40px;
height:150px;
float:left;
}
#formM #submenu #icon {
width:22px;
height:29px;
float:left;
margin-right:10px;
}
#formM #submenu #icon img {
border:none;
}
#formM #submenu #icon.space {
margin-top:10px;
}
#formM #collection{
border:none;
color:#2a2a2a;
width:307px;
float:left;
background:none;
}
#formM #collection #top-box {
height: 6px;
width:337px;
background:url(images/bg-top-box.gif) 0 0 no-repeat;
}
#formM #collection #center-box {
width:337px;
background:url(images/bg-center-box.gif) 0 0 repeat-y;
}
#formM #collection #bottom-box {
height: 6px;
width:337px;
background:url(images/bg-bottom-box.gif) 0 0 no-repeat;
}
#formM #collection #center-box #text {
padding:10px;
color:#2a2a2a;
}
#formM #collection #center-box #text #divTxt {
color:#2a2a2a;
}
#formM .textareaM{
border:1px solid #C0C0C0;
color:#666666;
font-size:16px;
cursor: pointer; cursor: hand;
}
#formM label{
display:block;
color:#b4cff2;
}
#formM label span{
display:block;
float:left;
padding-right:6px;
width:300px;
text-align:left;
font-weight:bold;
font-size:16px;
}
#formM .note{
float:right;
margin-top:-5px;
width: 325px;
font-size:10px;
}
#formM .buttonM{
background:url(images/bg-button.gif) 0 0 no-repeat;
border:none;
height:75px;
width:116px;
color:#b4cff2;
padding-bottom:40px;
font-size:14px;
text-decoration:none;
font-weight:bold;
cursor: pointer; cursor: hand;
}
/*FOOTER*/
#footer {
margin-bottom: 20px;
margin-top: 20px;
height: 30px;
width: 697px;
text-align:center;
}
#footer a:link {
color: #2a2a2a;
text-decoration: none;
}
#footer a:visited {
text-decoration: none;
color: #2a2a2a;
}
#footer a:hover {
text-decoration: underline;
color: #0099FF;
}
#footer a:active {
text-decoration: none;
color: #2a2a2a;
}

Well to make your main page, just create new HTML document with this HTML code:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Building Administrator Manager for Table Relation Using PHP and jQuery</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<!--
#
# Building Administrator Manager for Table Relation Using PHP and jQuery
# Author  hairul azami a.k.a dr.emi <webmaster@dremi.info>
# Website http://dremi.info
# License: GPL
#
-->
</head>
<body>
<div id="ajax_display"></div>
<div id="mainPan">
<div id="bodyPan">
<div id="header"></div>
<div id="menu">
<div id="welcome">Welcome. Today is </div>
<a href="?cPub=addnew"><div id="addnew">ADD NEW</div></a>
<a href="?cPub=list"><div id="list">LIST</div></a>
</div>
<div id="content">
<div id="top-content"></div>
<div id="center-content">
<div id="text">
<div id="formM">
<form id="form1" name="form1" method="get" action="">
<label><span>Book Title </span>
<input name="title" value="" type="text" class="inputM" id="title" size="20" />
</label>
<label><span>Category </span>
<div id="contenPanCategory"></div>
<div id="toBeHideCategory">
<select class="inputM" name="category_id" size="1">
<option value="">-category-</option>
</select>
</div>
<span class="note"> (* Your category not listed ? Manage <a href="#" title="Manage Category">here</a> and <a href="#" title="Refresh Category List">refresh</a></span>
</label>
<div class="spacer"> </div>
<label><span>Collections </span>
<div id="fieldBox">
<div id="submenu">
<div id="icon"><a href="#"><img alt="Refresh Collection Data" src="images/refresh.gif" width="32" height="29" /></a></div>
<div id="icon" class="space"><a href="#" title="Add New Collection"><img alt="Add New Collection" src="images/addplus.gif" width="32" height="29" /></a></div>
<div id="icon" class="space"><a href="#" title="Remove All Collection"><img alt="Remove All Collection" src="images/remove.gif" width="32" height="29" /></a></div>
</div>
<div id="collection">
<div id="top-box"></div>
<div id="center-box">
<div id="text">
<div id="contenPanCollection"></div>
<div id="toBeHideCollection">
<!--
iFrame Collection
-->
</div>
</div>
<div id="bottom-box"></div>
</div>
</div>
</div>
</label>
<div class="clear"></div>
<label><span>  </span>
<div class="spacer"></div><input type="submit" name="Submit" value="UPDATE" class="buttonM"/>
</label>
</form>
</div>
</div>
</div>
<div id="bottom-content"></div>
</div>
<div id="footer">
© Copyright 2009 dr.emi creative design { <a href="https://www.dremi.info" target="_blank">www.dremi.info</a> }
</div>
</div>
</div>
</body>
</html>

Note: this is just planning HTML page. Next, we will save as PHP file. This is preview of main HTML page

Step 3 » Database and Programming

Oukee!!!! In this step, we will learn how to create database and hand code of PHP for our Administrator Page.
But before you have fun with your code, take look my simple database structure from the scratch

The table that have relation to others is book . The book table related for collection and category table. So for the next, you will need phpMyAdmin to create our new SQL code, based on our table structure above.
MySQL Code

CREATE TABLE `book` (
`book_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 255 ) NOT NULL ,
`category_id` INT( 11 ) NOT NULL
) ENGINE = MYISAM ;
CREATE TABLE `category` (
`category_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`description` VARCHAR( 255 ) NOT NULL
) ENGINE = MYISAM ;
CREATE TABLE `collection` (
`collection_id` INT( 11 ) NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`collection_data` VARCHAR( 255 ) NOT NULL ,
`book_id` INT( 11 ) NOT NULL
) ENGINE = MYISAM ;

Just login into your phpMyAdmin page, and create new database, called as: my_book database.

Then execute your SQL code

Ok, now you have 3 table on your database

Database and table was created. Next is programming time !
Let me explain about our planning for files structure.
The srtructure of files consist of :

No. Files/folder Description
1. ./images/ Images folder
2. ./js/ Javascript folder
– thickbox/ jQuery thickbox plugin
– ajax-display.js jQuery ajax loading indicator
– dynamic-form.js Javascript Dynamic Form for Category and Collection Data
– jquery-1.2.6.js jQuery framework
– jquery.highlightFade.js jQuery highlightFade plugin
3. category-loader.php file handler for dynamic category field
4. db.php database connection class
5. dre-config.php database configuration
6. frame-collection-loader.php file loader for iframe of collection data
7. function.php simple php function
8. index.php main PHP file
9. style.css our beautifull style 🙂
10. ui-collection.php unit interface for collection data

You may use login form for user authentication, but on this tutorial I’m not explain about it. The solution is you may use my free opensource login scripts by click this link:
http://www.4shared.com/file/82642576/3cb9f4a6/dreLogin1.html
or you can try demo page before download it
https://www.dremi.info/demo/dreLogin1
Class and Configuration
Now create simple PHP class for database connection and database configuration
PHP code for Database class: db.php

<?
/**
#
# Building Administrator Manager for Table Relation Using PHP and jQuery
# Author  hairul azami a.k.a dr.emi <webmaster@dremi.info>
# Website http://dremi.info
# License: GPL
# File: db.php
#
**/
## connection & database class
if(!defined('_VALID_ACCESS'))
{
die("Direct Access Are Not Allow");
}
class mydb
{
//connect to database
function connect($host, $user, $pass, $dbase)
{
$con = mysql_connect($host, $user, $pass);
if($con)
{
mysql_select_db($dbase) or die("could'nt select database");
}
else
{
die("couldn't connect to host");
}
}
//query
function query($sql)
{
$qry = mysql_query($sql);
return $qry;
}
//counter rows
function numrows($qry)
{
$num = mysql_num_rows($qry);
return $num;
}
//rows data
function fetch($qry)
{
if($row = mysql_fetch_array($qry))
{
return $row;
}
else
{
echo mysql_error();
}
}
//next classes
}
?>

The classe will help you to call simple paramater of each of table execution needed.
Next create database configuration file for: dre-config.php
PHP code for configuration file : dre-config.php

<?
if(!defined('_VALID_ACCESS'))
{
die("Direct Access Are Not Allow");
}
##connection definition
define("_DB_HOST", "localhost");
define("_DB_USER", "root");
define("_DB_PASS", "yoursecreetpassword");
define("_DB_NAME", "my_book");
?>

define is used for Defines a named constant. Example: localhost is your server host name, will defined as _DB_HOST.
Next file is function.php. This is my function code:

<?
if(!defined('_VALID_ACCESS'))
{
die("Direct Access Are Not Allow");
}
function redirect($delay,$goto)
{
echo"<br>Redirect progress..<br>Please Stand By.. <meta http-equiv=\"refresh\" content=\"$delay;URL=$goto\" />";
}
function alert($msg)
{
echo "<SCRIPT>alert(\"$msg\");history.go(-1)</SCRIPT>";
exit;
}
function alert2($msg)
{
echo "<SCRIPT>alert(\"$msg\");</SCRIPT>";
exit;
}
?>

redirect is function that used for redirect the result page, once action cleared. For alert and alert2 is just to display Javascript alert, maybe you will need as messager for action result.
PHP Main Page
Well….. continue with PHP main Page, save as main.html into index.php
Now, I will explain about codes in index.php. In index.php we will create dynamic content for each of link, I use $_GET[‘string’] to implementad it. GET will give value from URL parameter. Also, in this page, we will create some code for insert, edit and delete rows of table. So, do not close your window now 🙂
First you must call dre-config.php, db.php, and function.php at the begining of index.php Use include_once to call each of file.

define("_VALID_ACCESS", true);
if(!defined('_VALID_ACCESS'))
{
die("Direct Access Are Not Allow");
}
include_once "dre-config.php";
include_once "db.php";
include_once "function.php";

You must define _VALID_ACCESS as true. So, index.php are allowed to direct access.
For calling your database connection class, use this code:

$db = new mydb;
$db->connect(_DB_HOST, _DB_USER, _DB_PASS, _DB_NAME);

connect is one of your function on db.php class. To call another function, just use $db->functionname. Example: $db->query() or $db->fetch()
OK, the next is creating javascript files. Just Begin with ajax-display.js

// JavaScript Document
$(function(){
$("#ajax_display").ajaxStart(function(){
$(this).html('<img src="images/ajax-loader-trans.gif" />');
});
$("#ajax_display").ajaxSuccess(function(){
$(this).html('');
});
$("#ajax_display").ajaxError(function(url){
alert('jQuery ajax is error ');
});
});

ajax-display.js will display jQuery action loading indicator by print out the images/ajax-loader-trans.gif into browser page.
Next, dynamic-form.js. This file will used for handling dynamic process for insert and update form. Offcourse to manage our relation table data.

// JavaScript Document
function addFormField() {
var id = document.getElementById("id").value;
$("#divTxt").append("<p style='margin:0px;padding:0px;width:90%;' id='row" + id + "'><label for='txt" + id + "' style='color:#2a2a2a;'>" + id + ".    <input title='Type new collection data' type=text name='collection_data[]' id='txt1" + id + "' size='35'>  <a href='#' onClick='removeFormField(\"#row" + id + "\"); return false;'><img alt='Remove' title='Remove' border=0 src='images/close.png'></a></label></p><br>");
$('#row' + id).highlightFade({
speed:1000
});
id = (id - 1) + 2;
document.getElementById("id").value = id;
}
function removeFormField(id) {
$(id).remove();
}
/**REFRESH SCRIPT FOR COLLECTION**/
function refreshCollection(book_id, cDel) {
$("#contenPanCollection").load("frame-collection-loader.php?book_id="+book_id+"&cDel="+cDel+"", '', callbackCollection);
}
function callbackCollection() {
$("#toBeHideCollection").hide();
$("#contenPanCollection").show();
}
$(document).ready(refreshCollection(book_id, cDel));
/**REFRESH SCRIPT FOR CATEGORY**/
function refreshCategory() {
$("#contenPanCategory").load("category-loader.php", '', callbackCategory);
}
function callbackCategory() {
$("#toBeHideCategory").hide();
$("#contenPanCategory").show();
}
$(document).ready(refreshCategory());

addFormField is function to display dynamic text field, on this part I use jquery.highlightFade.js plugin to implementad it.
frame-collection-loader.php is file that used by jQuery ajax, to get value of book relation table. Remember that, book table related with collection data table. So, to implementad it using jQuery, you must create function like refreshCollection.
OK, back to index.php, add this code to call some javascript file

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="js/jquery.highlightFade.js"></script>
<script type="text/javascript" src="js/dynamic-form.js"></script>
<script type="text/javascript" src="js/ajax-display.js"></script>
<style type="text/css" media="all">
@import "js/thickbox/thickbox.css";
</style>
<script type="text/javascript" src="js/thickbox/thickbox.js"></script>

Thickbox is a jQuery plugin to displaying unit interface content in form page. You will see the result after complete this tutorial.
On index.php I use <div id=”ajax_display”></div> after BODY tag as target of ajax-display javascript. So, you may create a style for it.

#ajax_display {
position: fixed; top: 49%; left: 35%; border:0px; z-index: 50; width: 110px; height: 100px; margin: auto 0;
}

Let’s see our last index.php code

&lt;?
/**
#
# Building Administrator Manager for Table Relation Using PHP and jQuery
# Author  hairul azami a.k.a dr.emi &lt;webmaster@dremi.info&gt;
# Website http://dremi.info
# License: GPL
# File: index.php
#
**/
##YOU MAY ADD SOME AUTHENTICATION CODE FOR USER LOGIN HERE
define(&quot;_VALID_ACCESS&quot;, true);
if(!defined('_VALID_ACCESS'))
{
die(&quot;Direct Access Are Not Allow&quot;);
}
include_once &quot;dre-config.php&quot;;
include_once &quot;db.php&quot;;
include_once &quot;function.php&quot;;
$db = new mydb;
$db-&gt;connect(_DB_HOST, _DB_USER, _DB_PASS, _DB_NAME);
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Building Administrator Manager for Table Relation Using PHP and jQuery&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.2.6.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery.highlightFade.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/dynamic-form.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/ajax-display.js&quot;&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot; media=&quot;all&quot;&gt;
@import &quot;js/thickbox/thickbox.css&quot;;
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/thickbox/thickbox.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;ajax_display&quot;&gt;&lt;/div&gt;

OK, next task is creating dynamic content for insert, edit, and delete of table rows.
Take look this code:
First content is listing and delete of table data

&lt;?
if($_GET['cPub'] == 'list')
{
if($_GET['cTask'] == 'delete')
{
$CHK = &quot;SELECT * FROM collection WHERE book_id = '$_GET[book_id]'&quot;;
$SQL = &quot;DELETE FROM book WHERE book_id = '$_GET[book_id]'&quot;;
##FIRST CHECK IT FOR COLLECTION
$COLL= $db-&gt;numrows($db-&gt;query($CHK));
if($COLL &gt; 0)
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;You cannot delete BOOK ID = $_GET[book_id]. This record still have $COLL collection data&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
if($QRY = $db-&gt;query($SQL))
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;Successfully Delete for BOOK ID = $_GET[book_id]&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;Error: Delete for BOOK ID = $_GET[book_id]&lt;span&gt;&lt;/p&gt;&quot;;
}
}
}
$SQL = &quot;SELECT * FROM book ORDER BY book_id DESC&quot;;
$QRY = $db-&gt;query($SQL);
$NUM = $db-&gt;numrows($QRY);
$i = 0;
if($NUM &gt; 0)
{
?&gt;
&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;4&quot; cellspacing=&quot;1&quot; bgcolor=&quot;#FFFFFF&quot; id=&quot;maintable&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;5%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;No.&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;47%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Book Title&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;24%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Category&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;10%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Collection&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;14%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Option&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?
while($ROW = $db-&gt;fetch($QRY))
{
$i++;
?&gt;
&lt;tr&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;&lt;? echo $i; ?&gt;&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;&lt;? echo $ROW['title']; ?&gt;&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;&lt;?
$CATROW = $db-&gt;fetch($db-&gt;query(&quot;SELECT * FROM category WHERE category_id = '$ROW[category_id]'&quot;));
echo $CATROW['description'];
?&gt;
&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;
&lt;?
##NUMBER OF COLLECTION
$COLLECTION_NUMBER = $db-&gt;numrows($db-&gt;query(&quot;SELECT * FROM collection WHERE book_id = '$ROW[book_id]'&quot;));
echo $COLLECTION_NUMBER;
?&gt;
&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;
&lt;a href=&quot;ui-collection.php?book_id=&lt;? echo $ROW['book_id']; ?&gt;&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=500&quot; class=&quot;thickbox&quot; title=&quot;View Collection of &lt;? echo $ROW['title']; ?&gt;&quot;&gt;&lt;img src=&quot;images/zoom16.png&quot; alt=&quot;View Collection&quot; width=&quot;16&quot; height=&quot;16&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;?cPub=edit&amp;amp;book_id=&lt;? echo $ROW['book_id']; ?&gt;&quot; title=&quot;Edit&quot;&gt;&lt;img src=&quot;images/edit.png&quot; alt=&quot;Edit&quot; width=&quot;16&quot; height=&quot;16&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;cf=confirm('Are you sure to delete No. &lt;? echo $i; ?&gt; ???');if(cf)window.location='?cPub=list&amp;amp;cTask=delete&amp;amp;book_id=&lt;? echo $ROW['book_id']; ?&gt;';return false;&quot; title=&quot;Delete&quot;&gt;&lt;img src=&quot;images/delete.png&quot; alt=&quot;Delete&quot; width=&quot;16&quot; height=&quot;16&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?
}
?&gt;
&lt;/table&gt;
&lt;?
}
else
{
echo &quot;&lt;p&gt;No Query&lt;/p&gt;&quot;;
}
}

Well… I cannot explain each of line, but feel free to have fun while typing the code. Actually the code will diplaying List of Data Rows.
Next is Adding New Record. This code will displaying form for adding new record of data

elseif($_GET['cPub'] == 'addnew')
{
?&gt;
&lt;?
if($_GET['Submit'] == 'SUBMIT' &amp;&amp; !empty($_GET['title']))
{
##INSERT NEW BOOK
if(!empty($_GET['category_id2']))
{
$choseCat = $_GET['category_id2'];
}
else
{
$choseCat = $_GET['category_id'];
}
$SQL = &quot;INSERT INTO book(title, category_id) VALUES('$_GET[title]', '$choseCat')&quot;;
if($db-&gt;query($SQL))
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;New Record Successfully Submited&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
echo &quot;&lt;p class='msg'&gt;E R R O R !&lt;/p&gt;&quot;;
}
##GET THE LAST ID FOR BOOK RECORD
$BOOKID = $db-&gt;fetch($db-&gt;query(&quot;SELECT * FROM book ORDER BY book_id DESC&quot;));
##INSERT NEW COLLECTION
for($i=0;$i&lt;=count($_GET['collection_data']);$i++)
{
if(!empty($_GET['collection_data'][$i]))
{
$SQLCOLLECTION = &quot;INSERT INTO collection(collection_data, book_id)
VALUES('&quot;.$_GET['collection_data'][$i].&quot;', '$BOOKID[book_id]')&quot;;
$db-&gt;query($SQLCOLLECTION);
}
}
}
?&gt;
&lt;div id=&quot;formM&quot;&gt;
&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;get&quot; action=&quot;&quot;&gt;
&lt;input name=&quot;cPub&quot; type=&quot;hidden&quot; value=&quot;&lt;? echo $_GET['cPub']; ?&gt;&quot; /&gt;
&lt;label&gt;&lt;span&gt;Book Title &lt;/span&gt;
&lt;input name=&quot;title&quot; type=&quot;text&quot; class=&quot;inputM&quot; id=&quot;title&quot; size=&quot;20&quot; /&gt;
&lt;/label&gt;
&lt;label&gt;&lt;span&gt;Category &lt;/span&gt;
&lt;div id=&quot;contenPanCategory&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;toBeHideCategory&quot;&gt;
&lt;select class=&quot;inputM&quot; name=&quot;category_id&quot; size=&quot;1&quot;&gt;
&lt;?
$QRYCAT = $db-&gt;query(&quot;SELECT * FROM category ORDER BY description&quot;);
while($ROWCAT = $db-&gt;fetch($QRYCAT))
{
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT['category_id']; ?&gt;&quot;&gt;&lt;? echo $ROWCAT['description']; ?&gt;&lt;/option&gt;
&lt;?
}
?&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;span class=&quot;note&quot;&gt; (* Your category not listed ? Manage &lt;a href=&quot;category-loader.php?cF=Manage&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=300&quot; class=&quot;thickbox&quot; title=&quot;Manage Category&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;javascript:void(0);&quot; title=&quot;Refresh Category List&quot; onClick=&quot;refreshCategory()&quot;&gt;refresh&lt;/a&gt;&lt;/span&gt;
&lt;/label&gt;
&lt;div class=&quot;spacer&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;Collections &lt;/span&gt;
&lt;div id=&quot;fieldBox&quot;&gt;
&lt;div id=&quot;submenu&quot;&gt;
&lt;div id=&quot;icon&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; onClick=&quot;addFormField(); return false;&quot; title=&quot;Add New Collection&quot;&gt;&lt;img alt=&quot;Add New Collection&quot; src=&quot;images/addplus.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;input type=&quot;hidden&quot; id=&quot;id&quot; value=&quot;1&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;collection&quot;&gt;
&lt;div id=&quot;top-box&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;center-box&quot;&gt;
&lt;div id=&quot;text&quot;&gt;&lt;div id=&quot;divTxt&quot;&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div id=&quot;bottom-box&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/label&gt;
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;
&lt;div class=&quot;spacer&quot;&gt;&lt;/div&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;SUBMIT&quot; class=&quot;buttonM&quot;/&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;?
}

And this is for Editing Form code. Will used for update one of data record.

elseif($_GET['cPub'] == 'edit')
{
?&gt;
&lt;?
if($_GET['Submit'] == 'UPDATE' &amp;&amp; !empty($_GET['title']))
{
##UPDATE CURRENT BOOK
if(!empty($_GET['category_id2']))
{
$choseCat = $_GET['category_id2'];
}
else
{
$choseCat = $_GET['category_id'];
}
$SQL = &quot;UPDATE book SET title='$_GET[title]', category_id='$choseCat' WHERE book_id='$_GET[book_id]'&quot;;
if($db-&gt;query($SQL))
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;Current Record Successfully Updated&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
echo &quot;&lt;p class='msg'&gt;E R R O R !&lt;/p&gt;&quot;;
}
}
?&gt;
&lt;?
$SQL = &quot;SELECT * FROM book WHERE book_id = '$_GET[book_id]'&quot;;
$ROW = $db-&gt;fetch($db-&gt;query($SQL));
?&gt;
&lt;div id=&quot;formM&quot;&gt;
&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;get&quot; action=&quot;&quot;&gt;
&lt;input name=&quot;cPub&quot; type=&quot;hidden&quot; value=&quot;&lt;? echo $_GET['cPub']; ?&gt;&quot; /&gt;
&lt;input name=&quot;book_id&quot; type=&quot;hidden&quot; value=&quot;&lt;? echo $_GET['book_id']; ?&gt;&quot; /&gt;
&lt;label&gt;&lt;span&gt;Book Title &lt;/span&gt;
&lt;input name=&quot;title&quot; value=&quot;&lt;? echo $ROW['title']; ?&gt;&quot; type=&quot;text&quot; class=&quot;inputM&quot; id=&quot;title&quot; size=&quot;20&quot; /&gt;
&lt;/label&gt;
&lt;label&gt;&lt;span&gt;Category &lt;/span&gt;
&lt;div id=&quot;contenPanCategory&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;toBeHideCategory&quot;&gt;
&lt;select class=&quot;inputM&quot; name=&quot;category_id&quot; size=&quot;1&quot;&gt;
&lt;?
$SQLCAT_CUR = &quot;SELECT * FROM category WHERE category_id = '$ROW[category_id]'&quot;;
$ROWCAT_CUR = $db-&gt;fetch($db-&gt;query($SQLCAT_CUR));
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT_CUR['category_id']; ?&gt;&quot;&gt;- &lt;? echo $ROWCAT_CUR['description']; ?&gt; -&lt;/option&gt;
&lt;?
$SQLCAT = &quot;SELECT * FROM category ORDER BY description&quot;;
$QRYCAT = $db-&gt;query($SQLCAT);
while($ROWCAT = $db-&gt;fetch($QRYCAT))
{
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT['category_id']; ?&gt;&quot;&gt;&lt;? echo $ROWCAT['description']; ?&gt;&lt;/option&gt;
&lt;?
}
?&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;span class=&quot;note&quot;&gt; (* Your category not listed ? Manage &lt;a href=&quot;category-loader.php?cF=Manage&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=300&quot; class=&quot;thickbox&quot; title=&quot;Manage Category&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;javascript:void(0);&quot; title=&quot;Refresh Category List&quot; onClick=&quot;refreshCategory()&quot;&gt;refresh&lt;/a&gt;&lt;/span&gt;
&lt;/label&gt;
&lt;div class=&quot;spacer&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;Collections &lt;/span&gt;
&lt;div id=&quot;fieldBox&quot;&gt;
&lt;div id=&quot;submenu&quot;&gt;
&lt;div id=&quot;icon&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; title=&quot;Refresh Collection Data&quot; onClick=&quot;refreshCollection(&lt;? echo $ROW['book_id']; ?&gt;, 0)&quot;&gt;&lt;img alt=&quot;Refresh Collection Data&quot; src=&quot;images/refresh.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div id=&quot;icon&quot; class=&quot;space&quot;&gt;&lt;a href=&quot;ui-collection.php?cF=Input&amp;amp;book_id=&lt;? echo $ROW['book_id'];?&gt;&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=300&quot; class=&quot;thickbox&quot; title=&quot;Add New Collection&quot;&gt;&lt;img alt=&quot;Add New Collection&quot; src=&quot;images/addplus.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div id=&quot;icon&quot; class=&quot;space&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;cf=confirm('Are you sure to remove all collection data ???');if(cf)refreshCollection(&lt;? echo $ROW['book_id']; ?&gt;, 1);return false;&quot; title=&quot;Remove All Collection&quot;&gt;&lt;img alt=&quot;Remove All Collection&quot; src=&quot;images/remove.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;collection&quot;&gt;
&lt;div id=&quot;top-box&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;center-box&quot;&gt;
&lt;div id=&quot;text&quot;&gt;
&lt;div id=&quot;contenPanCollection&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;toBeHideCollection&quot;&gt;
&lt;iframe width=&quot;300&quot; name=&quot;refreshCollectionFrame&quot; src=&quot;ui-collection.php?book_id=&lt;? echo $ROW['book_id']; ?&gt;&quot; frameborder=&quot;0&quot; scrolling=&quot;auto&quot;&gt;
&lt;/iframe&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;bottom-box&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/label&gt;
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;
&lt;div class=&quot;spacer&quot;&gt;&lt;/div&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;UPDATE&quot; class=&quot;buttonM&quot;/&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;?
}
else
{
echo &quot;&lt;p&gt;You are in Administrator Page. Select Main Menu to Manage your data.&lt;/p&gt;&quot;;
}
?&gt;

The last is let me type my copyright website

&lt;div id=&quot;footer&quot;&gt;
&amp;copy; Copyright 2009 dr.emi creative design { &lt;a href=&quot;https://www.dremi.info&quot; target=&quot;_blank&quot;&gt;www.dremi.info&lt;/a&gt; }
&lt;/div&gt;

IFRAME code will load ui-collection.php that contain used for displaying collection data of current data row. DIV ID contenPanCollection is ID that used by jQuery Ajax as target for Dynamic Collection Data. To activated it, I use onClick=”refreshCollection(<? echo $ROW[‘book_id’]; ?>, 0)”. While refreshCollection function executed, the condition is hidding DIV ID toBeHideCollection and show DIV ID contenPanCollection. The other example of dynamic field is refreshCategory javascript function to load dynamicly category-loader.php
How about thickbox plugin ?
ThickBox jQuery plugin used for displaying unit interface for Add New Collection link or manage category link. As you see, to define class of thickbox plugin, just use class=”thickbox”, and to define width and height of unit interface, just change parameter of width and height from this line:

   keepThis=true&amp;TB_iframe=true&amp;height=250&amp;width=300   

And this is code of ui-collection.php

&lt;?
define(&quot;_VALID_ACCESS&quot;, true);
if(!defined('_VALID_ACCESS'))
{
die(&quot;Direct Access Are Not Allow&quot;);
}
//echo $_SERVER['REQUEST_URI'];
include_once &quot;dre-config.php&quot;;
include_once &quot;db.php&quot;;
include_once &quot;function.php&quot;;
$db = new mydb;
?&gt;
&lt;style media=&quot;all&quot; type=&quot;text/css&quot;&gt;
* {
background:#ffffff;
color:#2a2a2a;
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery.highlightFade.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/dynamic-form.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/ajax-display.js&quot;&gt;&lt;/script&gt;
&lt;?
$book_id=intval($_GET['book_id']);
$cDel=intval($_GET['cDel']);
$db-&gt;connect(_DB_HOST, _DB_USER, _DB_PASS, _DB_NAME); //changet the configuration in required
?&gt;
&lt;?
if($_GET['cF'] == 'Delete')
{
$db-&gt;query(&quot;DELETE FROM collection WHERE collection_id = '$_GET[collection_id]'&quot;);
redirect(0, &quot;$_SERVER[PHP_SELF]?book_id=$_GET[book_id]&quot;);
}
elseif($cDel == 1)
{
$chk4Del = $db-&gt;numrows($db-&gt;query(&quot;SELECT * FROM collection
WHERE book_id = '$book_id'&quot;));
if($chk4Del &gt;= 1)
{
if($db-&gt;query(&quot;DELETE FROM collection WHERE book_id = '$book_id'&quot;))
{
alert2(&quot;All Collection data has been deleted !&quot;);
}
}
else
{
alert2(&quot;I didn't deleted anything !&quot;);
}
}
elseif($_GET['cF'] == 'Edit')
{
if($_POST['update'] &amp;&amp; !empty($_POST['collection_data']))
{
$db-&gt;query(&quot;UPDATE collection SET collection_data = '$_POST[collection_data]' WHERE collection_id = '$_GET[collection_id]'&quot;);
redirect(0, &quot;$_SERVER[PHP_SELF]?book_id=$_GET[book_id]&quot;);
}
$e_data_collection = $db-&gt;fetch($db-&gt;query(&quot;SELECT * FROM collection WHERE collection_id = '$_GET[collection_id]'&quot;));
?&gt;
&lt;p style=&quot;font-weight:bold&quot;&gt;Edit Data for Collection&lt;/p&gt;
&lt;form name=&quot;miniForm&quot; action=&quot;&quot; method=&quot;POST&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;book_id&quot; value=&quot;&lt;? echo $_GET['book_id']; ?&gt;&quot; /&gt;
&lt;input class=&quot;miniInput&quot; type=&quot;text&quot; name=&quot;collection_data&quot; value=&quot;&lt;? echo $e_data_collection['collection_data']; ?&gt;&quot;&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;submit&quot; name=&quot;update&quot; value=&quot;update&quot;&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;button&quot; name=&quot;cancel&quot; onclick=&quot;javascript:history.go(-1);&quot; value=&quot;cancel&quot;&gt;
&lt;/form&gt;
&lt;?
}
elseif($_GET['cF'] == 'Input')
{
if($_POST['submit'])
{
for($i=0;$i&lt;=count($_POST['collection_data']);$i++)
{
if(!empty($_POST['collection_data'][$i]))
{
$SQLCOLLECTION = &quot;INSERT INTO collection(collection_data, book_id) VALUES('&quot;.$_POST['collection_data'][$i].&quot;', '$_POST[book_id]')&quot;;
if($db-&gt;query($SQLCOLLECTION))
{
echo &quot;Collection Data $i Submited Successfully.&lt;br&gt;&quot;;
}
}
}
}
?&gt;
&lt;p style=&quot;font-weight:bold&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; onClick=&quot;addFormField(); return false;&quot; title=&quot;Add New Collection&quot;&gt;&lt;img alt=&quot;Add New Collection&quot; src=&quot;images/add.png&quot; border=&quot;0&quot; /&gt; Add New Collection Data&lt;/a&gt;&lt;input type=&quot;hidden&quot; id=&quot;id&quot; value=&quot;1&quot;&gt;&lt;/p&gt;
&lt;form name=&quot;miniForm&quot; action=&quot;&quot; method=&quot;POST&quot;&gt;
&lt;input type=&quot;hidden&quot; name=&quot;book_id&quot; value=&quot;&lt;? echo $_GET['book_id']; ?&gt;&quot; /&gt;
&lt;div id=&quot;divTxt&quot;&gt;&lt;/div&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;&gt;
&lt;/form&gt;
&lt;?
}
else
{
?&gt;
&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;1&quot; bgcolor=&quot;#CCCCCC&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;5%&quot; bgcolor=&quot;#efefef&quot;&gt;No.&lt;/td&gt;
&lt;td width=&quot;26%&quot; bgcolor=&quot;#efefef&quot;&gt;Collection Data &lt;/td&gt;
&lt;td width=&quot;20%&quot; bgcolor=&quot;#efefef&quot;&gt;&lt;center&gt;Option&lt;/center&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?
$q_data_colllection = $db-&gt;query(&quot;SELECT * FROM collection WHERE book_id = '$book_id'&quot;);
while($r_data_colllection = $db-&gt;fetch($q_data_colllection))
{
$i++;
?&gt;
&lt;tr&gt;
&lt;td bgcolor=&quot;#ffffff&quot;&gt;&lt;? echo $i; ?&gt;&lt;/td&gt;
&lt;td bgcolor=&quot;#ffffff&quot;&gt;&lt;? echo $r_data_colllection['collection_data']; ?&gt; &lt;/td&gt;
&lt;td valign=&quot;top&quot; bgcolor=&quot;#ffffff&quot;&gt;&lt;center&gt;
&lt;a alt=&quot;Edit Collection Data No. &lt;? echo $i; ?&gt;&quot; title=&quot;Edit Collection Data No. &lt;? echo $i; ?&gt;&quot; href=&quot;?cF=Edit&amp;book_id=&lt;? echo $_GET['book_id'] ?&gt;&amp;collection_id=&lt;? echo $r_data_colllection['collection_id'] ?&gt;&quot; class=&quot;thickbox&quot;&gt;&lt;img alt=&quot;Edit Collection Data No. &lt;? echo $i; ?&gt;&quot; title=&quot;Edit Collection Data No. &lt;? echo $i; ?&gt;&quot; src=&quot;images/edit.png&quot; border=&quot;0&quot; width=&quot;16px;&quot; height=&quot;16px;&quot; /&gt;&lt;/a&gt;
&lt;a alt=&quot;Delete Collection Data No. &lt;? echo $i; ?&gt;&quot; title=&quot;Delete Collection Data No. &lt;? echo $i; ?&gt;&quot; href=&quot;javascript:void(0);&quot; onclick=&quot;cf=confirm('Are you sure to delete No. &lt;? echo $i; ?&gt; ???');if(cf)window.location='?cF=Delete&amp;book_id=&lt;? echo $_GET['book_id'] ?&gt;&amp;collection_id=&lt;? echo $r_data_colllection['collection_id'] ?&gt;';return false;&quot;&gt;&lt;img alt=&quot;Delete Collection Data No. &lt;? echo $i; ?&gt;&quot; title=&quot;Delete Collection Data No. &lt;? echo $i; ?&gt;&quot; src=&quot;images/delete.png&quot; border=&quot;0&quot; width=&quot;16px;&quot; height=&quot;16px;&quot; /&gt;&lt;/a&gt;
&lt;/center&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?
}
?&gt;
&lt;/table&gt;
&lt;?
}
?&gt;

PHP code for category-loader.php

&lt;?
define(&quot;_VALID_ACCESS&quot;, true);
if(!defined('_VALID_ACCESS'))
{
die(&quot;Direct Access Are Not Allow&quot;);
}
//echo $_SERVER['REQUEST_URI'];
include_once &quot;dre-config.php&quot;;
include_once &quot;db.php&quot;;
include_once &quot;function.php&quot;;
$db = new mydb;
?&gt;
&lt;?
$category_id=intval($_GET['category_id']);
$cDel=intval($_GET['cDel']);
$db-&gt;connect(_DB_HOST, _DB_USER, _DB_PASS, _DB_NAME); //changet the configuration if required
?&gt;
&lt;?
if($_GET['cF'] == 'Delete')
{
$db-&gt;query(&quot;DELETE FROM category WHERE category_id = '$_GET[category_id]'&quot;);
redirect(0, &quot;$_SERVER[PHP_SELF]?cF=Manage&quot;);
}
elseif($_GET['cF'] == 'Edit')
{
if($_POST['update'] &amp;&amp; !empty($_POST['description']))
{
$db-&gt;query(&quot;UPDATE category SET description = '$_POST[description]' WHERE category_id = '$_GET[category_id]'&quot;);
redirect(0, &quot;$_SERVER[PHP_SELF]?cF=Manage&quot;);
}
$e_data_category = $db-&gt;fetch($db-&gt;query(&quot;SELECT * FROM category WHERE category_id = '$_GET[category_id]'&quot;));
?&gt;
&lt;style media=&quot;all&quot; type=&quot;text/css&quot;&gt;
* {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
&lt;/style&gt;
&lt;p style=&quot;font-weight:bold&quot;&gt;Edit Data for Category&lt;/p&gt;
&lt;form name=&quot;miniForm&quot; action=&quot;&quot; method=&quot;POST&quot;&gt;
&lt;input title='Type new category' type=&quot;text&quot; name='description' value=&quot;&lt;? echo $e_data_category['description']; ?&gt;&quot; size='35'&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;submit&quot; name=&quot;update&quot; value=&quot;update&quot;&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;button&quot; name=&quot;cancel&quot; onclick=&quot;javascript:history.go(-1);&quot; value=&quot;cancel&quot;&gt;
&lt;/form&gt;
&lt;?
}
elseif($_GET['cF'] == 'Manage')
{
?&gt;
&lt;style media=&quot;all&quot; type=&quot;text/css&quot;&gt;
* {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
&lt;/style&gt;
&lt;p style=&quot;font-weight:bold&quot;&gt;&lt;a href=&quot;?cF=Input&quot; title=&quot;Add New Category&quot;&gt;&lt;img alt=&quot;Add New Category&quot; src=&quot;images/add.png&quot; border=&quot;0&quot; /&gt; Add New Category&lt;/a&gt;&lt;/p&gt;
&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;2&quot; cellspacing=&quot;1&quot; bgcolor=&quot;#CCCCCC&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;5%&quot; bgcolor=&quot;#efefef&quot;&gt;No.&lt;/td&gt;
&lt;td width=&quot;26%&quot; bgcolor=&quot;#efefef&quot;&gt;Category Name&lt;/td&gt;
&lt;td width=&quot;20%&quot; bgcolor=&quot;#efefef&quot;&gt;&lt;center&gt;Option&lt;/center&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?
$q_data_category = $db-&gt;query(&quot;SELECT * FROM category ORDER BY description&quot;);
while($r_data_category = $db-&gt;fetch($q_data_category))
{
$i++;
?&gt;
&lt;tr&gt;
&lt;td bgcolor=&quot;#ffffff&quot;&gt;&lt;? echo $i; ?&gt;&lt;/td&gt;
&lt;td bgcolor=&quot;#ffffff&quot;&gt;&lt;? echo $r_data_category['description']; ?&gt; &lt;/td&gt;
&lt;td valign=&quot;top&quot; bgcolor=&quot;#ffffff&quot;&gt;&lt;center&gt;
&lt;a alt=&quot;Edit Collection Data No. &lt;? echo $i; ?&gt;&quot; title=&quot;Edit Category No. &lt;? echo $i; ?&gt;&quot; href=&quot;?cF=Edit&amp;category_id=&lt;? echo $r_data_category['category_id'] ?&gt;&quot; class=&quot;thickbox&quot;&gt;&lt;img alt=&quot;Edit Category No. &lt;? echo $i; ?&gt;&quot; title=&quot;Edit Category No. &lt;? echo $i; ?&gt;&quot; src=&quot;images/edit.png&quot; border=&quot;0&quot; width=&quot;16px;&quot; height=&quot;16px;&quot; /&gt;&lt;/a&gt;
&lt;a alt=&quot;Delete Category No. &lt;? echo $i; ?&gt;&quot; title=&quot;Delete Category No. &lt;? echo $i; ?&gt;&quot; href=&quot;javascript:void(0);&quot; onclick=&quot;cf=confirm('Are you sure to delete No. &lt;? echo $i; ?&gt; ???');if(cf)window.location='?cF=Delete&amp;category_id=&lt;? echo $r_data_category['category_id'] ?&gt;';return false;&quot;&gt;&lt;img alt=&quot;Delete Category Data No. &lt;? echo $i; ?&gt;&quot; title=&quot;Delete Category No. &lt;? echo $i; ?&gt;&quot; src=&quot;images/delete.png&quot; border=&quot;0&quot; width=&quot;16px;&quot; height=&quot;16px;&quot; /&gt;&lt;/a&gt;
&lt;/center&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?
}
?&gt;
&lt;/table&gt;
&lt;?
}
elseif($_GET['cF'] == 'Input')
{
if($_POST['submit'] &amp;&amp; !empty($_POST['description']))
{
$SQL = &quot;INSERT INTO category(description) VALUES('$_POST[description]')&quot;;
if($db-&gt;query($SQL))
{
redirect(0, &quot;$_SERVER[PHP_SELF]?cF=Manage&quot;);
}
}
?&gt;
&lt;style media=&quot;all&quot; type=&quot;text/css&quot;&gt;
* {
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
&lt;/style&gt;
&lt;form name=&quot;miniForm&quot; action=&quot;&quot; method=&quot;POST&quot;&gt;
&lt;input title='Type new category' type=&quot;text&quot; name='description' size='35'&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;submit&quot; name=&quot;submit&quot; value=&quot;submit&quot;&gt;
&lt;input class=&quot;miniSubmit&quot; type=&quot;button&quot; name=&quot;cancel&quot; onclick=&quot;javascript:history.go(-1);&quot; value=&quot;cancel&quot;&gt;
&lt;/form&gt;
&lt;?
}
else
{
?&gt;
&lt;select class=&quot;inputM&quot; name=&quot;category_id2&quot; size=&quot;1&quot;&gt;
&lt;?
$SQLCAT = &quot;SELECT * FROM category ORDER BY description&quot;;
$QRYCAT = $db-&gt;query($SQLCAT);
while($ROWCAT = $db-&gt;fetch($QRYCAT))
{
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT['category_id']; ?&gt;&quot;&gt;&lt;? echo $ROWCAT['description']; ?&gt;&lt;/option&gt;
&lt;?
}
?&gt;
&lt;/select&gt;
&lt;?
}
?&gt;

PHP Code for frame-collection-loader.php

&lt;iframe width=&quot;300&quot; name=&quot;refreshCollectionFrame&quot; src=&quot;ui-collection.php?book_id=&lt;? echo $_GET['book_id']; ?&gt;&amp;cDel=&lt;? echo $_GET['cDel']; ?&gt;&quot; frameborder=&quot;0&quot; scrolling=&quot;auto&quot;&gt;
&lt;/iframe&gt;

Here are the complete index.php code

&lt;?
/**
#
# Building Administrator Manager for Table Relation Using PHP and jQuery
# Author  hairul azami a.k.a dr.emi &lt;webmaster@dremi.info&gt;
# Website http://dremi.info
# License: GPL
# File: index.php
#
**/
##YOU MAY ADD SOME AUTHENTICATION CODE FOR USER LOGIN HERE
define(&quot;_VALID_ACCESS&quot;, true);
if(!defined('_VALID_ACCESS'))
{
die(&quot;Direct Access Are Not Allow&quot;);
}
include_once &quot;dre-config.php&quot;;
include_once &quot;db.php&quot;;
include_once &quot;function.php&quot;;
$db = new mydb;
$db-&gt;connect(_DB_HOST, _DB_USER, _DB_PASS, _DB_NAME);
?&gt;
&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt;
&lt;head&gt;
&lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=utf-8&quot; /&gt;
&lt;title&gt;Building Administrator Manager for Table Relation Using PHP and jQuery&lt;/title&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery-1.3.2.min.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/jquery.highlightFade.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/dynamic-form.js&quot;&gt;&lt;/script&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/ajax-display.js&quot;&gt;&lt;/script&gt;
&lt;style type=&quot;text/css&quot; media=&quot;all&quot;&gt;
@import &quot;js/thickbox/thickbox.css&quot;;
&lt;/style&gt;
&lt;script type=&quot;text/javascript&quot; src=&quot;js/thickbox/thickbox.js&quot;&gt;&lt;/script&gt;
&lt;link href=&quot;style.css&quot; rel=&quot;stylesheet&quot; type=&quot;text/css&quot; /&gt;
&lt;!--
#
# Building Administrator Manager for Table Relation Using PHP and jQuery
# Author  hairul azami a.k.a dr.emi &lt;webmaster@dremi.info&gt;
# Website http://dremi.info
# License: GPL
#
--&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;div id=&quot;ajax_display&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;mainPan&quot;&gt;
&lt;div id=&quot;bodyPan&quot;&gt;
&lt;div id=&quot;header&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;menu&quot;&gt;
&lt;div id=&quot;welcome&quot;&gt;Welcome. Today is &lt;? echo date(&quot;F j, Y, g:i a&quot;); ?&gt;&lt;/div&gt;
&lt;a href=&quot;?cPub=addnew&quot;&gt;&lt;div id=&quot;addnew&quot;&gt;ADD NEW&lt;/div&gt;&lt;/a&gt;
&lt;a href=&quot;?cPub=list&quot;&gt;&lt;div id=&quot;list&quot;&gt;LIST&lt;/div&gt;&lt;/a&gt;
&lt;/div&gt;
&lt;div id=&quot;content&quot;&gt;
&lt;div id=&quot;top-content&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;center-content&quot;&gt;
&lt;div id=&quot;text&quot;&gt;
&lt;?
if($_GET['cPub'] == 'list')
{
if($_GET['cTask'] == 'delete')
{
$CHK = &quot;SELECT * FROM collection WHERE book_id = '$_GET[book_id]'&quot;;
$SQL = &quot;DELETE FROM book WHERE book_id = '$_GET[book_id]'&quot;;
##FIRST CHECK IT FOR COLLECTION
$COLL= $db-&gt;numrows($db-&gt;query($CHK));
if($COLL &gt; 0)
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;You cannot delete BOOK ID = $_GET[book_id]. This record still have $COLL collection data&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
if($QRY = $db-&gt;query($SQL))
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;Successfully Delete for BOOK ID = $_GET[book_id]&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;Error: Delete for BOOK ID = $_GET[book_id]&lt;span&gt;&lt;/p&gt;&quot;;
}
}
}
$SQL = &quot;SELECT * FROM book ORDER BY book_id DESC&quot;;
$QRY = $db-&gt;query($SQL);
$NUM = $db-&gt;numrows($QRY);
$i = 0;
if($NUM &gt; 0)
{
?&gt;
&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellpadding=&quot;4&quot; cellspacing=&quot;1&quot; bgcolor=&quot;#FFFFFF&quot; id=&quot;maintable&quot;&gt;
&lt;tr&gt;
&lt;td width=&quot;5%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;No.&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;47%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Book Title&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;24%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Category&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;10%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Collection&lt;/span&gt;&lt;/td&gt;
&lt;td width=&quot;14%&quot; bgcolor=&quot;#003366&quot;&gt;&lt;span style=&quot;color:#FFFFFF; font-weight:bold;&quot;&gt;Option&lt;/span&gt;&lt;/td&gt;
&lt;/tr&gt;
&lt;?
while($ROW = $db-&gt;fetch($QRY))
{
$i++;
?&gt;
&lt;tr&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;&lt;? echo $i; ?&gt;&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;&lt;? echo $ROW['title']; ?&gt;&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;&lt;?
$CATROW = $db-&gt;fetch($db-&gt;query(&quot;SELECT * FROM category WHERE category_id = '$ROW[category_id]'&quot;));
echo $CATROW['description'];
?&gt;
&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;
&lt;?
##NUMBER OF COLLECTION
$COLLECTION_NUMBER = $db-&gt;numrows($db-&gt;query(&quot;SELECT * FROM collection WHERE book_id = '$ROW[book_id]'&quot;));
echo $COLLECTION_NUMBER;
?&gt;
&lt;/td&gt;
&lt;td bgcolor=&quot;#B7C0FF&quot;&gt;
&lt;a href=&quot;ui-collection.php?book_id=&lt;? echo $ROW['book_id']; ?&gt;&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=500&quot; class=&quot;thickbox&quot; title=&quot;View Collection of &lt;? echo $ROW['title']; ?&gt;&quot;&gt;&lt;img src=&quot;images/zoom16.png&quot; alt=&quot;View Collection&quot; width=&quot;16&quot; height=&quot;16&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;?cPub=edit&amp;amp;book_id=&lt;? echo $ROW['book_id']; ?&gt;&quot; title=&quot;Edit&quot;&gt;&lt;img src=&quot;images/edit.png&quot; alt=&quot;Edit&quot; width=&quot;16&quot; height=&quot;16&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;&amp;nbsp;&amp;nbsp;
&lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;cf=confirm('Are you sure to delete No. &lt;? echo $i; ?&gt; ???');if(cf)window.location='?cPub=list&amp;amp;cTask=delete&amp;amp;book_id=&lt;? echo $ROW['book_id']; ?&gt;';return false;&quot; title=&quot;Delete&quot;&gt;&lt;img src=&quot;images/delete.png&quot; alt=&quot;Delete&quot; width=&quot;16&quot; height=&quot;16&quot; border=&quot;0&quot; /&gt;&lt;/a&gt;
&lt;/td&gt;
&lt;/tr&gt;
&lt;?
}
?&gt;
&lt;/table&gt;
&lt;?
}
else
{
echo &quot;&lt;p&gt;No Query&lt;/p&gt;&quot;;
}
}
elseif($_GET['cPub'] == 'addnew')
{
?&gt;
&lt;?
if($_GET['Submit'] == 'SUBMIT' &amp;&amp; !empty($_GET['title']))
{
##INSERT NEW BOOK
if(!empty($_GET['category_id2']))
{
$choseCat = $_GET['category_id2'];
}
else
{
$choseCat = $_GET['category_id'];
}
$SQL = &quot;INSERT INTO book(title, category_id) VALUES('$_GET[title]', '$choseCat')&quot;;
if($db-&gt;query($SQL))
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;New Record Successfully Submited&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
echo &quot;&lt;p class='msg'&gt;E R R O R !&lt;/p&gt;&quot;;
}
##GET THE LAST ID FOR BOOK RECORD
$BOOKID = $db-&gt;fetch($db-&gt;query(&quot;SELECT * FROM book ORDER BY book_id DESC&quot;));
##INSERT NEW COLLECTION
for($i=0;$i&lt;=count($_GET['collection_data']);$i++)
{
if(!empty($_GET['collection_data'][$i]))
{
$SQLCOLLECTION = &quot;INSERT INTO collection(collection_data, book_id)
VALUES('&quot;.$_GET['collection_data'][$i].&quot;', '$BOOKID[book_id]')&quot;;
$db-&gt;query($SQLCOLLECTION);
}
}
}
?&gt;
&lt;div id=&quot;formM&quot;&gt;
&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;get&quot; action=&quot;&quot;&gt;
&lt;input name=&quot;cPub&quot; type=&quot;hidden&quot; value=&quot;&lt;? echo $_GET['cPub']; ?&gt;&quot; /&gt;
&lt;label&gt;&lt;span&gt;Book Title &lt;/span&gt;
&lt;input name=&quot;title&quot; type=&quot;text&quot; class=&quot;inputM&quot; id=&quot;title&quot; size=&quot;20&quot; /&gt;
&lt;/label&gt;
&lt;label&gt;&lt;span&gt;Category &lt;/span&gt;
&lt;div id=&quot;contenPanCategory&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;toBeHideCategory&quot;&gt;
&lt;select class=&quot;inputM&quot; name=&quot;category_id&quot; size=&quot;1&quot;&gt;
&lt;?
$QRYCAT = $db-&gt;query(&quot;SELECT * FROM category ORDER BY description&quot;);
while($ROWCAT = $db-&gt;fetch($QRYCAT))
{
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT['category_id']; ?&gt;&quot;&gt;&lt;? echo $ROWCAT['description']; ?&gt;&lt;/option&gt;
&lt;?
}
?&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;span class=&quot;note&quot;&gt; (* Your category not listed ? Manage &lt;a href=&quot;category-loader.php?cF=Manage&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=300&quot; class=&quot;thickbox&quot; title=&quot;Manage Category&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;javascript:void(0);&quot; title=&quot;Refresh Category List&quot; onClick=&quot;refreshCategory()&quot;&gt;refresh&lt;/a&gt;&lt;/span&gt;
&lt;/label&gt;
&lt;div class=&quot;spacer&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;Collections &lt;/span&gt;
&lt;div id=&quot;fieldBox&quot;&gt;
&lt;div id=&quot;submenu&quot;&gt;
&lt;div id=&quot;icon&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; onClick=&quot;addFormField(); return false;&quot; title=&quot;Add New Collection&quot;&gt;&lt;img alt=&quot;Add New Collection&quot; src=&quot;images/addplus.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;input type=&quot;hidden&quot; id=&quot;id&quot; value=&quot;1&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;collection&quot;&gt;
&lt;div id=&quot;top-box&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;center-box&quot;&gt;
&lt;div id=&quot;text&quot;&gt;&lt;div id=&quot;divTxt&quot;&gt;&lt;/div&gt;&lt;/div&gt;
&lt;div id=&quot;bottom-box&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/label&gt;
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;
&lt;div class=&quot;spacer&quot;&gt;&lt;/div&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;SUBMIT&quot; class=&quot;buttonM&quot;/&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;?
}
elseif($_GET['cPub'] == 'edit')
{
?&gt;
&lt;?
if($_GET['Submit'] == 'UPDATE' &amp;&amp; !empty($_GET['title']))
{
##UPDATE CURRENT BOOK
if(!empty($_GET['category_id2']))
{
$choseCat = $_GET['category_id2'];
}
else
{
$choseCat = $_GET['category_id'];
}
$SQL = &quot;UPDATE book SET title='$_GET[title]', category_id='$choseCat' WHERE book_id='$_GET[book_id]'&quot;;
if($db-&gt;query($SQL))
{
echo &quot;&lt;p class='msg'&gt;&lt;span&gt;Current Record Successfully Updated&lt;/span&gt;&lt;/p&gt;&quot;;
}
else
{
echo &quot;&lt;p class='msg'&gt;E R R O R !&lt;/p&gt;&quot;;
}
}
?&gt;
&lt;?
$SQL = &quot;SELECT * FROM book WHERE book_id = '$_GET[book_id]'&quot;;
$ROW = $db-&gt;fetch($db-&gt;query($SQL));
?&gt;
&lt;div id=&quot;formM&quot;&gt;
&lt;form id=&quot;form1&quot; name=&quot;form1&quot; method=&quot;get&quot; action=&quot;&quot;&gt;
&lt;input name=&quot;cPub&quot; type=&quot;hidden&quot; value=&quot;&lt;? echo $_GET['cPub']; ?&gt;&quot; /&gt;
&lt;input name=&quot;book_id&quot; type=&quot;hidden&quot; value=&quot;&lt;? echo $_GET['book_id']; ?&gt;&quot; /&gt;
&lt;label&gt;&lt;span&gt;Book Title &lt;/span&gt;
&lt;input name=&quot;title&quot; value=&quot;&lt;? echo $ROW['title']; ?&gt;&quot; type=&quot;text&quot; class=&quot;inputM&quot; id=&quot;title&quot; size=&quot;20&quot; /&gt;
&lt;/label&gt;
&lt;label&gt;&lt;span&gt;Category &lt;/span&gt;
&lt;div id=&quot;contenPanCategory&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;toBeHideCategory&quot;&gt;
&lt;select class=&quot;inputM&quot; name=&quot;category_id&quot; size=&quot;1&quot;&gt;
&lt;?
$SQLCAT_CUR = &quot;SELECT * FROM category WHERE category_id = '$ROW[category_id]'&quot;;
$ROWCAT_CUR = $db-&gt;fetch($db-&gt;query($SQLCAT_CUR));
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT_CUR['category_id']; ?&gt;&quot;&gt;- &lt;? echo $ROWCAT_CUR['description']; ?&gt; -&lt;/option&gt;
&lt;?
$SQLCAT = &quot;SELECT * FROM category ORDER BY description&quot;;
$QRYCAT = $db-&gt;query($SQLCAT);
while($ROWCAT = $db-&gt;fetch($QRYCAT))
{
?&gt;
&lt;option value=&quot;&lt;? echo $ROWCAT['category_id']; ?&gt;&quot;&gt;&lt;? echo $ROWCAT['description']; ?&gt;&lt;/option&gt;
&lt;?
}
?&gt;
&lt;/select&gt;
&lt;/div&gt;
&lt;span class=&quot;note&quot;&gt; (* Your category not listed ? Manage &lt;a href=&quot;category-loader.php?cF=Manage&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=300&quot; class=&quot;thickbox&quot; title=&quot;Manage Category&quot;&gt;here&lt;/a&gt; and &lt;a href=&quot;javascript:void(0);&quot; title=&quot;Refresh Category List&quot; onClick=&quot;refreshCategory()&quot;&gt;refresh&lt;/a&gt;&lt;/span&gt;
&lt;/label&gt;
&lt;div class=&quot;spacer&quot;&gt;&amp;nbsp;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;Collections &lt;/span&gt;
&lt;div id=&quot;fieldBox&quot;&gt;
&lt;div id=&quot;submenu&quot;&gt;
&lt;div id=&quot;icon&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; title=&quot;Refresh Collection Data&quot; onClick=&quot;refreshCollection(&lt;? echo $ROW['book_id']; ?&gt;, 0)&quot;&gt;&lt;img alt=&quot;Refresh Collection Data&quot; src=&quot;images/refresh.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div id=&quot;icon&quot; class=&quot;space&quot;&gt;&lt;a href=&quot;ui-collection.php?cF=Input&amp;amp;book_id=&lt;? echo $ROW['book_id'];?&gt;&amp;amp;keepThis=true&amp;amp;TB_iframe=true&amp;amp;height=250&amp;amp;width=300&quot; class=&quot;thickbox&quot; title=&quot;Add New Collection&quot;&gt;&lt;img alt=&quot;Add New Collection&quot; src=&quot;images/addplus.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;div id=&quot;icon&quot; class=&quot;space&quot;&gt;&lt;a href=&quot;javascript:void(0);&quot; onclick=&quot;cf=confirm('Are you sure to remove all collection data ???');if(cf)refreshCollection(&lt;? echo $ROW['book_id']; ?&gt;, 1);return false;&quot; title=&quot;Remove All Collection&quot;&gt;&lt;img alt=&quot;Remove All Collection&quot; src=&quot;images/remove.gif&quot; width=&quot;32&quot; height=&quot;29&quot; /&gt;&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;collection&quot;&gt;
&lt;div id=&quot;top-box&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;center-box&quot;&gt;
&lt;div id=&quot;text&quot;&gt;
&lt;div id=&quot;contenPanCollection&quot;&gt;&lt;/div&gt;
&lt;div id=&quot;toBeHideCollection&quot;&gt;
&lt;iframe width=&quot;300&quot; name=&quot;refreshCollectionFrame&quot; src=&quot;ui-collection.php?book_id=&lt;? echo $ROW['book_id']; ?&gt;&quot; frameborder=&quot;0&quot; scrolling=&quot;auto&quot;&gt;
&lt;/iframe&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;bottom-box&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/label&gt;
&lt;div class=&quot;clear&quot;&gt;&lt;/div&gt;
&lt;label&gt;&lt;span&gt;&amp;nbsp; &lt;/span&gt;
&lt;div class=&quot;spacer&quot;&gt;&lt;/div&gt;&lt;input type=&quot;submit&quot; name=&quot;Submit&quot; value=&quot;UPDATE&quot; class=&quot;buttonM&quot;/&gt;
&lt;/label&gt;
&lt;/form&gt;
&lt;/div&gt;
&lt;?
}
else
{
echo &quot;&lt;p&gt;You are in Administrator Page. Select Main Menu to Manage your data.&lt;/p&gt;&quot;;
}
?&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;bottom-content&quot;&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;div id=&quot;footer&quot;&gt;
&amp;copy; Copyright 2009 dr.emi creative design { &lt;a href=&quot;https://www.dremi.info&quot; target=&quot;_blank&quot;&gt;www.dremi.info&lt;/a&gt; }
&lt;/div&gt;
&lt;/div&gt;
&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

Oukeh!!!! I think all hand code was appear on your apache server. Try it with type this URL on your browser:
http://localhost/foldername/index.php
And this is screenshoot of Index.php within load default content

Just click on main menu to try the result of dynamic content.
Screenshoot for Add New Record

Screenshoot for Listing Record

Screenshoot for View Collection Data, using unit interface

Screenshoot for Dynamic Refresh of Collection Data

Feel free to try the demo on my demo page, and do not forget to leave your comment for suggest, critics, report or bug.
Now, you has been successfully to create your Administrator Page to Manage Some Relation Table Using PHP as main programming language and jQuery to give some interactivity result for dynamic form.
Regard, Hairul Azami a.k.a dr.emi

22 thoughts on “Building Administrator Manager for Table Relation Using PHP and jQuery”

  1. Siiiipp.. Tambah terus ya tutorial yang kayak gini. Palagi kalo tambah jquery. ajiiiiiibbb.
    Walaupun sebenernya gak gitu ngerti. tp ya OK-lah.. yg penting Demo-nya mantab

  2. Dr. Emi… saya mo request tutorial neh.. boleh khan….? saya kpengen tau gmana cara membuat “kategori” yang ada pd situs ini, yg brada di “pojok kanan bawah” yg bergambar kotak kearanjang barang… kasih tau donk ilmunya…. bagus tuh tampilannya…. saya jd ngiler kpengen punya juga hehehe…..

Leave a Reply

Your email address will not be published. Required fields are marked *