我是PHP和STACKOVERFLOW的新手,我有这个项目来创建一个简单的预订房间。 我已经让它在简单的PHP上做CRUD但现在我想创建数据表,以便我可以显示我的数据看起来更好。但我真的不知道如何使用这个数据表,我已经将数据库配置和表更改为我想要的那个,但它仍然返回空 这是我的代码片段,因此用户将输入日期并重定向到此页面,我还包括数据表的脚本
<?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>
这个是针对serverSide.php的数据表引用的那个
<?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 );
?>
对不起,我刚刚陷入困境