//Offset string with some chr or number
//I use this script to sort out array in 001 to 100
//if not it will give an order 1,11,13-19 & 2,20-29 like that
$mynumbers = str_pad(10, 2, "0", STR_PAD_LEFT);
// result 0010
$mynumbers = str_pad(10, 5, "0", STR_PAD_LEFT);
// result 0000010
??
How to offset a value with leading 0 or chr


Form Validator
<script Language="JavaScript">
function FormValidator(theForm){
if (theForm.Name.value==""){
alert("Please enter your name.");
theForm.Name.focus();
return (false);
}
if (theForm.Subject.value==""){
alert("Please enter the subject");
theForm.Subject.focus();
return (false);
}
return (true);
}
</script>
<form method="POST" action="add.php" onsubmit="return FormValidator(this)" name="FormName">
<p>
Name : <input type="text" name="Name" size="20"><br>
Subject : <input type="text" name="Subject" size="20"><br>
<input type="submit" value="Submit" name="Submit"> <input type="reset" value="Reset" name="Reset">
</p>
</form>
Array to Single Variable
//Get a form filling from an array and compile in to a single variable with a splitter
//Array to Single Variable
if ($fldUserName) {
$MyUserName="";
foreach ($fldUserName as $key => $val) {
if ($fldUserName[$key]) {
if ($MyUserName) {
$MyUserName = $MyUserName . "|" . $fldUserName[$key];
}else{
$MyUserName = $fldUserName[$key];
}
}
}
}
?>


Get the visitor IP anyhow
<?
function SafIP() {
if (getenv('HTTP_CLIENT_IP')) {
$ip = getenv('HTTP_CLIENT_IP');
}else if (getenv('HTTP_X_FORWARDED_FOR')) {
$ip = getenv('HTTP_X_FORWARDED_FOR');
}else if (getenv('HTTP_X_FORWARDED')) {
$ip = getenv('HTTP_X_FORWARDED');
}else if (getenv('HTTP_FORWARDED_FOR')) {
$ip = getenv('HTTP_FORWARDED_FOR');
}else if (getenv('HTTP_FORWARDED')) {
$ip = getenv('HTTP_FORWARDED');
}else{
$ip = $_SERVER['REMOTE_ADDR'];
}
return $ip;
}
?>


Url Encode and Url Decode
<?
function SafUrlDecode($returnurl){
$returnurl = str_replace("<safras.q>","?",$returnurl);
$returnurl = str_replace("<safras.e>","=",$returnurl);
$returnurl = str_replace("<safras.and>","&",$returnurl);
return $returnurl;
}
function SafUrlEncode($returnurl){
$returnurl = str_replace("?","<safras.q>",$returnurl);
$returnurl = str_replace("=","<safras.e>",$returnurl);
$returnurl = str_replace("&","<safras.and>",$returnurl);
return $returnurl;
}
?>


Basic Database Loop to display records
<?
//You can use the following script to take data from database and list, for each round it will print the tr and also each round column color will be change with the class2 and class 3.
//I am sorry I can now write more about this, this is I am just posting for my reference, if you like you can use this. If you want to know more about this please post a comment, I will try my best to help you (If I am free).
?>
<table border="0" width="100%" cellpadding="5" style="border-collapse: collapse">
<tr>
<td class="class1" align="left" valign="top"><b>Staff Number</b></td>
<td class="class1" align="left" valign="top"><b>First Name</b></td>
<td class="class1" align="left" valign="top"><b>Last Name</b></td>
<td class="class1" align="left" valign="top"><b>Email Address</b></td>
<td class="class1" align="left" valign="top"><b>Date Of Birth</b></td>
</tr>
<?
$sql = "SELECT * FROM tablename ORDER BY fldFirstName ASC";
$result = mysql_query($sql, $db);
$rows = mysql_num_rows($result);
if(mysql_num_rows($result)) {
$howmany = 0;
for ($i = 0; $i < $rows; $i++) {
$data = mysql_fetch_object($result);
$howmany = $howmany + 1;
$MYXXX = $howmany % 2;
switch ($MYXXX) {
case 1:
$MYbgcolor = "class=\"class2\"";
break;
case 0:
$MYbgcolor = "class=\"class3\"";
break;
}
?>
<tr <?=$MYbgcolor?>>
<td align="left" valign="top"><?=$data->EmployeeNo?></td>
<td align="left" valign="top"><?=$data->FirstName?></td>
<td align="left" valign="top"><?=$data->LastName?></td>
<td align="left" valign="top"><?=$data->Email?></td>
<td align="left" valign="top"><?=$data->DateOfBirth?></td>
</tr>
<?
}
}
?>
</table>


Delete records from databse
<?
$query = "DELETE FROM tblName where id='$id'";mysql_query($query, $db);
?>


Update records to databse
<?
$update=mysql_query("update tblName set Name='$Name',Email='$Email' where id='$id'",$db);
?>


Insert new records to database
<?
$sql = "INSERT INTO tblName ";
$sql .= "(Name,Email)";
$sql .= "VALUES('$fldName','$Email')";
$result = mysql_query($sql, $db);
?>

