Ok, ho provato la query in phpmyadmin e funziona, idem la connessione al db.
Questo è il sorgente della pagina:
index.php
Codice PHP:
<?php require_once('Connections/config.php'); ?>
<?php include("includes/stats.php"); ?>
<?php
if (!isset($_SESSION)) {
session_start();
}?>
<?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;
}
}
?>
<?php
$colname_Recordset1 = "-1";
if (isset($_SESSION['username'])) {
$colname_Recordset1 = $_SESSION['username'];
}
mysql_select_db($database_config, $config);
$query_Recordset1 = sprintf("SELECT * FROM f_user WHERE userName = %s", GetSQLValueString($colname_Recordset1, "text"));
$Recordset1 = mysql_query($query_Recordset1, $config) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
mysql_select_db($database_config, $config);
$query_DataTeam = "SELECT f_team.name, f_user.userName, f_team.teamID, f_team.emblem, COUNT(f_player.teamID), f_team_rating.rating_image FROM f_team, f_coach, f_user, f_player, f_team_rating WHERE f_team.teamID=f_coach.teamID AND f_coach.userID = f_user.userID AND f_team.teamID=f_player.teamID AND f_team_rating.rating_id = f_team.rating GROUP BY f_team.teamID ASC";
$DataTeam = mysql_query($query_DataTeam, $config) or die(mysql_error());
$row_DataTeam = mysql_fetch_assoc($DataTeam);
$totalRows_DataTeam = mysql_num_rows($DataTeam);
$varuser_MyTournaments = "-1";
if (isset($_SESSION['username'])) {
$varuser_MyTournaments = $_SESSION['username'];
}
mysql_select_db($database_config, $config);
$query_MyTournaments = sprintf("SELECT f_tournaments.tournamentName, f_tournaments.tournamentID FROM f_tournaments, f_tournaments_teams, f_team, f_coach, f_user WHERE f_tournaments.tournamentID = f_tournaments_teams.tournamentsID AND f_tournaments_teams.teamID = f_team.teamID AND f_team.teamID = f_coach.teamID AND f_coach.userID = f_user.userID AND f_user.userName = %s AND f_tournaments.t_active = 1", GetSQLValueString($varuser_MyTournaments, "text"));
$MyTournaments = mysql_query($query_MyTournaments, $config) or die(mysql_error());
$row_MyTournaments = mysql_fetch_assoc($MyTournaments);
$totalRows_MyTournaments = mysql_num_rows($MyTournaments);
$maxRows_dataauc = 10;
$pageNum_dataauc = 0;
if (isset($_GET['pageNum_dataauc'])) {
$pageNum_dataauc = $_GET['pageNum_dataauc'];
}
$startRow_dataauc = $pageNum_dataauc * $maxRows_dataauc;
mysql_select_db($database_config, $config);
$query_dataauc = "SELECT f_auction.auctionName, f_auction.id, f_auction.aucActive FROM f_auction";
$query_limit_dataauc = sprintf("%s LIMIT %d, %d", $query_dataauc, $startRow_dataauc, $maxRows_dataauc);
$dataauc = mysql_query($query_limit_dataauc, $config) or die(mysql_error());
$row_dataauc = mysql_fetch_assoc($dataauc);
if (isset($_GET['totalRows_dataauc'])) {
$totalRows_dataauc = $_GET['totalRows_dataauc'];
} else {
$all_dataauc = mysql_query($query_dataauc);
$totalRows_dataauc = mysql_num_rows($all_dataauc);
}
$totalPages_dataauc = ceil($totalRows_dataauc/$maxRows_dataauc)-1;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Home Page</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js"></script>
<script type="text/javascript" src="js/topPage.js"></script>
<link href="css/menu.css" rel="stylesheet" type="text/css" />
<link href="css/stile.css" rel="stylesheet" type="text/css" />
<link href="css/reset.css" rel="stylesheet" type="text/css" />
<link href="css/table.css" rel="stylesheet" type="text/css" />
<link href='http://fonts.googleapis.com/css?family=Oswald' rel='stylesheet' type='text/css'>
<style type="text/css">
body {
background: url(images/BG.png) no-repeat scroll 50% 10px #000000;
}
</style>
</head>
<body>
<div id="wrapper" class="newHeader">
<div id="doc">
<div id="header"><a id="logo" href="index.php">masterxls</a>
<div id="navigation">
<?php include("includes/menu.php"); ?>
</div></div>
<div id="simpleHeaderImgBanner">
<div class="inner clearfix"></div>
</div>
<div id="main">
<div class="newDash" id="bodyDetails">
<div class="bodyContent" id="bodyDash">
<div class="inner">
<div id="sidebar">
<a href="edit_profile.php"> <img class="avatar" src="uploads/<?php echo $row_Recordset1['avatar']; ?>" width="88" height="88" alt="Avatar" /></a>
<div class="clear"></div>
<?php echo '<h2>'.$_SESSION['username'].'</h2>';?>
<div class="clear"></div>
<?php include ("includes/sidebarmenu.php"); ?>
<h4>I miei Tornei</h4>
<?php do { ?>
<div style="clear:both;height:5px;"></div>
<ul class="rtools">
<li class="tournaments"><a href="mymatch.php?recordID=<?php echo $row_MyTournaments['tournamentID'];?>">
<?php echo $row_MyTournaments['tournamentName']; ?></a></li>
<?php } while ($row_MyTournaments = mysql_fetch_assoc($MyTournaments)); ?> </ul>
<h4 class="rtitle">Mercato</h4>
<ul class="rtools">
<?php do { if($row_dataauc['aucActive'] == 1){?>
<li class="auction"><a href="myauction.php?recordID=<?php echo $row_dataauc['id']; ?>"><?php echo $row_dataauc['auctionName']; ?></a></li><?php } else {}?><div style="clear:both;height:5px;"></div>
<?php } while ($row_dataauc = mysql_fetch_assoc($dataauc)); ?>
</ul>
<h4 class="rtitle">Utenti Online</h4>
<?php
$d=date('Y-m-d H:i:s',time()-5*60);//last 5 minutes
$q=mysql_query("select username from f_navigation where time>'$d'");
if(mysql_affected_rows()>0){
print
"<ul class='tools'>";
while($users=mysql_fetch_array($q)){
print
"<li class='online'>{$users[0]}</li>"; }
print "</ul>";
}
?>
</div>
<div id="dashContent">
<div class="dash_content_section">
<table width = "100%">
<tr class="title">
<td class="head">Squadra</td>
<td class="head">Fascia</td>
<td class="head">NR. Giocatori</td>
<td class="head">Finanze</td>
<td class="head">Monte Ingaggi</td>
<td class="head">Allenatore</td>
</tr>
<?php do { ?>
<tr>
<td class="table0"><img class="playeravatar" width="40" height="40" src="uploads/emblem/<?php echo $row_DataTeam['emblem']; ?>"><a href="teamview.php?recordID=<?php echo $row_DataTeam['teamID']; ?>"> <?php echo $row_DataTeam['name']; ?></a></td>
<td class="table1"><img src="http://forum.it.altervista.org/images/teamrank/<?php echo $row_DataTeam['rating_image']; ?>"/></td>
<td class="table1"><?php echo $row_DataTeam['COUNT(f_player.teamID)']; ?></td>
<td class="table1"> </td>
<td class="table1"> </td>
<td class="table1lastfield"><?php echo $row_DataTeam['userName']; ?></td>
</tr>
<?php } while ($row_DataTeam = mysql_fetch_assoc($DataTeam)); ?>
</table>
</div>
</div>
<div class="clear"></div>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<div class="wrapperFooter">
<div class="footer">
<?php include("includes/footer.php"); ?>
</div>
<div class="copyright"><?php include("includes/copyright.php"); ?></div>
</div>
</div>
</div>
<div id='topPage'>
<a href=''></a>
</div>
</body>
</html>
<?php
mysql_free_result($Recordset1);
mysql_free_result($DataTeam);
mysql_free_result($MyTournaments);
mysql_free_result($dataauc);
?>
stats.php = (il codice postato all'inizio del topic)
La tabella:
Codice PHP:
CREATE TABLE `navigation` (
`username` varchar(50) NOT NULL,
`time` datetime NOT NULL,
PRIMARY KEY (`username`)
)