dpxo13079 2016-08-17 06:19
浏览 42

php中的数据表什么都不返回

i'm new in PHP and also STACKOVERFLOW and i have this project to create a simple reservation room. i've made it to do CRUD on simple PHP but now i wanted to create datatables so that i can display my data to look better. But i really have no idea how to use this datatables, i've changed the database config and tables to the one i wanted and still it returns empty this is my snippet codes for few, so user will input the date and redirect to this page, i also includes the script for datatables

<?php
    include ("connect.php");
    session_start();
    $datebook = $_POST["datepicker"]; 
    $_SESSION['date']=$datebook;
    $nim= $_SESSION['nim'];
    echo('Selected Date=');
    echo($datebook);
    mysqli_close($connect);
?>

<html>
<head>

     <table id="example" class="display" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th>Room ID</th>
                <th>Start </th>
                <th>End</th>
                <th>Purpose</th>
            </tr>
        </thead>
    </table>

<title>Input Page</title>
    <link rel="stylesheet" type="text/css" href="phpstyle.css">
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
    <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" href="font-awesome/css/font-awesome.css">
    <link href="//cdn.datatables.net/1.10.5/css/jquery.dataTables.css" type="text/css" rel="stylesheet">

    <!-- jQuery -->
    <script src="//code.jquery.com/jquery-1.11.1.min.js" language="javascript" type="text/javascript"></script>

    <!-- DataTables -->
    <script src="//cdn.datatables.net/1.10.5/js/jquery.dataTables.min.js" language="javascript" type="text/javascript"></script>


    <script class="init" type="text/javascript">
    $(document).ready(function() {
    $('#example').dataTable( {
        "bProcessing": true,
        "bServerSide": true,
        "sAjaxSource": "serverSide.php"
        "aoColumns": [
                mData: 'roomID',
                mData: 'start',
                mData: 'end',
                mData: 'purpose'
                ]
  } );
} );
</script>
    </head>
<body>

<form method="POST" action="add.php">
<ul class="form-style-1">
    <li><label>Purposes <span class="required">*</span></label><input type="text" name="alasan" id="alasan" class="field-divided" placeholder="Purposes" required/></li>
    <li>
        <label>Start Time <span class="required">*</span></label>
        <input type="time" name="startTime" id="startTime" min="00:00" max="24:00" step="1800" class="field-short" required/>
    </li>
    <li>
        <label>End Time <span class="required">*</span></label>
        <input type="time" name="endTime" id="endTime" min="00:00" max="24:00" step="1800" class="field-short" required/>
    </li>
    <li>
        <label>Room Code</label>
        <select name="code" id="code" class="field-divided">
            <option value="RoomA" >Toefl Room A</option>
            <option value="RoomB">Toefl Room B</option>
            <option value="RoomC">PSP Room Sekre 2</option>
            <option value="RoomD">PSP Room Sekre 2</option>
            <option value="RoomE">Debate Room (2nd FLoor)</option>
        </select>
    </li>
    <li>
        <input type="submit" value="Submit" />
    </li>
</ul>
</form>
</body>
</html>

this one is for serverSide.php the one that datatables refers to

<?php
  session_start();
  $datebook=$_SESSION['date'];
/*
 * Script:    DataTables server-side script for PHP and MySQL
 * Copyright: 2010 - Allan Jardine, 2012 - Chris Wright
 * License:   GPL v2 or BSD (3-point)
 */

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * Easy set variables
 */

/* Array of database columns which should be read and sent back to DataTables. Use a space where
 * you want to insert a non-database field (for example a counter or static image)
 */
$aColumns = array( 'roomID', 'start', 'end', 'purpose');

/* Indexed column (used for fast and accurate table cardinality) */
$sIndexColumn = "roomID";


/* DB table to use */
$sTable = "trroom";

/* Database connection information */
$gaSql['user']       = "root";
$gaSql['password']   = "";
$gaSql['db']         = "k5442245_bnec";
$gaSql['server']     = "localhost";


/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * If you just want to use the basic configuration for DataTables with PHP server-side, there is
 * no need to edit below this line
 */

/*
 * Local functions
 */
function fatal_error ( $sErrorMessage = '' )
{
    header( $_SERVER['SERVER_PROTOCOL'] .' 500 Internal Server Error' );
    die( $sErrorMessage );
}


/*
 * MySQL connection
 */
if ( ! $gaSql['link'] = mysql_pconnect( $gaSql['server'], $gaSql['user'], $gaSql['password']  ) )
{
    fatal_error( 'Could not open connection to server' );
}

if ( ! mysql_select_db( $gaSql['db'], $gaSql['link'] ) )
{
    fatal_error( 'Could not select database ' );
}


/*
 * Paging
 */
$sLimit = "";
if ( isset( $_GET['iDisplayStart'] ) && $_GET['iDisplayLength'] != '-1' )
{
    $sLimit = "LIMIT ".intval( $_GET['iDisplayStart'] ).", ".
        intval( $_GET['iDisplayLength'] );
}


/*
 * Ordering
 */
$sOrder = "";
if ( isset( $_GET['iSortCol_0'] ) )
{
    $sOrder = "ORDER BY  ";
    for ( $i=0 ; $i<intval( $_GET['iSortingCols'] ) ; $i++ )
    {
        if ( $_GET[ 'bSortable_'.intval($_GET['iSortCol_'.$i]) ] == "true" )
        {
            $sOrder .= $aColumns[ intval( $_GET['iSortCol_'.$i] ) ]."
                ".($_GET['sSortDir_'.$i]==='asc' ? 'asc' : 'desc') .", ";
        }
    }

    $sOrder = substr_replace( $sOrder, "", -2 );
    if ( $sOrder == "ORDER BY" )
    {
        $sOrder = "";
    }
}


/*
 * Filtering
 * NOTE this does not match the built-in DataTables filtering which does it
 * word by word on any field. It's possible to do here, but concerned about efficiency
 * on very large tables, and MySQL's regex functionality is very limited
 */
$sWhere = "";
if ( isset($_GET['sSearch']) && $_GET['sSearch'] != "" )
{
    $sWhere = "WHERE (";
    for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" )
        {
            $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string( $_GET['sSearch'] )."%' OR ";
        }
    }
    $sWhere = substr_replace( $sWhere, "", -3 );
    $sWhere .= ')';
}

/* Individual column filtering */
for ( $i=0 ; $i<count($aColumns) ; $i++ )
{
    if ( isset($_GET['bSearchable_'.$i]) && $_GET['bSearchable_'.$i] == "true" && $_GET['sSearch_'.$i] != '' )
    {
        if ( $sWhere == "" )
        {
            $sWhere = "WHERE ";
        }
        else
        {
            $sWhere .= " AND ";
        }
        $sWhere .= $aColumns[$i]." LIKE '%".mysql_real_escape_string($_GET['sSearch_'.$i])."%' ";
    }
}


/*
 * SQL queries
 * Get data to display
 */
$sQuery = "SELECT * FROM trroom WHERE tanggal = '$datebook' ";
$rResult = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );

/* Data set length after filtering */
$rResultFilterTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
$aResultFilterTotal = mysql_fetch_array($rResultFilterTotal);
$iFilteredTotal = $aResultFilterTotal[0];

/* Total data set length */
$sQuery = "
    SELECT COUNT(".$sIndexColumn.")
    FROM   $sTable
";
$rResultTotal = mysql_query( $sQuery, $gaSql['link'] ) or fatal_error( 'MySQL Error: ' . mysql_errno() );
$aResultTotal = mysql_fetch_array($rResultTotal);
$iTotal = $aResultTotal[0];


/*
 * Output
 */
$output = array(
    "sEcho" => intval($_GET['sEcho']),
    "iTotalRecords" => $iTotal,
    "iTotalDisplayRecords" => $iFilteredTotal,
    "aaData" => array()
);

while ( $aRow = mysql_fetch_array( $rResult ) )
{
    $row = array();
    for ( $i=0 ; $i<count($aColumns) ; $i++ )
    {
        if ( $aColumns[$i] == "version" )
        {
            /* Special output formatting for 'version' column */
            $row[] = ($aRow[ $aColumns[$i] ]=="0") ? '-' : $aRow[ $aColumns[$i] ];
        }
        else if ( $aColumns[$i] != ' ' )
        {
            /* General output */
            $row[] = $aRow[ $aColumns[$i] ];
        }
    }
    $output['aaData'][] = $row;
}

echo json_encode( $output );
 ?>

Sorry for being new i'm really stuck at this point

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 #MATLAB仿真#车辆换道路径规划
    • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
    • ¥15 数据可视化Python
    • ¥15 要给毕业设计添加扫码登录的功能!!有偿
    • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
    • ¥15 微信公众号自制会员卡没有收款渠道啊
    • ¥100 Jenkins自动化部署—悬赏100元
    • ¥15 关于#python#的问题:求帮写python代码
    • ¥20 MATLAB画图图形出现上下震荡的线条
    • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘