(codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย ucasino88 » 14/09/2018 1:32 pm

ขอบคุณสำหรับข้อมูลมากครับ

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย supattra_su » 24/08/2018 11:37 am

tsukasaz เขียน:ตอนดึงข้อมูลใน Controller ให้จัดข้อมูลใน ตัวแปร $output ให้อยู่ในรูปแบบ x,x,x

ตอนนี้เขียน

โค้ด: เลือกทั้งหมด

foreach ($data as $key => $row)
{
    $output .= '
        <tr>
            <td>' . $row->nCountCustomer . '</td>
        </tr>
    ';
} 
ลองปรับเป็น

โค้ด: เลือกทั้งหมด

$output = array();
foreach ($data as $key => $row)
{
    $output[] = $row->nCountCustomer;
}
echo implode(',', $output); 


ได้แย้วๆๆๆๆๆ ขอบคุณมากๆค่ะ

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย tsukasaz » 24/08/2018 11:23 am

ตอนดึงข้อมูลใน Controller ให้จัดข้อมูลใน ตัวแปร $output ให้อยู่ในรูปแบบ x,x,x

ตอนนี้เขียน

โค้ด: เลือกทั้งหมด

foreach ($data as $key => $row)
{
    $output .= '
        <tr>
            <td>' . $row->nCountCustomer . '</td>
        </tr>
    ';
}
ลองปรับเป็น

โค้ด: เลือกทั้งหมด

$output = array();
foreach ($data as $key => $row)
{
    $output[] = $row->nCountCustomer;
}
echo implode(',', $output);

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย supattra_su » 24/08/2018 11:08 am

tsukasaz เขียน:ถ้าเป็นแนวนี้ใช้แบบที่เคยแก้ได้ครับ
supattra_su เขียน:

โค้ด: เลือกทั้งหมด

<?php
	class cTpstsalDT extends CI_Controller{

		public function __construct(){
			parent::__construct();
		}
		public function index(){

            $this->load->view('common/index');		
        }
        
    function fetchDT(){

         $output = '';
         $query = '';

         $this->load->model('mTpstsalDT');
         
         if($this->input->post('query')){
            $query = $this->input->post('query');
         }

        $data = $this->mTpstsalDT->FSaTpstsalDT($query);
         
        $tChain = '';
        $nQty = '';
        $nPrice = '';

               foreach($data as $key => $row){    

                     $tChain = $row->tChain;
                     $nQty   = $row->nQty;
                     $nPrice = $row->nPrice;
               }
             
             echo $tChain.",".$nQty.",".$nPrice;
            }
        }
?>

โค้ด: เลือกทั้งหมด

<script>
        $(document).ready(function(){
            load_data_dt();
        });
    function load_data_dt(query){
        $.ajax({
            url:"tpstsalDT",
            method:"POST",
            data:{query:query},
            success:function(data){
            //    data =  "UDF,9,900";
            aData = data.split(',');
            $('#odvChain').html(aData[0]);
            $('#odvnQty').html(aData[1]);
            $('#nPrice').html(aData[2]);

        }
    });
  }
</script>


ไม่น่าได้ค่ะ เพราะมาแค่ คอลัมปเดียว
555
555
56987.png (5.65 KiB) Viewed 1699 times

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย tsukasaz » 24/08/2018 10:53 am

ถ้าเป็นแนวนี้ใช้แบบที่เคยแก้ได้ครับ
supattra_su เขียน:

โค้ด: เลือกทั้งหมด

<?php
	class cTpstsalDT extends CI_Controller{

		public function __construct(){
			parent::__construct();
		}
		public function index(){

            $this->load->view('common/index');		
        }
        
    function fetchDT(){

         $output = '';
         $query = '';

         $this->load->model('mTpstsalDT');
         
         if($this->input->post('query')){
            $query = $this->input->post('query');
         }

        $data = $this->mTpstsalDT->FSaTpstsalDT($query);
         
        $tChain = '';
        $nQty = '';
        $nPrice = '';

               foreach($data as $key => $row){    

                     $tChain = $row->tChain;
                     $nQty   = $row->nQty;
                     $nPrice = $row->nPrice;
               }
             
             echo $tChain.",".$nQty.",".$nPrice;
            }
        }
?>

โค้ด: เลือกทั้งหมด

<script>
        $(document).ready(function(){
            load_data_dt();
        });
    function load_data_dt(query){
        $.ajax({
            url:"tpstsalDT",
            method:"POST",
            data:{query:query},
            success:function(data){
            //    data =  "UDF,9,900";
            aData = data.split(',');
            $('#odvChain').html(aData[0]);
            $('#odvnQty').html(aData[1]);
            $('#nPrice').html(aData[2]);

        }
    });
  }
</script>

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย supattra_su » 24/08/2018 10:30 am

แล้วถ้าแบบแนวตั้งหล่ะค่ะ จะ spit อย่างไหร่ค่ะ
14
14
1234.png (5.38 KiB) Viewed 1702 times
หน้า Controller

โค้ด: เลือกทั้งหมด

<?php
	class cPayChannel extends CI_Controller{

		public function __construct(){
			parent::__construct();
		}
		public function index(){

            $this->load->view('common/index');		
        }
        
    function fetchPayChannel(){

         $output = '';
         $query = '';

         $this->load->model('mPayChannel');
         
         if($this->input->post('query')){
            $query = $this->input->post('query');
         }

        $data = $this->mPayChannel->FSnPayChannel($query);

        $output .= '
          
        ';
        
        if(is_array($data) == 1){
           foreach($data as $key => $row)
           {
           $output .= '
                   <tr>
                       <td>'.$row->nCountCustomer.'</td>
                   </tr>
           ';
           }
        }else{
         $output .= '<tr>
             <td colspan="5">No Data Found</td>
            </tr>';
        }
      
        echo $output;
       }
       
      }
  

?>
หน้า View

โค้ด: เลือกทั้งหมด

<script>
    $(document).ready(function(){
        load_data();
    });

 function load_data(query){
 
    $.ajax({
        url:"nPayment",
        method:"POST",
        data:{query:query},
        success:function(data){
        $('#odvResultxx').html(data);
    }
  });
 }

</script>

โค้ด: เลือกทั้งหมด

<tbody>         
                                   
                                        <tr>
                                            <td style="width:45%">นักศึกษา/อาจารย์</td>
                                            <td class="text-center" id="odvResultxx"></td>
                                        </tr>
                                        <tr>
                                            <td style="width:45%">ลงทะเบียนผ่านบัตรประชาชน</td>
                                            <td style="width:10%" class="text-right" id="#"></td>
                                        </tr>
                                        <tr>
                                            <td>ลงทะเบียนผ่านโซเชียล</td>
                                            <td style="width:10%" class="text-right" id="#"></td>
                                        </tr>
                                    </tbody>

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย supattra_su » 23/08/2018 4:57 pm

tsukasaz เขียน:ในไฟล์ php ตอนแรกที่โพส ไม่ใช่แบบนี้นิครับ แก้กลับเป็นส่งแบบเดิมไหม ที่เป็นโครงตาราง เหมือนจะง่ายกว่านะ
อ่อได้แล้วค่ะขอบคุณนะค่ะ

โค้ด: เลือกทั้งหมด

<?php
	class cTpstsalDT extends CI_Controller{

		public function __construct(){
			parent::__construct();
		}
		public function index(){

            $this->load->view('common/index');		
        }
        
    function fetchDT(){

         $output = '';
         $query = '';

         $this->load->model('mTpstsalDT');
         
         if($this->input->post('query')){
            $query = $this->input->post('query');
         }

        $data = $this->mTpstsalDT->FSaTpstsalDT($query);
         
        $tChain = '';
        $nQty = '';
        $nPrice = '';

               foreach($data as $key => $row){    

                     $tChain = $row->tChain;
                     $nQty   = $row->nQty;
                     $nPrice = $row->nPrice;
               }
             
             echo $tChain.",".$nQty.",".$nPrice;
            }
        }
?>

โค้ด: เลือกทั้งหมด

<script>
        $(document).ready(function(){
            load_data_dt();
        });
    function load_data_dt(query){
        $.ajax({
            url:"tpstsalDT",
            method:"POST",
            data:{query:query},
            success:function(data){
            //    data =  "UDF,9,900";
            aData = data.split(',');
            $('#odvChain').html(aData[0]);
            $('#odvnQty').html(aData[1]);
            $('#nPrice').html(aData[2]);

        }
    });
  }
</script>

Re: (codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย tsukasaz » 23/08/2018 4:19 pm

ในไฟล์ php ตอนแรกที่โพส ไม่ใช่แบบนี้นิครับ แก้กลับเป็นส่งแบบเดิมไหม ที่เป็นโครงตาราง เหมือนจะง่ายกว่านะ

(codeigniter) รบกวนช่วยหน่อยค่ะ ดึงข้อมูลขึ้นมาจาก database แล้วแบ่งข้อมูลต้องทำไงค่ะ

โดย supattra_su » 23/08/2018 4:10 pm

asd
asd
asda.png (1.95 KiB) Viewed 1721 times

หน้า Controller

โค้ด: เลือกทั้งหมด

<?php
	class cTpstsalDT extends CI_Controller{

		public function __construct(){
			parent::__construct();
		}
		public function index(){

            $this->load->view('common/index');		
        }
        
    function fetchDT(){

         $output = '';
         $query = '';

         $this->load->model('mTpstsalDT');
         
         if($this->input->post('query')){
            $query = $this->input->post('query');
         }

        $data = $this->mTpstsalDT->FSaTpstsalDT($query);
         
        $tChain = '';
        $nQty = '';
        $nPrice = '';

               foreach($data as $key => $row){    

                     $tChain = $row->tChain;
                     $nQty   = $row->nQty;
                     $nPrice = $row->nPrice;
               }
            
             echo $tChain;
             echo $nQty;
             echo $nPrice;
            }
        }
?>
หน้า View

โค้ด: เลือกทั้งหมด

<script>
        $(document).ready(function(){
            load_data_dt();
        });
    function load_data_dt(query){
        $.ajax({
            url:"tpstsalDT",
            method:"POST",
            data:{query:query},
            success:function(data){
            $('#odvChain').html(data);
        }
    });
  }
</script>

โค้ด: เลือกทั้งหมด

 <div class="table-responsive">
                                        <p>ยอดขายตามสินค้า </p>
                                        <table class="table table-striped">
                                        <thead>
                                            <tr>
                                            <th>ชื่อสินค้า</th>
                                            <th>จำนวน</th>
                                            <th>มูลค่า</th>
                                            </tr>
                                        </thead>
                                        <tbody>
                                            <tr>
                                                <td style="width:45%" id="odvChain"></td>
                                                <td style="width:10%" class="text-right"></td>
                                                <td style="width:15%" class="text-right"></td>
                                            </tr>
                                        </tbody>
                                        </table>
                                        
                                    </div>

ข้างบน