【问题标题】:PHP Booking system databasePHP订票系统数据库
【发布时间】:2014-05-24 05:16:44
【问题描述】:

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

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

谢谢

<?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);


?>

【问题讨论】:

  • 您可能会考虑使用这样的框架。我个人喜欢 CodeIgniter。它将有助于避免像您这样的混乱数据库代码......

标签: php mysql sql database


【解决方案1】:

改变这一行:

$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,将返回 bookings 表中的所有行。

【讨论】:

    【解决方案2】:

    您的查询仅限于一位用户。

    $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";
    

    您可能希望通过按用户、日期等对结果进行排序来改进该查询。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多