从MySQL中提取数据并使用php中的表ID在表格中显示?

时间:2014-03-26 11:28:01

标签: php mysql sql

有人可以告诉我如何使用id="datatable"表来显示$output

中的内容

如果无法回答这个问题,那么请告诉我:有没有办法使用像" {CONTENT} ".这样的变量动态显示整个内容

我该怎么做?

这是我的代码:

case "user_outgoing_full":
    $base_url = "index.php?app=menu&inc=user_outgoing&op=user_outgoing_full";

    $content = "
        <h2>Outgoing SMS Full Report</h2>
        <table cellpadding=\"0\" cellspacing=\"0\" border=\"0\" class=\"pretty\" id=\"datatable\" style=\"width:100%;table-layout:fixed\">
        <thead>
        <tr>
            <th>Time</th>
            <th>To</th>
            <th>Message</th>
            <th>Update</th>
            <th style=\"width:7%\">Count</th>
            <th style=\"width:10%\">Status</th>
            <th style=\"width:10%\">Action</th>
        </tr>
        </thead>    
        <thead> 
        <tr>
            <th></th>
        </tr>
        </thead>
        <tbody>
        </tbody>
        </table>";
    if ($err = $_SESSION['error_string']) {
        echo "<div class=error_string>$err</div>";
    }
    echo $content;
    break;
case "user_outgoing_full_data":
        ob_start( 'ob_gzhandler' );
    header( 'Content-type: application/json; charset=UTF-8' );
    header( 'Content-Encoding: gzip' );
    $db_query = "SELECT * FROM "._DB_PREF_."_tblSMSOutgoing"." WHERE uid=".$uid." AND flag_deleted=0 group by p_msg,p_datetime,uid,flag_deleted";
    $db_result = dba_query($db_query);
    while ($db_row = dba_fetch_array($db_result)) {
        $list[] = $db_row;
    }
    $j=0;
    $maxcount = count($list);
    $output = array(
    "sEcho" => intval($_GET['sEcho']),
    "iTotalRecords" => $maxcount,
    "iTotalDisplayRecords" => $maxcount,
    "aaData" => array()
    );
    for ($j=0;$j<$maxcount;$j++) {
        $row = array();
        $list[$j] = core_display_data($list[$j]);
        $smslog_id = $list[$j]['smslog_id'];
        $c_count=$list[$j]['count'];
        $p_dst = $list[$j]['p_dst'];
        $p_desc = phonebook_number2name($p_dst);
        $current_p_dst = $p_dst;
        if ($p_desc) {
            $current_p_dst = "$p_dst<br />$p_desc";
        }
        $p_sms_type = $list[$j]['p_sms_type'];
        if (($p_footer = $list[$j]['p_footer']) && (($p_sms_type == "text") || ($p_sms_type == "flash"))) {
            $p_msg = $p_msg.' '.$p_footer;
        }
        $p_datetime = core_display_datetime($list[$j]['p_datetime']);
        $p_update = core_display_datetime($list[$j]['p_update']);
        $p_status = $list[$j]['p_status'];
        $p_gpid = $list[$j]['p_gpid'];
        // 0 = pending
        // 1 = sent
        // 2 = failed
        // 3 = delivered
        // 4 = DND
        /*if ($p_status == "1") {
            $p_status = "<span class=status_sent />";
        } else if ($p_status == "2") {
            $p_status = "<span class=status_failed />";
        } else if ($p_status == "3") {
            $p_status = "<span class=status_delivered />";
        } else {
            $p_status = "<span class=status_pending />";
        }
        $p_status = strtolower($p_status);*/
        if ($p_status == "1") {
            $p_status = "SENT";
        } else if ($p_status == "2") {
            $p_status = "FAILED";
        } else if ($p_status == "3") {
            $p_status = "DELIVERED";
        } else if ($p_status == "4") {
            $p_status = "DND";
        } else {
            $p_status = "PENDING";
        }
        if ($p_gpid) {
            $p_gpcode = strtoupper(phonebook_groupid2code($p_gpid));
        } else {
            $p_gpcode = "&nbsp;";
        }
        $msg = $list[$j]['p_msg'];
        $p_msg = core_display_text($msg);
        if ($msg && $p_dst) {
            $resend = _a('index.php?app=menu&inc=send_sms&op=sendsmstopv&do=reply&message='.urlencode($msg).'&to='.urlencode($p_dst), $core_config['icon']['resend']);
            $forward = _a('index.php?app=menu&inc=send_sms&op=sendsmstopv&do=forward&message='.urlencode($msg), $core_config['icon']['forward']);
        }
        $c_option = $resend."&nbsp".$forward;

        $row[] = $p_datetime;
        $row[] = $current_p_dst;
        $row[] = $p_msg;
        $row[] = $p_update;
        $row[] = $c_count;
        $row[] = $p_status;
        $row[]=  $c_option;
        $output['aaData'][] = $row;
    }
    echo json_encode( $output );
    exit();
    break;

1 个答案:

答案 0 :(得分:0)

你必须使用javascript

此代码位于jquery,javascript库

function newTable(value1,value2){

    $.ajax({
       type:"POST",
       url:"../yourDirectory/your.php",
       data: {var1: value1,
              var2: value2
       },
       success:function(data){
               $("#datatable").html( data ) ;
       } 
   });
}

数据中的代码:{}是php的变量,在你的代码$ _REQUEST [“var1”]中  或$ _REQUEST [“var2”]。 对于来自php的新表,你必须调用函数newTable()