dean7 Posted April 5, 2010 Share Posted April 5, 2010 Hi all, On my website i have a login which under that i have a information box which says the users currently online and the most users which have ever been online.. Login.php: <tr> <td colspan="3">Website Online: <font color="red">Offline! (Coding)</font> <br /> Users Onlie: <font color="green"><?php echo ("$num"); ?></font><br /> Most Online: <font color="green"><?php echo ("$most"); ?></font><br /> <center>© mafia-drift - all content</center> </td> </tr> </table> </body> </html> Online.php <?php ini_set ('display_errors', 1); error_reporting (E_ALL); ?> <?php session_start(); include_once "includes/config.php"; include_once "includes/functions.php"; if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ header("Location: index.php"); }else{ $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE username='".$_SESSION['username']."'")); } $username=$_SESSION['username']; $total_mem = mysql_num_rows(mysql_query("SELECT * FROM users")); $admins = mysql_num_rows(mysql_query("SELECT * FROM users WHERE userlevel = '3'")); // How many admins? $headmod = mysql_num_rows(mysql_query("SELECT * FROM users WHERE userlevel = '2'")); // How many head mods? $mod = mysql_num_rows(mysql_query("SELECT * FROM users WHERE userlevel = '1'")); // How many mods? $meheha = mysql_fetch_object(mysql_query("SELECT * FROM site_info WHERE id = '1'")); // Just getting the info for line 17 $more=$meheha->online; // Gets the most online. ?> So on the login.php id like it to show how many is online.. is there a way that I could i use the same varibals from online.php to login.php? Link to comment https://forums.phpfreaks.com/topic/197634-same-variables-on-two-pages/ Share on other sites More sharing options...
Pikachu2000 Posted April 5, 2010 Share Posted April 5, 2010 The best way to do it would be to determine the number each time a page on which you want the data displayed loads, otherwise it won't be current; although nothing in the queries above seems to determine which users are currently online. Link to comment https://forums.phpfreaks.com/topic/197634-same-variables-on-two-pages/#findComment-1037265 Share on other sites More sharing options...
dean7 Posted April 5, 2010 Author Share Posted April 5, 2010 Oh sorry, might be because i didnt post the bit of the online script you need.. well heres all the code: <?php ini_set ('display_errors', 1); error_reporting (E_ALL); ?> <?php session_start(); include_once "includes/config.php"; include_once "includes/functions.php"; if(!isset($_SESSION['username']) || !isset($_SESSION['password'])){ header("Location: index.php"); }else{ $fetch_users_data = mysql_fetch_object(mysql_query("SELECT * FROM `users` WHERE username='".$_SESSION['username']."'")); } $username=$_SESSION['username']; $total_mem = mysql_num_rows(mysql_query("SELECT * FROM users")); $admins = mysql_num_rows(mysql_query("SELECT * FROM users WHERE userlevel = '3'")); // How many admins? $headmod = mysql_num_rows(mysql_query("SELECT * FROM users WHERE userlevel = '2'")); // How many head mods? $mod = mysql_num_rows(mysql_query("SELECT * FROM users WHERE userlevel = '1'")); // How many mods? $meheha = mysql_fetch_object(mysql_query("SELECT * FROM site_info WHERE id = '1'")); // Just getting the info for line 17 $more=$meheha->online; // Gets the most online. ?> <br /> <html> <head> <title>Players Online</title> </head> <body> <center><table class="thinline" width='70%' border="1" cellpadding="2" cellspacing="0" bordercolor='black'> <tr> <td colspan="2" bordercolor="#000000" class="header" border='1px' ><div align="center"><a href='online.php'><font color="white">Players Online</font></a></td> </tr> <tr> <td class="forum" colspan="2" border="1px" bordercolor="#000000"> <center>Users online in the last 5 minutes</center> </td> </tr> <tr> <td width="2%" bordercolor="#000000" bgcolor="#2E2E2E" border='1px' class="tablestyle"> </td> <td bordercolor="#000000" bgcolor="#2E2E2E" border='1px' bordercolor='ffffff' class="tablestyle"><b> <font color='#3399cc'><br /> - <?php $timenow=time(); $select = mysql_query("SELECT * FROM users WHERE online > '$timenow' ORDER by 'id' DESC"); $num = mysql_num_rows($select); $num = mysql_num_rows($select); $timeout = $timestamp-$timeoutseconds; while ($i = mysql_fetch_object($select)){ if ($i->crew == "0"){ $crew="None"; }else{ $crew=$i->crew; } if ($i->last_oc > time()){ $oc="No"; }else{ $oc="Yes"; } if($i->userlevel=="4"){ $echo = "<font color=#7DC6C2>$i->username</font>"; }elseif ($i->userlevel=="3"){ $echo = "<font color=darkred>$i->username</font>"; }elseif ($i->userlevel=="2"){ $echo = "<font color=blue>$i->username</font>"; }elseif ($i->userlevel=="1"){ $echo = "<font color=pink>$i->username</font>"; }else{ $echo = "<font color=black>$i->username</font>"; } echo "<a onMouseover=\"tip('User: $i->username <br /> Rank: $fetch_user_data->rank <br /> Money: $fetch_user_data->money');\" onmouseout=\"nd();\" href='profile.php?viewuser=$i->username' style=\"\"> $echo </a> - "; } ?> <br /></font> </b></td> </tr> <tr> <td height="27" bordercolor="#000000" bgcolor="#2E2E2E" border='1px'> </td> <td height="27" bordercolor="#000000" bgcolor="#2E2E2E" border='1px'>Total Number Of Players Online: <font color="#ffffff"><?php echo "$num"; ?></font> | The Most Online At Once: <font color="#FFFFFF"><?php echo "$more"; ?></span></td> </tr> <tr> <td bordercolor="#000000" bgcolor="#2E2E2E" border='1px' class="tablestyle"> </td> <td bordercolor="#000000" bgcolor="#2E2E2E" border='1px' class="tablestyle"><a href="helpdesk.php" target="mainFrame">Help Desk</a> | <a href="reportabuse.php" target="mainFrame">Report Abuse</a></td> </tr> <tr> <td bordercolor="#000000" bgcolor="#2E2E2E" border='1px' class="tablestyle"> </td> <td bordercolor="#000000" bgcolor="#2E2E2E" border='1px' class="tablestyle"> <font color='#7DC6C2'>Light Blue</font> - This is the owner.<br /> <font color='darkred'>Dark Red</font> - These are Admins, they help run the game and do the refunds. <br /> <font color="blue">Blue</font> - These are Head Moderators, they are here to keep the game under control and contol the Moderators<br> <font color="pink">Pink</font> - These are Moderators, They will answer any question's about the game, and who also help out best they can.<br /> <font color="black">Black</font> - These are the members of Mafia Drift. <br> </span></td> </tr> </td> </table> </center> <p> </p> </body> </html> <center> <?php require_once "footer.php"; ?> </center> Link to comment https://forums.phpfreaks.com/topic/197634-same-variables-on-two-pages/#findComment-1037284 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.