Showing posts with label Opensources. Show all posts
Showing posts with label Opensources. Show all posts

Wednesday, December 21, 2011

Using Flexigrid with PHP and MySQL

Flexigrid is a lightweight but rich data grid with resizable columns and a scrolling data to match the headers, plus an ability to connect to an xml based data source using Ajax to load the content.
Features :

  • Resizable columns
  • Resizable height and width
  • Sortable column headers
  • Cool theme
  • Can convert an ordinary table
  • Ability to connect to an ajax data source (XML and JSON[new])
  • Paging
  • Show/hide columns
  • Toolbar (new)
  • Search (new)
  • Accessible API

There are two formats you can get your data return to your page, in JSON or XML.

Follow this link, you can find a sample source code for returning in XML format, and for returning in JSON, follow here.

How it  works:
First, you have to these three lines to your html page

<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.css"> 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> 

Please make sure that you add  <script type="text/javascript" src="jquery.js"></script>  before <script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> since it is using jquery to populate its grid.

then you can add the table definition which you want to show in your web page.
In this following example, the data will display in "flex1" table. 
And the data will be processing in post2.php file and return to your html page in JSON format.

<table id="flex1" style="display:none"></table> 
<script type="text/javascript"> 
$("#flex1").flexigrid({ 
        url: 'post2.php', 
        dataType: 'json', 
        colModel : [ 
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
                ], 
        searchitems : [ 
                {display: 'ISO', name : 'iso'}, 
                {display: 'Name', name : 'name', isdefault: true} 
                ], 
        sortname: "iso", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Countries', 
        useRp: true, 
        rp: 15, 
        showTableToggleBtn: true, 
        width: 700, 
        onSubmit: addFormData, 
        height: 200 
}); 

To get to the point here, please follow below steps to use Flexigrid in your webpage (in php or any languages) with MySQL or any databases.
Let's assume that you already had jquery.js in your root directory.
Step 1:
<link rel="stylesheet" type="text/css" href="flexigrid/css/flexigrid.css"> 
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="flexigrid/js/flexigrid.js"></script> 

Step 2:
<table id="flex1" style="display:none"></table> 
<script type="text/javascript"> 
$("#flex1").flexigrid({ 
        url: 'post2.php', 
        dataType: 'json', 
        colModel : [ 
                {display: 'ISO', name : 'iso', width : 40, sortable : true, align: 'center'}, 
                {display: 'Name', name : 'name', width : 180, sortable : true, align: 'left'}, 
                {display: 'Printable Name', name : 'printable_name', width : 120, sortable : true, align: 'left'}, 
                {display: 'ISO3', name : 'iso3', width : 130, sortable : true, align: 'left', hide: true}, 
                {display: 'Number Code', name : 'numcode', width : 80, sortable : true, align: 'right'} 
                ], 
        searchitems : [ 
                {display: 'ISO', name : 'iso'}, 
                {display: 'Name', name : 'name', isdefault: true} 
                ], 
        sortname: "iso", 
        sortorder: "asc", 
        usepager: true, 
        title: 'Countries', 
        useRp: true, 
        rp: 15, 
        showTableToggleBtn: true, 
        width: 700, 
        onSubmit: addFormData, 
        height: 200 
}); 

**if you want to use xml, just replace
dataType: 'json' with datatype:'xml'.

Steps 3: Create the processing page in php or any language you like.
Here is the sample pages in php format. please find json and xml

You can use $("#flex1").flexReload(); to reload or refresh your flexigrid. But you have to put it in right location in order to use it effectively.

And you can find full sample source codes for flexigrid at https://code.google.com/p/flexigrid/source/browse/#svn%2Ftrunk%2Fdemo

Download flexigrid directly here. or go to flexigrid.info for more detail.

Be remind yourself not to forget ; semi-colon and cases since both javascript and php are case-sensitive scripting engines.

All the best!!! Enjoy!!!



Thursday, December 15, 2011

Create multiple virtual hosts in Apache/XAMPP

I am working with both IIS and Apache, so I assigned port number 9000 to apache web server. You may change as you wish.

Step 1: Please modify your httpd.vhosts as follows :
It is locating under D:\xampp\apache\conf\extra

NameVirtualHost *:9000



<VirtualHost *:9000>
ServerAdmin webmaster@localhost
DocumentRoot D:\YourSite
ServerName yoursite


<Directory "D:\YourSite">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

<VirtualHost *:9000>
ServerAdmin webmaster@localhost
DocumentRoot D:\YourSite1
ServerName yoursite1


<Directory "D:\YourSite1">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>


<VirtualHost *:9000>
ServerAdmin webmaster@localhost
DocumentRoot D:\xampp\htdocs
ServerName localhost


<Directory "D:\xampp\htdocs">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>

Step 2:
Open your notepad with administrator permission, then go to C:\Windows\System32\drivers\etc


and Open that file called hosts and add your virtual hosts as follows

127.0.0.1 yoursite
127.0.0.1 yoursite1

You don't need to add your localhost. 

Now, you can browse your sites as follows

http://yoursite:9000 which will get you to your site hosted on your apache web server.
http://yoursite1:9000 which will get you to your site1.


If you want to go to your xampp page, just browse like http://localhost:9000, then it will get you to this:

And finally you can get to Microsoft IIS by typing http://localhost in your browser's address bar and go.

If you think there is some mistakes in my post, please leave a comment. Thanks.
Enjoy!!!