dennis m: Datensatz Abfrage zählen

Beitrag lesen

Stückchen Code:

<?php require_once('../../Connections/database.php');?>
<?php include("rating/includes/rating_functions.php"); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $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;
}
}

$currentPage = $_SERVER["PHP_SELF"];

mysql_select_db($database_database, $database);
$query_rt = "SELECT * FROM rt ORDER BY DATE DESC";
$rt = mysql_query($query_rt, $database) or die(mysql_error());
$row_rt = mysql_fetch_assoc($rt);
$totalRows_rt = mysql_num_rows($rt);

$maxRows_commentsys = 10;
$pageNum_commentsys = 0;
if (isset($_GET['pageNum_commentsys'])) {
  $pageNum_commentsys = $_GET['pageNum_commentsys'];
}
$startRow_commentsys = $pageNum_commentsys * $maxRows_commentsys;

$colname_commentsys = "-1";
if (isset($_GET['ID'])) {
  $colname_commentsys = $_GET['ID'];
}
mysql_select_db($database_database, $database);
$query_commentsys = sprintf("SELECT * FROM commentsys WHERE TOS_ID = %s ORDER BY DATE DESC", GetSQLValueString($colname_commentsys, "text"));
$query_limit_commentsys = sprintf("%s LIMIT %d, %d", $query_commentsys, $startRow_commentsys, $maxRows_commentsys);
$commentsys = mysql_query($query_limit_commentsys, $database) or die(mysql_error());
$row_commentsys = mysql_fetch_assoc($commentsys);

if (isset($_GET['totalRows_commentsys'])) {
  $totalRows_commentsys = $_GET['totalRows_commentsys'];
} else {
  $all_commentsys = mysql_query($query_commentsys);
  $totalRows_commentsys = mysql_num_rows($all_commentsys);
}
$totalPages_commentsys = ceil($totalRows_commentsys/$maxRows_commentsys)-1;

mysql_select_db($database_database, $database);
$query_commentsys_autor_usrname = "SELECT Autor_usrname FROM commentsys";
$commentsys_autor_usrname = mysql_query($query_commentsys_autor_usrname, $database) or die(mysql_error());
$row_commentsys_autor_usrname = mysql_fetch_assoc($commentsys_autor_usrname);
$totalRows_commentsys_autor_usrname = mysql_num_rows($commentsys_autor_usrname);

$colname_visits = "0";
if (isset($_GET['ID'])) {
  $colname_visits = $_GET['ID'];
}
mysql_select_db($database_database, $database);
$query_visits = sprintf("SELECT ID, VISITS FROM rt WHERE ID = %s", GetSQLValueString($colname_visits, "int"));
$visits = mysql_query($query_visits, $database) or die(mysql_error());
$row_visits = mysql_fetch_assoc($visits);
$totalRows_visits = mysql_num_rows($visits);

$queryString_commentsys = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_commentsys") == false &&
        stristr($param, "totalRows_commentsys") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_commentsys = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_commentsys = sprintf("&totalRows_commentsys=%d%s", $totalRows_commentsys, $queryString_commentsys);
?>