Thursday, November 22, 2007

Paging in CodeIgniter PHP

Paging in CodeIgniter PHP


CONTROLLER

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class City extends CI_Controller {
    public function __construct() {
        parent:: __construct();
        $this->load->helper("url");
        $this->load->model("Cities");
        $this->load->library("pagination");
    }
    public function index() {
        $this->load->view('welcome_message');
    }
    public function page() {
        $config = array();
        $config["base_url"] = base_url() . "city/page";
        $config["total_rows"] = $this->Cities->city_record_count();
        $config["per_page"] = 20;
        $config["uri_segment"] = 3;
        $this->pagination->initialize($config);
        $page = ($this->uri->segment(3)) ? $this->uri->segment(3) : 0;
        $data["results"] = $this->Cities->fetch_cities($config["per_page"], $page);
        $data["links"] = $this->pagination->create_links();
        $this->load->view("city_view", $data);
    }
}


MODEL

<?php class Cities extends CI_Model {
    public function __construct() {
        parent::__construct();
        $this->load->library('pagination');
        $this->load->database();
    }
    public function city_record_count() {
        $this->db->where('city_id >', 10);
        $this->db->from('cities');
        return $this->db->count_all_results();
        //return $this->db->count_all("cities");
    }

    public function fetch_cities($limit, $start) {
        $this->db->limit($limit, $start);
        $this->db->where('city_id >', 10);
        $this->db->order_by("city_name", "asc");
        $query = $this->db->get("cities");
        if ($query->num_rows() > 0) {
            foreach ($query->result() as $row) {
                $data[] = $row;
            }
            return $data;
        }
        return false;
   }
}



VIEW

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>Welcome to CodeIgniter</title>
</head>
<body>
 <div id="container">
  <h1>Cities</h1>
  <div id="body">
<?php
foreach($results as $data) {
    echo $data->city_id . " - " . $data->city_name . "<br>";
}
?>
   <p><?php echo $links; ?></p>
  </div>
  <p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
 </div>
</body>
</html>

Tuesday, November 20, 2007

config.getServletContext().getRealPath() is not working

config.getServletContext().getRealPath() is not working

This is the very common problem in Servlet and JSP while you deploy WAR file in tomcat or any other server. to over come this problem just extract the .WAR file in the "tomcat/webapps" directory.
and problem will be solved.


Wednesday, November 14, 2007

Sort Alphanumeric Data in Real Number in Sql

Sort Alphanumeric Data in Real Number in Sql


Suppose you have a table with columns pID Autonumber, registrationNo varchar(50) ,pName varchar(100)
registrationNo value is the first character is alphabets and rest is the number listed below:


pID registrationNo
1,    A1315
2,    A1
3,    A132
4,    A2
5,    A1316
6,    A1317
7,    A1318
8,    A133
9,    A1330
10,   A1331
11,   A3
12,   A1450
13,   A4
14,   A5643
15,   A5
16,   A1390
17,   A6


My client want to see those records in ascending number order as listed below order:
pID registrationNo
2,    A1
4,    A2
11,   A3
13,   A4
15,   A5
17,   A6
3,    A132
8,    A133
9,    A1330
10,   A1331
1,    A1315
5,    A1316
6,    A1317
7,    A1318
16,   A1390
12,   A1450
14,   A5643


but when retrieve the order by registrationNo. records was coming in ascending order,
because registrationNo are not a integer data type , those are Alphanumeric data type.

So how to show the Alphanumeric data in real ascending number order?
I have solved this problem with using listed below Sql. listed below sql will show the records which start with character 'a' :

SELECT pID,CAST(SUBSTRING(registrationNo, 2, 10) AS INT) as registrationNoNew
FROM [patientdb].[dbo].[Patients] where registrationNo like '%a1%' order by registrationNoNew


Tuesday, November 13, 2007

Failed to create sessionFactory object.org.hibernate.MappingException Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister Exception in thread main java.lang.NullPointerException

You can face this problem during Java Hibernate application development:

Failed to create sessionFactory object.org.hibernate.MappingException: Could not get constructor for org.hibernate.persister.entity.SingleTableEntityPersister
Exception in thread "main" java.lang.NullPointerException



Solution:
The most common mistake is that you have you have
missed any one getXXXX() or setXXXX() methods.

So check again your code and make the missed getXXXX() or setXXXX() methods.

Wednesday, October 24, 2007

Send Files to IP address in C#


 Send Files to IP address in C#
=============================

string sourceDir = @"C:\\tt";
string destIP = @"\\10.10.10.10\shared-folder-amit";
string[] sourceFiles = Directory.GetFiles(sourceDir, "*", SearchOption.AllDirectories);
foreach (string files in sourceFiles) {
  string localFile = files.Replace(sourceDir, "");
  if (!Directory.Exists(Path.GetDirectoryName(destIP + "\\" + localFile)))
    Directory.CreateDirectory(Path.GetDirectoryName(destIP + "\\" + localFile));
  File.Copy(files, destIP + "\\" + localFile, true);
}

Tuesday, October 16, 2007

Image rotate in jQuery

Image rotate in jQuery



<!DOCTYPE html>
<html>
<head>
<script type="text/javascript" src="jquery.js"></script>
</head>
<body>
<img style="transform: rotate(285.4deg);" id="myimg"  src="WOW.jpg">
<script type="text/javascript">
    jQuery(function($) {
        $(document).ready(function() {
            window.imagerotate = function () {
                $('#myimg').rotate({
                                angle:0,
                                animateTo:-360,
                                callback: imagerotate,
                                //t: current time,b: beginning value,c: change in value,d: duration
                                easing: function (x,t,b,c,d) {
                                    return c*(t/d)+b+10000;
                                }
                            });
                        };
                        setTimeout('imagerotate()', 1000);
                });
});
</script>
</body></html>

Thursday, September 20, 2007

Floating effect with jQuery

Floating effect with jQuery

Listed below the code for how to make any object float-able in html webpage .

aa.html

<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<!--[if lt IE 9]>
<script src="//html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<script>
//jqfloat.js
(function(e){var t={init:function(t){return this.each(function(){e(this).data("jSetting",e.extend({},e.fn.jqFloat.defaults,t));e(this).data("jDefined",true);var n=e("<div/>").css({width:e(this).outerWidth(true),height:e(this).outerHeight(true),"z-index":e(this).css("zIndex")});if(e(this).css("position")=="absolute")n.css({position:"absolute",top:e(this).position().top,left:e(this).position().left});else n.css({"float":e(this).css("float"),position:"relative"});if((e(this).css("marginLeft")=="0px"||e(this).css("marginLeft")=="auto")&&e(this).position().left>0&&e(this).css("position")!="absolute"){n.css({marginLeft:e(this).position().left})}e(this).wrap(n).css({position:"absolute",top:0,left:0})})},update:function(t){e(this).data("jSetting",e.extend({},e.fn.jqFloat.defaults,t))},play:function(){if(!e(this).data("jFloating")){e(this).data("jFloating",true)}n(this)},stop:function(){this.data("jFloating",false)}};var n=function(t){var r=e(t).data("jSetting");var i=Math.floor(Math.random()*r.width)-r.width/2;var s=Math.floor(Math.random()*r.height)-r.height/2-r.minHeight;var o=Math.floor(Math.random()*r.speed)+r.speed/2;e(t).stop().animate({top:s,left:i},o,function(){if(e(this).data("jFloating"))n(this);else e(this).animate({top:0,left:0},o/2)})};e.fn.jqFloat=function(n,r){var i=e(this);if(t[n]){if(i.data("jDefined")){if(r&&typeof r==="object")t.update.apply(this,Array.prototype.slice.call(arguments,1))}else t.init.apply(this,Array.prototype.slice.call(arguments,1));t[n].apply(this)}else if(typeof n==="object"||!n){if(i.data("jDefined")){if(n)t.update.apply(this,arguments)}else t.init.apply(this,arguments);t.play.apply(this)}else e.error("Method "+n+" does not exist!");return this};e.fn.jqFloat.defaults={width:100,height:100,speed:1e3,minHeight:0}})(jQuery)
</script>
<script>
$(document).ready(function() {
    $('#nato').jqFloat({
        width:10,
        height:50,
        speed:1800
    });
   
    $('#butterfly').jqFloat({
        width:400,
        height:100,
        speed:3500
    });
});
</script>
</head>
<body>
<div id="nato" style="width:106px;height:105px;position:absolute;z-index:8;top:12%;right:15%"><img src="2.jpg"/></div>
    <div id="butterfly" style="width:35px; height:27px; position:absolute; z-index:20; left: 383px; top: 77px;"><img src="butterfly.JPG"/>
   </div>
</body>
</html>

Thursday, September 13, 2007

Date and Time with AM/PM Format in mysql

Date and Time with AM/PM Format in mysql:
use listed below sql:



SELECT DATE_FORMAT(my_entry_date_time, '%d/%M/%Y %r') FROM my_table

Tuesday, August 14, 2007

Show mysql timestamp/datetime column with AM and PM in JSP/JAVA


How to show mysql timestamp/datetime column with AM and PM in JSP/JAVA

<%@ page import="java.sql.*" %>
<%@ page import="java.util.Date.*" %>
<%@ page import="java.util.Calendar" %>
<%@ page import="java.util.GregorianCalendar" %>
<%@ page import="java.text.*" %>


SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
java.util.Date date = format.parse(rs.getString("entry_date_time"));
GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(date);
out.print(calendar.get(Calendar.DATE)+"/");
out.print((calendar.get(Calendar.MONTH)+1)+"/");
out.print(calendar.get(Calendar.YEAR)+"&nbsp;&nbsp;&nbsp;");
out.print(calendar.get(Calendar.HOUR)+":");
out.print(calendar.get(Calendar.MINUTE)+":");   
out.print(calendar.get(Calendar.SECOND));       
if(calendar.get(Calendar.AM_PM)==0) out.print("AM"); else out.print("PM");   

Wednesday, July 11, 2007

Submit form with jQuery

Submit form with jQuery


posting.php file
<script language="javascript" src="js/jquery-1.6.3.min.js" type="text/javascript"></script>
<form id="myform" name="myform" action="postdata.php" method="post">
  <input type="text" id="nm" name="nm" />
  <input type="submit" value="Go" />
  <span id="errorspan"></span>
</form>
<div id="banner">
  Submit form with jQuery.
</div>
<script>
$('#myform').submit(function() {
  if($("#nm").val()=="") {
      $("#errorspan").text("Not valid!").show().fadeOut(3000);
      return false;
  } else {
      return true;
  }
});

$('#banner').click(function() {
  $('#myform').submit();
});
</script>



postdata.php file
<?php
echo $_POST['nm'];


?>


Wednesday, July 4, 2007

Show all objects of LDAP Server in PHP

Show all objects of LDAP Server in PHP

<?php
//$ldapServer = "ldap://111.222.111.222:389";

$ldapServer = '111.222.111.222';
$ldapBase = 'DC=abc,DC=com';
$ldapConn = ldap_connect($ldapServer);
if (!$ldapConn)
{
  die('Cannot Connect to LDAP server');
}
$ldapBind = ldap_bind($ldapConn);
if (!$ldapBind) {
  die('Cannot Bind to LDAP server');
}
ldap_set_option($ldapConn, LDAP_OPT_PROTOCOL_VERSION, 3);
$ldapSearch = ldap_search($ldapConn, $ldapBase, "(cn=*)");
$ldapResults = ldap_get_entries($ldapConn, $ldapSearch);
for ($item = 0; $item < $ldapResults['count']; $item++) {
  for ($attribute = 0; $attribute < $ldapResults[$item]['count']; $attribute++) {
    $data = $ldapResults[$item][$attribute];
    echo $data.":&nbsp;&nbsp;".$ldapResults[$item][$data][0]."<br>";
  }
  echo '<hr />';
}
?>

Wednesday, June 13, 2007

make single line paragraph in word

Make single line paragraph in word. 

There is a very common double paragraph problem in Microsoft word. and you want to set it in single line paragraph. follow the listed below steps.
1) Select the matter which you want to convert in single line paragraph.
2) Right click and select paragraph and set the listed below parameter:

General:::::::::
Alignment: left
Outline level: Bodytext
Indentation::::::
Left=0"    Right=0"   Special=(none)     By=Empty
Mirror indents=uncheck
Spacing::::::::::
Before= 0 pt       After=0 pt   Line Spacing =At least
At=5 pt