Showing posts with label Codeigniter PDF File Upload. Show all posts
Showing posts with label Codeigniter PDF File Upload. Show all posts

PHP database while loop value alphabetically view

PHP database while loop value alphabetically view


PHP database while loop value alphabetically view
PHP database while loop value alphabetically view

Today Discussed PHP database while loop value alphabetical Order view how to display this task is view looks nice view and order based view a database value flows this code.

mysql queris: 

$query = "SELECT `primaryid`,`fieldname`,LEFT(`fieldname`, 1) AS `first_char` FROM tbl_name WHERE (UPPER(`fieldname`) BETWEEN 'A' AND 'Z' OR `fieldname` BETWEEN '0' AND '9') ORDER BY `fieldname`"
$queryresult = mysql_query($query);                                          $current_char = '';
                                                                           while ($row = mysql_fetch_assoc($queryresult)) {                       if ($row['first_char'] != $current_char) {
                        $current_char = $row['first_char'];

                        echo '<div class="clearfix"></div><h1>' . strtoupper($current_char) . '</h1>' . '<br />-----<br />';
                    }                                                     <?php echo stripslashes($row['fieldname']); } ?>
Copy and Paste this code this code is example modify queriys field name is your database table current fieldname and tbl_name is your database table name just replace this field. and another part of code is whill loop displaying looping function try this code and more example click here

Codeigniter full featrued JQuery datatables

Codeigniter full featrued JQuery datatables


PHP Codeigniter full featrued Jquery datatables means fetch data display table default set pagination and filter included more featreued in datatable. Create cool full featured datatables for your daily in any Codeigniter  Projects specially CMS and how to add controls.

Codeigniter full featrued JQuery datatables
Codeigniter full featrued JQuery datatables

You are Familiar with Codeigniter
You have a webserver up and running (XAMP,LAMP, AND WAMP Server)

example database code:

CREATE TABLE `demotable` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`first` varchar(100) DEFAULT NULL,
`last` varchar(100) DEFAULT NULL,
`email` varchar(100) DEFAULT NULL,
`date_created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=25 DEFAULT CHARSET=latin1;
insert into `demotable`(`id`,`first`,`last`,`email`,`date_created`) values (23,'Amedd','samy','dev2tricks@gmail.com','2013-03-11 23:11:40');
insert into `demotable`(`id`,`first`,`last`,`email`,`date_created`) values (24,'John','Carter','test@test.com','2013-03-11 23:19:05');
insert into `subscriber`(`id`,`first`,`last`,`email`,`date_created`) values (25,'Lina','Khaled','lina@hotmail.com','2013-03-17 20:54:48');
Download and extract Codeigniter in your root folder

Change base_url  in your application/config/config.php file to

$config['base_url'] = 'http://localhost/tutorial_datatables;

Make sure you set database configuration in your application/config/database.php

-Download ignited datatables library from https://github.com/IgnitedDatatables/Ignited-Datatables

-Copy Datatables.php in application/libraries

-Download Datatables JS plugin from http://www.datatables.net/download/

- Create assets folder with the below structure

Copy jquery.dataTables.min.js   from  DataTables-1.9.4\media\js  to assets\js

-Create a CSS file called style.css in assets/css

body{font-family:Arial,Helvetica,sans-serif;background-color:#F0F0F0;font-size:12px;}
h1{color:#072936;}
.wrapper{width:730px;margin:0 auto;}
footer{border-top:1px solid #CCC;float:right;font-size:12px;width:81%;margin:40px 0 0;padding:10px;}
#big_table_wrapper{background-color:#fff;}
#big_table_wrapper .dataTables_length{float:left;}
#big_table_wrapper .dataTables_filter{float:right;}
#big_Table_wrapper .ui-toolbar{padding:5px;}
#big_table{width:730px;text-align: center;}
.dataTables_paginate .ui-button{margin-right:-.1em!important;}
.paging_full_numbers .ui-button{color:#333!important;cursor:pointer;margin:0;padding:2px 6px;}
.dataTables_info{float:left;width:50%;padding-top:3px;}
.dataTables_paginate{float:right;text-align:right;width:auto;}
.paging_full_numbers{width:350px!important;}
#big_table_processing > img{padding-left:20px;}</code>

-Change the default controller in application/config/routes.php

$route['default_controller'] = "subscriber";

Application/Controller
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Subscriber extends CI_Controller
{
 
    public function __construct()
    {
        parent::__construct();
        $this->load->library('Datatables');
        $this->load->library('table');
        $this->load->database();
    }
 
    function index()
    {
 
        //set table id in table open tag
        $tmpl = array('table_open' => '<table id="big_table" border="1" cellpadding="2" cellspacing="1" class="mytable">');
        $this->table->set_template($tmpl);
 
        $this->table->set_heading('First Name', 'Last Name', 'Email');
 
        $this->load->view('subscriber_view');
    }
 
    //function to handle callbacks
    function datatable()
    {
        $this->datatables->select('id,first,last,email')
            ->unset_column('id')
            ->from('subscriber');
 
        echo $this->datatables->generate();
    }
}

Application/View
<h1>Subscriber management</h1>
<?php echo $this->table->generate(); ?>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        var oTable = $('#big_table').dataTable({
            "bProcessing": true,
            "bServerSide": true,
            "sAjaxSource": '<?php echo base_url(); ?>index.php/subscriber/datatable',
            "bJQueryUI": true,
            "sPaginationType": "full_numbers",
            "iDisplayStart ": 20,
            "oLanguage": {
                "sProcessing": "<img src='<?php echo base_url(); ?>assets/images/ajax-loader_dark.gif'>"
            },
            "fnInitComplete": function () {
                //oTable.fnAdjustColumnSizing();
            },
            'fnServerData': function (sSource, aoData, fnCallback) {
                $.ajax
                ({
                    'dataType': 'json',
                    'type': 'POST',
                    'url': sSource,
                    'data': aoData,
                    'success': fnCallback
                });
            }
        });
    });
</script>
$('#big_table').dataTable
"sAjaxSource":'<?php echo base_url(); ?>index.php/subscriber/datatable'
<?php echo $this->table->generate(); ?>



Codeigniter PDF File Upload

Codeigniter PDF File Upload


PDF File Upload Codeigniter Framework mostly discussed previously and this post is about uploading files in Codeigniter has upload library by using this class we can upload file on server very easily. Codeigniter session Storage

Codeigniter PDF File Upload
Codeigniter PDF File Upload


<?php
echo $error;
echo form_open_multipart('upload/do_upload');
echo form_input(array('type' => 'file','name' => 'userfile'));
echo form_submit('submit','upload');
echo form_close();
?>

Controller method you need to set some config setting like uploading path, allowed types, upload sizes, width height,... etc.

    function upload(){
        $this->load->library('upload');   
        $config['upload_path'] = './assets/certificates/';
        $config['allowed_types'] = 'pdf';
        $config['max_size']    = '1000000';
        $config['file_name'] = "upload";

        $this->upload->initialize($config);
        $certificateflag = $this->upload->do_upload("certificate");       
        if ($this->upload->do_upload("certificate"))
            error_reporting(E_ALL);
        else{
            echo "<pre>"; Print_r($this->upload->data()); echo "</pre>";
        }
}<?php

Library Codeigniter PDF File upload root directory Follows


Open <root_directory>/system/application/config/mimes.php file

Change value of ‘pdf’ element of $mimes array

$mimes = array( ‘hqx’   =>      ‘application/mac-binhex40’,
‘cpt’   =>      ‘application/mac-compactpro’,
‘csv’   =>      array(‘text/x-comma-separated-values’, ‘text/comma-separated-values’, ‘application/octet-stream’, ‘application/vnd.ms-excel’, ‘text/csv’, ‘application/csv’, ‘application/excel’, ‘application/vnd.msexcel’),
‘bin’   =>      ‘application/macbinary’,
‘dms’   =>      ‘application/octet-stream’,
‘lha’   =>      ‘application/octet-stream’,
‘lzh’   =>      ‘application/octet-stream’,
‘exe’   =>      ‘application/octet-stream’,
‘class’ =>      ‘application/octet-stream’,
‘psd’   =>      ‘application/x-photoshop’,
‘so’    =>      ‘application/octet-stream’,
‘sea’   =>      ‘application/octet-stream’,
‘dll’   =>      ‘application/octet-stream’,
‘oda’   =>      ‘application/oda’,
‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’),

To

‘pdf’   =>      array(‘application/pdf’, ‘application/x-pdf’, ‘application/x-download’,’application/x-download’, ‘binary/octet-stream’, ‘application/unknown’, ‘application/force-download’),