2014-04-10 131 views
0

我对PHP和数据库相当陌生,我创建了一个使用xampp的预订系统。我有一个登录页面供用户预订,还有一个限制访问页面,供管理员查看所有预订。然而,我似乎无法查看所有人的预订,只有用户所做的预订。我相信这与会议有关,但不确定哪一部分。帮助将不胜感激。PHP预订系统数据库

这里是以下记录集代码,它只显示登录了预订的用户,而不是所有的数据库预订。

谢谢

<?php 
if (!function_exists("GetSQLValueString")) { 
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{ 
    if (PHP_VERSION < 6) { 
$theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; 
} 

$theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) :  mysql_escape_string($theValue); 

    switch ($theType) { 
    case "text": 
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
    break;  
case "long": 
case "int": 
    $theValue = ($theValue != "") ? intval($theValue) : "NULL"; 
    break; 
case "double": 
    $theValue = ($theValue != "") ? doubleval($theValue) : "NULL"; 
    break; 
case "date": 
    $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; 
    break; 
case "defined": 
    $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; 
    break; 
} 
return $theValue; 
} 
} 

$colname_Recordset1 = "-1"; 
if (isset($_SESSION['MM_Userid'])) { 
$colname_Recordset1 = $_SESSION['MM_Userid']; 
} 
mysql_select_db($database_myconnectiono, $myconnectiono); 
$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s",  GetSQLValueString($colname_Recordset1, "int")); 
$Recordset1 = mysql_query($query_Recordset1, $myconnectiono) or die(mysql_error()); 
$row_Recordset1 = mysql_fetch_assoc($Recordset1); 
$totalRows_Recordset1 = mysql_num_rows($Recordset1); 


?> 
+0

你可能会考虑使用这样的框架。我个人喜欢CodeIgniter。这将有助于避免混乱的数据库代码,比如你的... – swiss196

回答

2

您的查询它限制到只有一个用户。

$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int")); 

WHERE user_id = %s在哪里会将结果限制为仅用户的结果。删除它,你会得到所有的预订。

$query_Recordset1 = "SELECT * FROM booking"; 

你可能会想通过订购用户,日期等

0

改变这一行的结果,以提高该查询:

$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int")); 

要:

$query_Recordset1 = sprintf("SELECT * FROM booking", GetSQLValueString($colname_Recordset1, "int")); 

通过删除WHERE user_id = %s预订表中的所有行将被返回。