Pagination in php

form.php


lt?php
$ColorID = "";
if(!empty($_REQUEST['ID'])) $ColorID = $_REQUEST['ID'];

if(!empty($_REQUEST['ID']))
{
$title = "EDIT COLOR";
$button = "Update";
$closeButton = "javascript:window.close();";

$query = " SELECT * FROM colors WHERE ColorID = '{$_REQUEST['ID']}' ";
$colorPacket = SelectQuery($query);
$thisColorPacket = $colorPacket[0];
}
else
{
$title = "ADD COLOR";
$button = "Insert";
$closeButton = "javascript:history.back();";
}

// variable default section
$colorCode = '';
if(!empty($thisColorPacket['ColorCode'])) $colorCode = $thisColorPacket['ColorCode'];
if(!empty($_REQUEST['colorCode'])) $colorCode = $_REQUEST["colorCode"];
$publish = '';
if(!empty($thisColorPacket['IsActive'])) $publish = $thisColorPacket['IsActive'];
if(!empty($_REQUEST['publish'])) $publish = $_REQUEST["publish"];


// Set the error flags section
if(empty($error)) $error = false;
if(empty($errorMessage)) $errorMessage="";

if(empty($colorCodeError)) $colorCodeError=false;
?gt
ltdiv align="center"gt
lt?php if($error && $errorMessage!=""){?gt
ltdiv class="erroMessage"gt
ltulgt
lt?php print " {$errorMessage}";?gt
lt/ulgt
lt/divgt
lt?php }?gt
lt!-- Build the interface --gt
ltform name="oColorInsertUpdateForm" action="lt?php echo $_SERVER['SCRIPT_NAME'];?gt?skin=admin&area=lt?php echo $_REQUEST['area']; ?gt&action=color-action" method="post"gt
ltfieldset class="fieldDesign3"gt
ltlegend class="legendDesign"gtlt?php echo $title;?gtlt/legendgt
lttable width="0" border="0" cellpadding="4" cellspacing="4" class="formtable"gt
lt?php
if(!empty($_REQUEST['message']))
{
print"
lttr valign=\"top\"gtlttd align=\"center\" colspan=\"2\" style=\"font-weight:bold;color:orange;\"gt{$_REQUEST['message']}
";
}
?gt


lt?php


// the interface for sitefontFamilyName
if($colorCodeError)
{
print "

lttrgtlttd style='color: red;'gtColor Codelt/tdgt
";
}
else
{
print "lttrgtlttdgtColor Codelt/tdgt";
}
print "lttdgtltinput name='colorCode' value='{$colorCode}' type='text' size='60' class='inputText2'gtltspan style='color:red;'gt*lt/spangtlt/tdgtlt/trgt";
?gt
lttrgt
lttdgtPublishlt/tdgt
lttdgt
ltselect name="publish" style="width:70px;" class='inputText2'gt
ltoption value="1" lt?php if($publish == 1) echo "Selected"; ?gtgtEnablelt/optiongt
ltoption value="0" lt?php if($publish == 0) echo "Selected"; ?gtgtDisablelt/optiongt
lt/selectgt
ltspan style="color:red;"gt*lt/spangt
lt/tdgt
lt/trgt
lt!-- the interface for insert, reset or cancel button --gt
lttr height="2"gtlttd colspan="2"gt lt/tdgtlt/trgt
lttrgt
lttdgt lt/tdgt
lttdgt
ltinput name="btnlt?php echo $button;?gt" type="submit" value="lt?php echo $button;?gt" class="inputBtn2"gt
ltinput name="btnReset" type="Reset" class="inputBtn2"gt
ltinput name="btnCancel" type="button" value="Cancel" onclick="lt?php echo $closeButton; ?gt" class="inputBtn2"gt
ltinput type="hidden" name="ID" value="lt?php echo $ColorID;?gt"gt
lt/tdgt
lt/trgt
lt/tablegt
lt/fieldset gt
lt/formgt
lt/divgt





2. select.php


lt?php
/* Set Default Variable */
if (empty($_REQUEST["startValue"])) $_REQUEST["startValue"] = 0;
if (empty($_REQUEST["limitValue"])) $_REQUEST["limitValue"] = 20;
if (empty($_REQUEST["OrderBy"])) $_REQUEST["OrderBy"] = "UserID";
if (empty($_REQUEST["Order"])) $_REQUEST["Order"] = "ASC";
if (empty($_REQUEST["publish"])) $_REQUEST["publish"] = "";


$colorCode = "";
if(!empty($_REQUEST['colorCode'])) $colorCode = $_REQUEST['colorCode'];
$publish = "";
if(!empty($_REQUEST['publish'])) $publish = $_REQUEST['publish'];

?gt

ltpgtltstronggt COLOR MANAGERlt/stronggtlt/pgt
lt!-- Starting the search interface --gt
ltform name="oColorCodeSearchForm" method="post" action="lt?php echo $_SERVER['SCRIPT_NAME']; ?gt?skin=admin&area=lt?php echo $_REQUEST['area']; ?gt&action=lt?php echo $_REQUEST['action']; ?gt"gt
ltpgtPlease select the desired options and press listlt/pgt
lttable width="100%" cellpadding="4" cellspacing="0" class="borderStyle" gt
lttr valign="top"gt
lttdgt
Color Code  
ltinput name="colorCode" value="lt?php echo $colorCode;?gt" type="text" class="inputText2"gt
lt/tdgt
lttdgt
Publish  
ltselect name="publish" class="inputText2"gt
ltoption value="" lt?php if(empty($publish)) echo "Selected";?gtgt lt/optiongt
ltoption value="1" lt?php if($publish == '1') echo "Selected";?gtgtEnablelt/optiongt
ltoption value="0" lt?php if($publish == '0') echo "Selected";?gtgtDisablelt/optiongt
lt/selectgt
lt/tdgt
lttd valign="middle"gt
Records Per Page lt/tdgt
lttd valign="middle"gt
ltselect name="limitValue" class="inputText2"gt
ltoption value="20" lt?php if($_REQUEST['limitValue'] == 20) echo "Selected";?gtgt20lt/optiongt
ltoption value="50" lt?php if($_REQUEST['limitValue'] == 50) echo "Selected";?gtgt50lt/optiongt
ltoption value="100" lt?php if($_REQUEST['limitValue'] == 100) echo "Selected";?gtgt100lt/optiongt
ltoption value="500" lt?php if($_REQUEST['limitValue'] == 500) echo "Selected";?gtgt500lt/optiongt
ltoption value="1000" lt?php if($_REQUEST['limitValue'] == 1000) echo "Selected";?gtgt1000lt/optiongt
lt/selectgt
lt/tdgt
lttd align="right"gtltinput type="Submit" name="btnSubmit" value="View List" class="inputBtn2"gt
lt/tdgt
lt/trgt
lt/tablegt
lt/formgt

lt!-- Do the search only if search button was clicked or show the entire list --gt
lt?php
if(!empty($_REQUEST['btnSubmit']) or true)
{
$query = " SELECT * FROM colors WHERE TRUE ";
if(!empty($_REQUEST['colorCode'])) $query.=" AND LOWER(ColorCode) LIKE LOWER('%{$_REQUEST['colorCode']}%') ";
if(!empty($_REQUEST['publish'])) $query.=" AND IsActive = {$_REQUEST['publish']} ";
$query.=" ORDER BY ColorID ";
//print $query;

$dataPacket = SelectQuery($query);
// Display the record
if($dataPacket != 0)
{
$records=count($dataPacket);
//print $records;
print "
lttable width='100%' border='0' cellspacing='2' cellpadding='4' class='borderStyle' bgcolor='#ffffff'gt
lttr valign='top'gt
lttd colspan='5'gt
lttable width='100%' cellspacing='0' cellpadding='0'gt
lttrgt
lttd align='left'gtList of Record(s)lt/tdgt
lttd align='right'gtTotal of ltstronggt{$records}lt/stronggt record(s) found.lt/tdgt
lt/trgt
lt/tablegt
lt/tdgt
lt/trgt
lttrgt
lttd colspan=4gtlt/tdgtlttd class='main_menu'gt
lta href='{$_SERVER['SCRIPT_NAME']}?skin=admin&area={$_REQUEST['area']}&action=color-form'gtADD NEWlt/agt
lt/tdgt
lt/trgt
lttr style='font-weight:bold;' bgcolor='#00CCFF'gt
lttdgt#lt/tdgt
lttdgtColor Codelt/tdgt
lttdgtCreatedlt/tdgt
lttdgtPublishlt/tdgt
lttd align='center'gtActionlt/tdgt
lt/trgt
";

$flag=false;
foreach($dataPacket as $thisPacket)
{
$url = "{$_SERVER['SCRIPT_NAME']}?skin=admin&area={$_REQUEST['area']}&action=color-form&ID={$thisPacket['ColorID']}";

if($thisPacket['IsActive']==1) $publish="Enable";
if($thisPacket['IsActive']==0) $publish="Disable";

if($flag)
{
$flag=false;
$color="#F7F7F7";
}
else
{
$flag=true;
$color="#EEEEEE";
}

print "
lttr valign='top' bgcolor='{$color}'gt
lttdgt". $thisPacket['ColorID'] ."lt/tdgt
lttdgt". ucwords($thisPacket['ColorCode']) ."lt/tdgt
lttdgt". $thisPacket['DateInserted'] ."lt/tdgt
lttdgt". $publish ."lt/tdgt
lttd align='center' class='main_menu'gt
lta href=\"javascript:popUp('{$url}');\" gtEDITlt/agt
lt/tdgt
lt/trgt
";

}
print "
lttrgt
lttd colspan='4' align='left' class='main_menu'gt
";
/* Start Paging */
$PageNo = 1;
$PageIncrement = 0;
$RowIncrement = $_REQUEST["limitValue"];
$ShowPage = ceil($records/$_REQUEST["limitValue"]);

$ShowstartValue = $_REQUEST["startValue"]+1;

print "Showing results {$ShowstartValue} - ";


if ($_REQUEST["limitValue"] gt $records)
print "{$records} of {$records}";
else
{
$viewValue = $_REQUEST["startValue"] + $_REQUEST["limitValue"];
if ($viewValue gt $records)
print "{$records} of {$records}";
else
print "{$viewValue} of {$records}";
}


print " ";

if($ShowstartValue gt 1)
{
//if(intval($_REQUEST["startValue"] + $RowIncrement) == $records)
//{
// $PreviousLink = $_REQUEST["startValue"];
//}
//else
//{
$PreviousLink = $_REQUEST["startValue"] - $RowIncrement;
//}
print "lta href=\"{$_SERVER['PHP_SELF']}?skin=admin&area={$_REQUEST['area']}&action=site-cat-select&startValue=$PreviousLink&limitValue=$RowIncrement\"gtPreviouslt/agt  ";
}

$NextLink=$_REQUEST["startValue"] + $RowIncrement;
if(intval($records - $NextLink) lt $_REQUEST["limitValue"])
{
$RowIncrement = intval($records - $NextLink);
}
if($NextLink lt $records)
{

print "lta href=\"{$_SERVER['PHP_SELF']}?skin=admin&area={$_REQUEST['area']}&action=site-cat-select&startValue=$NextLink&limitValue=$RowIncrement\"gtNextlt/agt  ";
$RowIncrement = $_REQUEST["limitValue"];
}
/* End Paging */
print "
lt/tdgt
lttd class='main_menu'gt
lta href='{$_SERVER['SCRIPT_NAME']}?skin=admin&area={$_REQUEST['area']}&action=color-form'gtADD NEWlt/agt
lt/tdgt
lt/trgt
lt/tablegt
";
}
else
{
print "
ltdiv style='padding-right:10px; text-align:right;'gt
Total of ltstronggt0lt/stronggt record found.
lta href='{$_SERVER['SCRIPT_NAME']}?skin=admin&area={$_REQUEST['area']}&action=color-form'gtADD NEWlt/agt
lt/divgt
";
}
}
?gt




action.php





lt?php
//Build the server side error check
$error = false;
$errorMessage = "";

// existance check
$table = "colors";
$column = "ColorCode";
$value = trim($_REQUEST['colorCode']);
//$column2 = "CategoryID";
//$value2 = trim($_REQUEST['categoryName']);
if(empty($_REQUEST['ID']) && !empty($_REQUEST['colorCode']))
{
$colorQuery = " SELECT * FROM $table WHERE $column='$value' OR $column='LOWER($value)'";
$colorResult=mysql_query($colorQuery);

if($colorResult != false)
{
$colorRecords = mysql_num_rows($colorResult);
if($colorRecords gt 0)
{
$error = true;
$colorCodeError = true;
$errorMessage.=" ltligtColor Code already exist.lt/ligt";
$thiscolorResult = mysql_fetch_array($colorResult);
if($thiscolorResult['IsActive'] == 0)
{
$errorMessage.=" ltligtPlease enable previous one.lt/ligt";
}
}
}
}
if($_REQUEST['colorCode'] == "")
{
$error = true;
$colorCodeError = true;
$errorMessage.=" ltligtColor Code cannot be empty.lt/ligt";
}


// back to insert user if error occurs
if($error)
{
include "color-form.php";
}
else
{
if(!empty($_REQUEST['ID']))
{
echo $query = "
UPDATE colors
SET
ColorCode = '" . trim($_REQUEST['colorCode']) . "',
IsActive = '" . trim($_REQUEST['publish']) . "',
UserIDUpdated = '" . trim($_SESSION["UserID"]) . "',
DateUpdated = '" . trim(date('Y-m-d H:m:s')) . "'
WHERE ColorID = '{$_REQUEST['ID']}'
";
}
else
{
echo $query = "
INSERT INTO colors
(
ColorCode,
IsActive,
UserIDInserted,
DateInserted
)
VALUES
(
'" . trim($_REQUEST['colorCode']) . "',
'" . trim($_REQUEST['publish']) . "',
'" . trim($_SESSION["UserID"]) . "',
'" . trim(date('Y-m-d H:m:s')) . "'
)
";
}
//exit;
//OperationQuery($query);

$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}?skin=admin&area={$_REQUEST['area']}&action=color-select";
if(!empty($_REQUEST['ID']))
{
$url = "http://{$_SERVER['HTTP_HOST']}{$_SERVER['SCRIPT_NAME']}?skin=admin&area={$_REQUEST['area']}&action=color-form&ID={$_REQUEST['ID']}&message=Successfully updated";
}

print "
ltscript language='JavaScript'gt
lt!--
//window.location='$url';
//--gt
lt/scriptgt
";
}

?gt

0 Response to "Pagination in php"

Post a Comment

powered by Blogger | WordPress by Newwpthemes | Converted by BloggerTheme