weixin_33682719 2017-07-18 07:39
浏览 71

可点击的数据表行

I am having a data table which is fetching its data from MySQL database. In my database i am having a column named as "location" which is a link to some audio file. All the rows in the database are having their respective links to their audio files.What i want is that

  1. When i click on any row of the data table the browser should automatically get redirected to the link of their respective audio files.
  2. The Current link that is stored in the database is for local IP. i want to change the link to my public IP before the user is redirected since the local IP won't work on remote server. Below is my code:

data table.php

 <?php
    /* Database connection start */
    $servername = "localhost";
    $username = "root";
    $password = "";
    $dbname = "vici";

    $conn = mysqli_connect($servername, $username, $password, $dbname) or die("Connection failed: " . mysqli_connect_error());

    /* Database connection end */


    // storing  request (ie, get/post) global array to a variable  
    $requestData= $_REQUEST;


    $columns = array( 
    // datatable column index  => database column name
        0 =>'recording_id', 
        1 => 'call_date',
        2=> 'location',
        3=> 'Agent',
        4=> 'phone'
    );

    // getting total number records without any search
    $sql = "SELECT recording_id, call_date, location,agent,phone";
    $sql.=" FROM goautodial_recordings_view";
    $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
    $totalData = mysqli_num_rows($query);
    $totalFiltered = $totalData;  // when there is no search parameter then total number rows = total number filtered rows.


    $sql = "SELECT recording_id, call_date, location,agent,phone";
    $sql.=" FROM goautodial_recordings_view WHERE 1=1";
    if( !empty($requestData['search']['value']) ) {   // if there is a search parameter, $requestData['search']['value'] contains search parameter
        $sql.=" AND ( recording_id LIKE '".$requestData['search']['value']."%' ";    
        $sql.=" OR call_date LIKE '".$requestData['search']['value']."%' ";
        $sql.=" OR agent LIKE '".$requestData['search']['value']."%' )";
    }
    $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");
    $totalFiltered = mysqli_num_rows($query); // when there is a search parameter then we have to modify total number filtered rows as per search result. 
    $sql.=" ORDER BY ". $columns[$requestData['order'][0]['column']]."   ".$requestData['order'][0]['dir']."  LIMIT ".$requestData['start']." ,".$requestData['length']."   ";
    /* $requestData['order'][0]['column'] contains colmun index, $requestData['order'][0]['dir'] contains order such as asc/desc  */    
    $query=mysqli_query($conn, $sql) or die("employee-grid-data.php: get employees");

    $data = array();
    while( $row=mysqli_fetch_array($query) ) {  // preparing an array
        $nestedData=array(); 

        $nestedData[] = $row["recording_id"];
        $nestedData[] = $row["call_date"];
        $nestedData[] = $row["location"];
        $nestedData[] = $row["agent"];
        $nestedData[] = $row["phone"];

        $data[] = $nestedData;
    }



    $json_data = array(
                "draw"            => intval( $requestData['draw'] ),   // for every request/draw by clientside , they send a number as a parameter, when they recieve a response/data they first check the draw number, so we are sending same number in draw. 
                "recordsTotal"    => intval( $totalData ),  // total number of records
                "recordsFiltered" => intval( $totalFiltered ), // total number of records after searching, if there is no searching then totalFiltered = totalData
                "data"            => $data   // total data array
                );

    echo json_encode($json_data);  // send data as json format

    ?>

index.php

<!DOCTYPE html>
<html>
    <title>GO VOIP</title>
    <head>
        <link rel="stylesheet" type="text/css" href="css/jquery.dataTables.css">
        <script type="text/javascript" language="javascript" src="js/jquery.js"></script>
        <script type="text/javascript" language="javascript" src="js/jquery.dataTables.js"></script>
        <script type="text/javascript" language="javascript" >
            $(document).ready(function() {
                var dataTable = $('#employee-grid').DataTable( {
                    "processing": true,
                    "serverSide": true,
                    "ajax":{
                        url :"employee-grid-data.php", // json datasource
                        type: "post",  // method  , by default get
                        error: function(){  // error handling
                            $(".employee-grid-error").html("");
                            $("#employee-grid").append('<tbody class="employee-grid-error"><tr><th colspan="3">No data found in the server</th></tr></tbody>');
                            $("#employee-grid_processing").css("display","none");

                        }
                    }
                } );

            $('.dataTable').on('click', 'tbody td', function() {

  //get textContent of the TD
  alert('TD cell textContent : ', this.textContent)

  //get the value of the TD using the API 
  ('value by API : ', table.cell({ row: this.parentNode.rowIndex, column : this.cellIndex }).data());
})
            } );
        </script>
        <style>
            div.container {
                margin: 0 auto;
                max-width:760px;
            }
            div.header {
                margin: 100px auto;
                line-height:30px;
                max-width:760px;
            }
            body {
                background: #f7f7f7;
                color: #333;
                font: 90%/1.45em "Helvetica Neue",HelveticaNeue,Verdana,Arial,Helvetica,sans-serif;
            }
        </style>
    </head>
    <body>
        <div class="header"><h1>DataTable demo (Server side) in Php,Mysql and Ajax </h1></div>
        <div class="container">
            <table id="employee-grid"  cellpadding="0" cellspacing="0" border="0" class="display" width="100%">
                    <thead>
                        <tr>
                            <th>Recording ID</th>
                            <th>Call date</th>
                            <th>Location</th>
                            <th>Agent</th>
                            <th>Phone</th>
                        </tr>
                    </thead>
            </table>
        </div>
    </body>
</html>

Below is the Screenshot:

enter image description here

  • 写回答

3条回答 默认 最新

  • weixin_33691598 2017-07-18 07:52
    关注

    You can do it in simple php with eco like:

    echo '<a href="'.$stringwiththelink.'">Name of the song</a>';
    

    If you click on it it will redirect you to the file.

    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料