PHP预订系统数据库
我对php和数据库相当陌生,我已经使用xampp创建了一个预订系统。我有一个登录页面供用户预订,还有一个限制访问页面供管理员查看所有已预订。但是,我似乎无法查看所有人进行的所有预订,只能查看用户进行的预订。我确信这与课程有关,但不确定是哪一部分。我们将不胜感激 以下是记录集代码,它仅显示登录预订的用户,而不是所有数据库预订 多谢各位PHP预订系统数据库,php,mysql,sql,database,Php,Mysql,Sql,Database,我对php和数据库相当陌生,我已经使用xampp创建了一个预订系统。我有一个登录页面供用户预订,还有一个限制访问页面供管理员查看所有已预订。但是,我似乎无法查看所有人进行的所有预订,只能查看用户进行的预订。我确信这与课程有关,但不确定是哪一部分。我们将不胜感激 以下是记录集代码,它仅显示登录预订的用户,而不是所有数据库预订 多谢各位 <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($
<?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);
?>
您的查询仅限于一个用户
$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int"));
Where is表示,Where user_id=%s
将仅将结果限制为该用户的结果。删除该选项,您将获得所有预订
$query_Recordset1 = "SELECT * FROM booking";
您可能希望通过按用户、日期等对结果排序来改进该查询。更改此行:
$query_Recordset1 = sprintf("SELECT * FROM booking WHERE user_id = %s", GetSQLValueString($colname_Recordset1, "int"));
致:
通过删除<代码> > USELIDID= %s将返回预订表中的所有行。
您可以考虑使用这样的框架。我个人喜欢CodeIgniter。这将有助于避免混乱的数据库代码,如您的。。。
$query_Recordset1 = sprintf("SELECT * FROM booking", GetSQLValueString($colname_Recordset1, "int"));