doulaozhi6835 2010-09-14 02:44
浏览 78
已采纳

PHP / Codeigniter / jQuery / MySQL的最佳数据访问方法

I'm originally a .NET dev by heart so I've always been use to having ADO.net and LINQ for strongly typed, easy data access into gridviews and other .net controls. In trying to learn PHP and MySQL with CodeIgniter and a dash of jQuery, but I'm having a hard time visualizing my data access methods.

I want to use a PHP or jquery grid for my grid controls (which I rely heavily on). What is the best way to populate them from a MySQL environment? I've heard lots about using JSON but I haven't studied anything on it yet. I'm also pretty sure CodeIgniter does a lot of data access as well.

What direction do I need to be taking this? Thank you Stackoverflow!

  • 写回答

3条回答 默认 最新

  • douyue6520 2010-09-14 06:42
    关注

    Let's get started with this:

    Plain PHP

    <?php
      class Report{
               ….
         public function __construct($city, $sidx, $sord, $_search, $searchField, $searchString, $searchOper){
             //connecting to db, stm, execute query, fetch array from result …..
                echo json_encode(array("name"=>"Alissa", "phone" => "555-55551", "city" => "Sussex");
               //or
                echo json_encode($result);
                //where result is an associative array, codeigniter can map such objects from ORM results
        }
     }
    
     $report = new Report($_GET['city'], $_GET['sidx'], $_GET['sord'], $_GET['_search'],$_GET['searchField'],$_GET['searchString'],$_GET['searchOper'])
    ?>
    

    jQuery/html side using jqGrid

    $("#grid").jqGrid({
           url: 'report.php?city=' + c + '&searchString=null&searchField=null&searchOper=null',
           datatype: 'json',
           mtype: 'GET',
           colNames: ['Name', 'Phone', 'City'],
           colModel: [
                    { name:'rows.name',      index: 'name',   search:true, jsonmap: 'name',  width: 30, align: 'left', sortable:true},
                    { phone:'rows.phone',    index: 'phone',               jsonmap: 'phone', width: 50, align: 'left'},
                    { name:'rows.city',      index: 'city',                jsonmap: 'city',  width: 50, align: 'left', sortable: true},
           pager: '#pager',
           rowNum: 8,
           autowidth: true,
           rowList: [8, 16,32,48],
           sortname: 'name',
           sortorder: 'asc',
           viewrecords: false,
           caption: 'Customer',
           jsonReader : {
                          root: "rows",
                          repeatitems: false
                        },
           height: 650,
           width: 800
     });
    

    No matter what PHP Framework you use, believe me. I use QCubed, sometimes I write plain PDO classes for this.

    You can check this: http://www.codeigniter-jquery.com/codeigniter/using-json-in-codeigniter-with-jquery/

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 vscode的问题提问
  • ¥50 切换TabTip键盘的输入法
  • ¥15 可否在不同线程中调用封装数据库操作的类
  • ¥15 微带串馈天线阵列每个阵元宽度计算
  • ¥15 keil的map文件中Image component sizes各项意思
  • ¥20 求个正点原子stm32f407开发版的贪吃蛇游戏
  • ¥15 划分vlan后,链路不通了?
  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM