เราจะใส่ลิ้งใน array ยังไงเหรอครับ

เริ่มโดย Fallen, 23 สิงหาคม 2018, 18:50:42

หัวข้อก่อนหน้า - หัวข้อถัดไป

0 สมาชิก และ 1 ผู้มาเยือน กำลังดูหัวข้อนี้

Fallen

เราจะใส่ลิ้งใน array ได้ยังไงครับ
<a href="edit.php">Edit</a>


$columns = array(
  array( 'db' => 'id_msg','dt' => 0),
  array( 'db' => 'id', 'dt' => 1 ),
  array( 'db' => 'id_board',  'dt' => 2 ),
  array( 'db' => 'subject',   'dt' => 3 ),
  array( 'db' => 'poster_time', 'dt' => 4 ),
  array( 'db' => 'modified_time','dt' => 5 ),

  );


:P
 
 
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

thanoo001

ยังงงว่าจะทำอะไร ที่ถามมาไม่ชัดเจน คือจะเอาอะไรไปใส่อะไร ถ้าจะทำ array_merge ก็ประมาณนี้
$columns = array(
  array( 'db' => 'id_msg','dt' => 0),
  array( 'db' => 'id', 'dt' => 1 ),
  array( 'db' => 'id_board',  'dt' => 2 ),
  array( 'db' => 'subject',   'dt' => 3 ),
  array( 'db' => 'poster_time', 'dt' => 4 ),
  array( 'db' => 'modified_time','dt' => 5 ),

  );
$arr = array(array( 'db' => 'id_msg','dt' => 'edit.php'));
$array_merge = array_merge($columns,$arr);
ถ้าไม่ใช่ก็อธิบายให้ชัดหน่อยจะทำอะไร
[direct=https://animereturn.com]อนิเมะ[/direct]

mean


$columns = array(
  array( 'db' => 'id_msg','dt' => 0),
  array( 'db' => 'id', 'dt' => 1 ),
  array( 'db' => 'id_board',  'dt' => 2 ),
  array( 'db' => 'subject',   'dt' => 3 ),
  array( 'db' => 'poster_time', 'dt' => 4 ),
  array( 'db' => 'modified_time','dt' => 5 ),

  );

foreach($columns as $value)
{
echo "<a href="edit.php?db={$value['db']}&dt={$value['dt']}">Edit</a>\n";
}

ต้องการแบบนี้หรือป่าวครับ


[direct=https://www.ireallyhost.com/]บริการโดเมน, เว็บโฮสติ้ง, SSL Certificate[/direct]
[direct=https://www.ireallyhost.com/ssl]บริการ SSL Certificate , HTTPS สำหรับเว็บไซต์[/direct]
[direct=https://www.ireallyhost.com/]บริการ Web Hosting Free! Domain name ตลอดอายุบริการ [/direct]
[direct=https://www.ireallyhost.com/domain]บริการ จดโดเมน, Free DNS Service, Domain Forwarding, จัดการโดเมนได้เอง Domain Control Panel[/direct

Fallen

อ้างถึงจาก: mean ใน 23 สิงหาคม 2018, 21:16:39

$columns = array(
  array( 'db' => 'id_msg','dt' => 0),
  array( 'db' => 'id', 'dt' => 1 ),
  array( 'db' => 'id_board',  'dt' => 2 ),
  array( 'db' => 'subject',   'dt' => 3 ),
  array( 'db' => 'poster_time', 'dt' => 4 ),
  array( 'db' => 'modified_time','dt' => 5 ),

  );

foreach($columns as $value)
{
echo "<a href="edit.php?db={$value['db']}&dt={$value['dt']}">Edit</a>\n";
}

ต้องการแบบนี้หรือป่าวครับ

เอ๊ คือมันจะเป็นแบบนี้ครับ (Demo)
http://sysapp.itoffside.com/datatables/




แต่มันคลิ๊กลิ้งไม่ได้
ผมจะคลิ๊กจากหัวข้อกระทู้ไปที่ id ของกรทู้นั้น เพื่อเปิดหน้าเนื้อหาครับ
จึงไม่รู้จะใส่ โค๊ดลิ้งที่ไหนครับ

:P

โค๊ดเต็มของไฟล์นี้คือแบบนี้ครับ

<?php
//ชื่อตาราง
$table 'datatables_demo';
//ชื่อคีย์หลัก
$primaryKey 'id';
//ข้อมูลอะเรที่ส่งป datables
$columns = array(
  array( 
'db' => 'first_name''dt' => ),
  array( 
'db' => 'last_name',  'dt' => ),
  array( 
'db' => 'position',   'dt' => ),
  array( 
'db' => 'office',     'dt' => ),
  array(
    
'db' => 'start_date',
    
'dt' => 4,
    
'formatter' => function( $d$row ) {
      return 
date'jS M y'strtotime($d));
    }
  ),
  array(
    
'db' => 'salary',
    
'dt' => 5,
    
'formatter' => function( $d$row ) {
      return 
'$'.number_format($d);
    }
    )
  );
 
  
//เชื่อต่อฐานข้อมูล
  
$sql_details = array(
    
'user' => 'root',
    
'pass' => '',
    
'db'   => 'datatables',
    
'host' => 'localhost'
  
);
  
// เรียกใช้ไฟล์ spp.class.php
  
require( 'ssp.class.php' );
 
//ส่งข้อมูลกลับไปเป็น JSON โดยข้อมูลถูกดึงมาจากการเรียกใช้ class ssp
  
echo json_encode(
      
SSP::simple$_GET$sql_details$table$primaryKey$columns )
  );


หน้าเว็บโค๊ดนี้
https://www.itoffside.com/howto-datatables-retrieve-data-ajax/

:wanwan017:
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

mean



[direct=https://www.ireallyhost.com/]บริการโดเมน, เว็บโฮสติ้ง, SSL Certificate[/direct]
[direct=https://www.ireallyhost.com/ssl]บริการ SSL Certificate , HTTPS สำหรับเว็บไซต์[/direct]
[direct=https://www.ireallyhost.com/]บริการ Web Hosting Free! Domain name ตลอดอายุบริการ [/direct]
[direct=https://www.ireallyhost.com/domain]บริการ จดโดเมน, Free DNS Service, Domain Forwarding, จัดการโดเมนได้เอง Domain Control Panel[/direct

Fallen

#5
อ้างถึงจาก: mean ใน 23 สิงหาคม 2018, 22:11:44
ดูตามคู่มือนี้ทำง่ายกว่าครับ
https://datatables.net/examples/ajax/simple.html

:wanwan017: :wanwan017:
นี่ต้นฉบับเลยนี่นา ขอบคุณครับ +1

อันนี้ใช่ไหมครับ

$(document).ready(function() {
   $('#example').DataTable( {
       "processing": true,
       "serverSide": true,
       "ajax": {
           "url": "scripts/post.php",
           "type": "POST"
       },
       "columns": [
           { "data": "first_name" },
           { "data": "last_name" },
           { "data": "position" },
           { "data": "office" },
           { "data": "start_date" },
           { "data": "salary" }
       ]
   } );
} );

:wanwan019:

ลองแล้วใช้ไม่ได้อ่ะครับ
:P
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

gilbert

หน้า php ต้อง return json รูปแบบนี้ครับ

{"draw":1,"recordsTotal":57,"recordsFiltered":57,
     "data":[["Airi","Satou","Accountant","Tokyo","28th Nov 08","$162,700"],
                ["Angelica","Ramos","Chief Executive Officer (CEO)","London","9th Oct 09","$1,200,000"],
                ["Ashton","Cox","Junior Technical Author","San Francisco","12th Jan 09","$86,000"],
                ["Bradley","Greer","Software Engineer","London","13th Oct 12","$132,000"],
                ["Brenden","Wagner","Software Engineer","San Francisco","7th Jun 11","$206,850"],
                ["Brielle","Williamson","Integration Specialist","New York","2nd Dec 12","$372,000"],
                ["Bruno","Nash","Software Engineer","London","3rd May 11","$163,500"],
                ["Caesar","Vance","Pre-Sales Support","New York","12th Dec 11","$106,450"],
                ["Cara","Stevens","Sales Assistant","New York","6th Dec 11","$145,600"],
                ["Cedric","Kelly","Senior Javascript Developer","Edinburgh","29th Mar 12","$433,060"]]
}

thanoo001

ที่ผมลองดูโค้ด ตัวนี้ไม่สามารถใส่ลิ้งค์ได้ครับ คนทำเขาทำมาเพื่อดึกข้อมูลจาก Database แล้วก็สร้าง Table ขึ้นมา
ถ้าจะทำต้องแก้โค้ดหลายจุดเลยทีเดียว
ที่สงสัยคือ ทำไมไม่ทำขึ้นมาเองครับ เพราะการเชื่อมต่อ ฐานข้อมูลกับ PHP มันก็ไม่ใช่เรื่องยากอะไร
แถมการเขียนโค้ดจริงๆ สั้นกว่าตัวอย่างที่ให้มากว่าเยอะมาก
[direct=https://animereturn.com]อนิเมะ[/direct]

Fallen

อ้างถึงจาก: gilbert ใน 24 สิงหาคม 2018, 09:51:43
หน้า php ต้อง return json รูปแบบนี้ครับ

{"draw":1,"recordsTotal":57,"recordsFiltered":57,
     "data":[["Airi","Satou","Accountant","Tokyo","28th Nov 08","$162,700"],
                ["Angelica","Ramos","Chief Executive Officer (CEO)","London","9th Oct 09","$1,200,000"],
                ["Ashton","Cox","Junior Technical Author","San Francisco","12th Jan 09","$86,000"],
                ["Bradley","Greer","Software Engineer","London","13th Oct 12","$132,000"],
                ["Brenden","Wagner","Software Engineer","San Francisco","7th Jun 11","$206,850"],
                ["Brielle","Williamson","Integration Specialist","New York","2nd Dec 12","$372,000"],
                ["Bruno","Nash","Software Engineer","London","3rd May 11","$163,500"],
                ["Caesar","Vance","Pre-Sales Support","New York","12th Dec 11","$106,450"],
                ["Cara","Stevens","Sales Assistant","New York","6th Dec 11","$145,600"],
                ["Cedric","Kelly","Senior Javascript Developer","Edinburgh","29th Mar 12","$433,060"]]
}

จาเอาไปใส่ไงเหรอคับ  :wanwan004:
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

Fallen

#9
อ้างถึงจาก: thanoo001 ใน 24 สิงหาคม 2018, 11:27:34
ที่ผมลองดูโค้ด ตัวนี้ไม่สามารถใส่ลิ้งค์ได้ครับ คนทำเขาทำมาเพื่อดึกข้อมูลจาก Database แล้วก็สร้าง Table ขึ้นมา
ถ้าจะทำต้องแก้โค้ดหลายจุดเลยทีเดียว
ที่สงสัยคือ ทำไมไม่ทำขึ้นมาเองครับ เพราะการเชื่อมต่อ ฐานข้อมูลกับ PHP มันก็ไม่ใช่เรื่องยากอะไร
แถมการเขียนโค้ดจริงๆ สั้นกว่าตัวอย่างที่ให้มากว่าเยอะมาก

อ้างถึงจาก: thanoo001 ใน 24 สิงหาคม 2018, 11:27:34
ที่ผมลองดูโค้ด ตัวนี้ไม่สามารถใส่ลิ้งค์ได้ครับ คนทำเขาทำมาเพื่อดึกข้อมูลจาก Database แล้วก็สร้าง Table ขึ้นมา
ถ้าจะทำต้องแก้โค้ดหลายจุดเลยทีเดียว
ที่สงสัยคือ ทำไมไม่ทำขึ้นมาเองครับ เพราะการเชื่อมต่อ ฐานข้อมูลกับ PHP มันก็ไม่ใช่เรื่องยากอะไร
แถมการเขียนโค้ดจริงๆ สั้นกว่าตัวอย่างที่ให้มากว่าเยอะมาก

ต้องแก้หลายจุดเลยเหรอครับ เลิกละงั้น 555
:wanwan001:

ไม่ทำขึ้นมาเองเพราะเขียนไม่ค่อยจะเป็นครับ ก็พยายามทำอยู่เรื่อยๆ
เคยทำได้สมัยที่ยังไม่ใช้ MySQLi ตอนนี้ย้ายไป php7 โค๊ดมันรันไม่ได้ ไม่รู้ต้องเปลียนค่าตรงไหน
โค๊ดผมมีไม่กี่ไฟล์เอง ลองเเล้วก็ยังไม่ได้ เลยต้องหาใน กูเกิ้ลหามาหลายวันละครับ เอามาดัดแปลง

ที่ผมแปลกใจอยู่อย่างหนึ่ง คนที่เขาทำ โค๊ดประมาณนี้แจก (code CRUD) แล้วก็ให้คน ได้ศึกษาหรือเข้าเว็บใช้งาน
ทำไม ไม่ทำให้ฟูลออฟชั่นไปเลย (ในแง่การนำไปใช้ที่ครอบคลุมมากขึ้น แต่ไม่มากเกินไป จนไปทับไลน์ของ CMS อื่นๆ)
(ผมชอบ script ไฟล์เล็กๆ น้อยๆ เวลาเจอไวรัสก็แก้ง่าย)

มันน่าติดตาม น่าสนใจกว่าเยอะเลยครับ ถ้าผมเขียนเป็นนะ จะเขียนเป็น EP เลย
EP ต่อไป ก็เพื่ม pagination
EP ต่อไป ก็เพื่ม การแก้ไข
EP ต่อไป ก็เพื่ม ลิ้งไปบทความได้
EP ต่อไป ก็เพื่ม ใส่ login

ทำเป็นแนวทางที่สมบูรณ์ น่าจะจะมีคนเรียนจากในเว็บเยอะ เพราะมันมีอนาคต มันรวมศูนย์
แล้วอาจจะขาย course ออนไลน์ หรือ สอนอะไรที่ advance กว่านั้นเพิ่ม หรือ อาจจะมี แต่ผมยังหาไม่เจอ มีแนะนำไหมครับ
แต่คุ้นๆว่ามีในหนังสือ

บางเว็บก็รัน php7 ไม่ได้ เพราะบทความเก่า ไม่อัพเดท

---
อย่างตัวนี้ มีแบ่งหน้า แต่ใส่ลิ้งไม่เป็น หรือ ใส่ยาก
อีกตัว ใส่ลิ้งได้แต่ไม่มีแบ่งหน้ามาให้
พอหาcode แบ่งหน้าเจอ ก็เอามารวมกันไม่เป็นอีก

ผมจะมาถาม การรวมโค๊ด แบ่งหน้าในอีกกระทู้นะครับ
จะลองพยายามก่อน

:P
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

thanoo001

ลองศึกษาสคริปสำเร็จรูปอย่าง wordpress ดูครับ ผมว่ามันมี API ครบ แถมเวลาจะทำอะไรเราไม่ต้อง Mod ไฟล์ สร้างเพียงปลั๊กอินง่ายๆขึ้นมาแก้ คนที่พอมีพื้นฐานโค้ด PHP Java CSS HTML ก็เขียนได้สบายแล้ว แค่ต้องใช้เวลาศึกษา API ของ Wordpress เท่านั้น โค้ดมีให้อ่านทั่วไป หาง่าย มีครบ ตั้งแต่ Basic ยันไปถึงระดับ Pro
อันนี้บอกต่อแบบคนเขียนโค้ดไม่เป็นนะ มาเป็นตอนศึกษา Wordpress นี่แหละ
[direct=https://animereturn.com]อนิเมะ[/direct]

Fallen

#11
อ้างถึงจาก: thanoo001 ใน 24 สิงหาคม 2018, 12:22:39
ลองศึกษาสคริปสำเร็จรูปอย่าง wordpress ดูครับ ผมว่ามันมี API ครบ แถมเวลาจะทำอะไรเราไม่ต้อง Mod ไฟล์ สร้างเพียงปลั๊กอินง่ายๆขึ้นมาแก้ คนที่พอมีพื้นฐานโค้ด PHP Java CSS HTML ก็เขียนได้สบายแล้ว แค่ต้องใช้เวลาศึกษา API ของ Wordpress เท่านั้น โค้ดมีให้อ่านทั่วไป หาง่าย มีครบ ตั้งแต่ Basic ยันไปถึงระดับ Pro
อันนี้บอกต่อแบบคนเขียนโค้ดไม่เป็นนะ มาเป็นตอนศึกษา Wordpress นี่แหละ

ขอบคุณที่แนะนำ สิ่งดีๆ Wordpress ผมใช้อยู่เหมือนกันครับ อิอิ
แต่ อันนี้ผมเอาไว้ ดึง กระทู้ และ content ของ SMF ที่พังลง ลงใหม่ก็มีปัญหา config ไม่ได้
(ผมตั้งกระทู้ไปก่อนหน้านี้ http://www.thaiseoboard.com/index.php/topic,411596
เข้าใจว่ามันมีปัญหากับ host php7.x บางรุ่น)
ทาง support เองก็พยายามแล้วแต่ก็ยังไม่ไ่ด้ ผมก็เข้าใจ แค่ wordpress ผมมันเร็วกว่าเดิมเท่าตัวนี่ ก็ดีใจละครับ อิอิ

อนาคตอาจจะเอา SMF ออกไป จึงต้องการดึงกระทู้ ใส่ตัวแบ่งหน้า และ ใส่ลิ้งไปหน้าบทความ แค่นั้นเองครับ
ที่มาก็เป็นแบบนี้เเหละครับ ก็เลยต้องถามอะไรไกลตัว ออกทะล อาเร์อะไรเนี่ย 5555
:-X
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

gilbert

ขอโทษทีครับเข้าใจผิด

var table = $('#example').DataTable( {
      "processing": true,
      "serverSide": true,
      "ajax": "server_processing.php",
      "footerCallback": function ( row, data, start, end, display ) {
            var api = this.api(), data;

            // Remove the formatting to get integer data for summation
            var intVal = function ( i ) {
                return typeof i === 'string' ?
                    i.replace(/[\$,]/g, '')*1 :
                    typeof i === 'number' ?
                        i : 0;
            };

            // Total over all pages
            total = api
                .column( 5 )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Total over this page
            pageTotal = api
                .column( 5, { page: 'current'} )
                .data()
                .reduce( function (a, b) {
                    return intVal(a) + intVal(b);
                }, 0 );

            // Update footer
            $( api.column( 5 ).footer() ).html(
                '$'+pageTotal +' total'
            );
        }
    } );

table.on( 'select', function ( e, dt, type, indexes ) {
    if ( type === 'row' ) {
        var data = table.rows( indexes ).data().pluck( 'id' );

        alert(data);
    }
} );

ลองเอาโค้ดไปแทรกใน javascript ดูครับ ไม่แน่ใจว่าเข้าใจหรือเปล่า
ตัว Plug-in มันจะมี Event ให้ใช้งานตามนี้ครับ ลองดูว่ามัน alert value อะไรมา
ถ้าเป็น id ที่เราต้องการก็แก้ตรง alert เป็น window.location = "http:xxx.com?id="+data  แทน
https://datatables.net/reference/event/

Fallen

ผมไปหาต่อ

เขาบอกว่าเอาโค๊ดนี้ใส่ครับ แต่ไม่รู้ใส่ยังตรงไหน

render: function ( data, type, row ) {
  return '<a href="...">'+data+'</a>';
}


https://datatables.net/forums/discussion/45663

อีกคน บอกแบบนี้

{ data: null,
   render: function ( data, type, row ) {
                return '<a href="http://cookies.insites.com/" </a>';
          }
  },


https://datatables.net/forums/discussion/48582

ของคนนี้แก้อย่างเยอะ
https://datatables.net/reference/option/columns.render


อันนี้เป็นของคนสร้างเลย
Generated content for a column
https://datatables.net/release-datatables/examples/ajax/null_data_source.html

$(document).ready(function() {
    var table = $('#example').DataTable( {
        "ajax": "data/arrays.txt",
        "columnDefs": [ {
            "targets": -1,
            "data": null,
            "defaultContent": "<button>Click!</button>"
        } ]
    } );

    $('#example tbody').on( 'click', 'button', function () {
        var data = table.row( $(this).parents('tr') ).data();
        alert( data[0] +"'s salary is: "+ data[ 5 ] );
    } );
} );



เอาไปใส่ตรงไหนน๊าาาา
:wanwan001:
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

sputtaro

#14
ถ้าคุณใช้ PHP, MYSQLI, BOOTSTRAP
ลองเข้าไปดูที่เว็บนี้ก่อนก็ได้นะครับ
https://codersfolder.com/2016/07/crud-with-php-mysqli-bootstrap-datatables-jquery-plugin/

เผื่อจะเข้าใจการประยุกต์ใช้งาน ( หรือบางทีอาจจะเลิกสนใจไปเลย 555 )

*******************************
ตัวอย่างที่ผมปรับใช้ ประมาณนี้ครับ
ผมตัดตอนต้น ส่วนที่ใช้เช็ค login ออกไป
เหลือส่วนล่าง ที่น่าจะตรงกับคำถามของคุณ
( gaDecrypto เป็นฟังชั่นที่ผมทำไว้ Decrypt ข้อมูล)
เมื่อคลิ๊ก Edit มันจะดึงข้อมูลของสมาชิกมาให้แก้ไข ซึ่งกรณีของคุณก็แค่ทำลิ้งไปยังหน้าที่คุณต้องการ
คงพอเข้าใจนะครับ

สรุปง่ายๆ คุณทำให้มันเป็นลิ้งที่คลิ๊กได้ ตั้งแต่ก่อนที่จะ echo json dataนั่นเอง



require_once 'db_connect.php';
$output = array('data' => array());

$sql = "SELECT * FROM site_users";
$query = $connect->query($sql);


$x = 1;
while ($row = $query->fetch_assoc()){
   $Decryptfirstname = $db->gaDecrypto($row['firstname'],$encrypt_method,$hash_algo,$encryption_key,$iv,$htype);
   $Decryptusername = $db->gaDecrypto($row['username'],$encrypt_method,$hash_algo,$encryption_key,$iv,$htype);
   $active = '';
   if($row['active'] == 1) {
      $active = '<span class="badge badge-pill badge-success">Active</span>';
   } else {
      $active = '<span class="badge badge-pill badge-danger">Deactive</span>';
   }

   $actionButton = '
   <div class="btn-group">
     <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
       Action <span class="caret"></span>
     </button>
     <ul class="dropdown-menu">
       <li><a type="button" class="btn btn-warning" data-toggle="modal" data-target="#editMemberModal" onclick="editMember('.$row['uid'].')"> <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</a></li>
       <li><a type="button" class="btn btn-danger" data-toggle="modal" data-target="#removeMemberModal" onclick="removeMember('.$row['uid'].')"> <i class="fa fa-trash-o" aria-hidden="true"></i> Remove</a></li>       
     </ul>
   </div>
      ';

   $output['data'][] = array(
      $x,
      $Decryptfirstname,
      $Decryptusername,   
      $active,
      $actionButton
   );

   $x++;
}
// database connection close
$connect->close();
echo json_encode($output);

sputtaro

อักตัวอย่าง เป็นการเขียนไว้ใน java script


jQuery("#vvideolist").on("click", "#mySKRBtn", function(event) {
         vurl1 = jQuery(this).parents("tr").find("td.one a").attr('rel');
         vtitle1 = jQuery(this).parents("tr").find("td.one a").attr('title');
         vcover1 = jQuery(this).parents("tr").find("td.one img").attr('src');
         jQuery('td.three').html('');
         var vvideolist1 = $(this);   
         //alert(vurl1+'\r\n'+vtitle1+'\r\n'+vcover1);
         //exit();
         jQuery.ajax({
               type: "POST",
            dataType: 'json',
            data: {vurl: vurl1,vtitle: vtitle1,vcover: vcover1},
            url: 'streams/VideoStreamApi.php',
            //cache: false,
            
            success: function(response){
               var videoList = '';
               //var items = response.messages;
               //alert(items[0].source);
               //exit();               
               if(response.success == true) {   
                  var items = response.messages;      
                  jQuery.each(items, function(index,e) {
                     vtitle = e.vtitle;
                     vlink = e.vurl;
                     vcover = e.vcover;
                     videoList = videoList +                  
                     ' <button id="previewBtn" type="button" class="btn btn-success btn-md" data-toggle="modal" data-target="#previewStreamModal" data-title="'+vtitle+'" data-link="'+vlink+'" data-cover="'+vcover+'">View '+vtitle+'</button> ';
                  });                  
                  vvideolist1.parents("tr").find('td.three').html(videoList);               
   
         }               
            },
            
            error: function(){
               alert('error333');
            }   
         });      
         
      });

Fallen

อ้างถึงจาก: sputtaro ใน 24 สิงหาคม 2018, 21:46:41
ถ้าคุณใช้ PHP, MYSQLI, BOOTSTRAP
ลองเข้าไปดูที่เว็บนี้ก่อนก็ได้นะครับ
https://codersfolder.com/2016/07/crud-with-php-mysqli-bootstrap-datatables-jquery-plugin/

เผื่อจะเข้าใจการประยุกต์ใช้งาน ( หรือบางทีอาจจะเลิกสนใจไปเลย 555 )

*******************************
ตัวอย่างที่ผมปรับใช้ ประมาณนี้ครับ
ผมตัดตอนต้น ส่วนที่ใช้เช็ค login ออกไป
เหลือส่วนล่าง ที่น่าจะตรงกับคำถามของคุณ
( gaDecrypto เป็นฟังชั่นที่ผมทำไว้ Decrypt ข้อมูล)
เมื่อคลิ๊ก Edit มันจะดึงข้อมูลของสมาชิกมาให้แก้ไข ซึ่งกรณีของคุณก็แค่ทำลิ้งไปยังหน้าที่คุณต้องการ
คงพอเข้าใจนะครับ

สรุปง่ายๆ คุณทำให้มันเป็นลิ้งที่คลิ๊กได้ ตั้งแต่ก่อนที่จะ echo json dataนั่นเอง



require_once 'db_connect.php';
$output = array('data' => array());

$sql = "SELECT * FROM site_users";
$query = $connect->query($sql);


$x = 1;
while ($row = $query->fetch_assoc()){
   $Decryptfirstname = $db->gaDecrypto($row['firstname'],$encrypt_method,$hash_algo,$encryption_key,$iv,$htype);
   $Decryptusername = $db->gaDecrypto($row['username'],$encrypt_method,$hash_algo,$encryption_key,$iv,$htype);
   $active = '';
   if($row['active'] == 1) {
      $active = '<span class="badge badge-pill badge-success">Active</span>';
   } else {
      $active = '<span class="badge badge-pill badge-danger">Deactive</span>';
   }

   $actionButton = '
   <div class="btn-group">
     <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
       Action <span class="caret"></span>
     </button>
     <ul class="dropdown-menu">
       <li><a type="button" class="btn btn-warning" data-toggle="modal" data-target="#editMemberModal" onclick="editMember('.$row['uid'].')"> <i class="fa fa-pencil-square-o" aria-hidden="true"></i> Edit</a></li>
       <li><a type="button" class="btn btn-danger" data-toggle="modal" data-target="#removeMemberModal" onclick="removeMember('.$row['uid'].')"> <i class="fa fa-trash-o" aria-hidden="true"></i> Remove</a></li>       
     </ul>
   </div>
      ';

   $output['data'][] = array(
      $x,
      $Decryptfirstname,
      $Decryptusername,   
      $active,
      $actionButton
   );

   $x++;
}
// database connection close
$connect->close();
echo json_encode($output);

แบบนี้น่าจะแก้ง่ายกว่า https://datatables.net อีกนะ
ผมจะลองทำตามดู ขอบคุณครับ
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

Fallen

#17
อ้างถึงจาก: sputtaro ใน 24 สิงหาคม 2018, 21:59:54
อักตัวอย่าง เป็นการเขียนไว้ใน java script


jQuery("#vvideolist").on("click", "#mySKRBtn", function(event) {
         vurl1 = jQuery(this).parents("tr").find("td.one a").attr('rel');
         vtitle1 = jQuery(this).parents("tr").find("td.one a").attr('title');
         vcover1 = jQuery(this).parents("tr").find("td.one img").attr('src');
         jQuery('td.three').html('');
         var vvideolist1 = $(this);   
         //alert(vurl1+'\r\n'+vtitle1+'\r\n'+vcover1);
         //exit();
         jQuery.ajax({
              type: "POST",
            dataType: 'json',
            data: {vurl: vurl1,vtitle: vtitle1,vcover: vcover1},
            url: 'streams/VideoStreamApi.php',
            //cache: false,
            
            success: function(response){
               var videoList = '';
               //var items = response.messages;
               //alert(items[0].source);
               //exit();               
               if(response.success == true) {   
                  var items = response.messages;      
                  jQuery.each(items, function(index,e) {
                     vtitle = e.vtitle;
                     vlink = e.vurl;
                     vcover = e.vcover;
                     videoList = videoList +                  
                     ' <button id="previewBtn" type="button" class="btn btn-success btn-md" data-toggle="modal" data-target="#previewStreamModal" data-title="'+vtitle+'" data-link="'+vlink+'" data-cover="'+vcover+'">View '+vtitle+'</button> ';
                  });                  
                  vvideolist1.parents("tr").find('td.three').html(videoList);               
   
         }               
            },
            
            error: function(){
               alert('error333');
            }   
         });      
         
      });

ลองทำแล้วไม่ได้

แต่ผมได้ไอเดียแล้ววววววววว

ผมสร้าง column แล้ว ใส่ code เข้าไปข้างใน
code ที่สำหรับ get id แค่นี้ก็ กด link ไปบทความได้แล้ว รึป่าวครับ

มันก็จะ get id ของ row ข้อมูลนั้นในตาราง โดยเรากำหนดรูปแบบให้ เป็น hyperlink
ง่ายกว่าวิธีการเพิ่มโค๊ดที่ดูเหมือนนว่าซับซ้อนนี้อีก?! แม้จะไม่ใช่วิธีที่ดี อิอิ
:P
[direct=https://www.cymiz.com/]ประกันภัย[/direct]
[direct=https://www.cymiz.com/promotion/]ประกันรถยนต์ พรบ มอเตอร์ไซต์ ราคาสมาชิก[/direct]
[direct=http://cymiz.com/].[direct=http://vir9.com].[/direct][/direct]

netytp


sputtaro

"ผมสร้าง column แล้ว ใส่ code เข้าไปข้างใน
code ที่สำหรับ get id แค่นี้ก็ กด link ไปบทความได้แล้ว รึป่าวครับ"

ใช่แล้วครับ อย่างที่บอกว่า

สรุปง่ายๆ คุณทำให้มันเป็นลิ้งที่คลิ๊กได้ ตั้งแต่ก่อนที่จะ echo json dataนั่นเอง
ก็คือ jQuery DataTable จะนำเอา json data เข้าไปจัดรูปแบบเอง แล้วแสดงผลออกมาเป็นตารางให้เรา
ถ้าต้องการให้เป็นลิ้งคลิ๊กได้ เราก็ทำลิ้งซะ แล้วให้ออกมาเป็น json data

เพียงแต่คุณต้องระวังเรื่อง encode, decode ให้ดีเท่านั้นเอง