elis Posted September 10, 2008 Share Posted September 10, 2008 I have a script that is supposed to display how long somebody has been logged in for. The script is based off of tables that are related to an adjoining site. I.E. if somebody were to visit Google from my site, my site would display, in real time, how long they've been visiting Google for until that person clicks the logout button. The tables are connected to each site that is available for visitation: For example: ID ---- SITE ---- USER --- TIME_OPEN 1 | Google.com | test_user | 2008-09-10 13:08:54 2. | Yahoo.com | new_user | 2008-09-10 12:10:33 etc. This worked perfectly fine until I inserted a new site (in the same format in the above example) and suddenly, it stopped showing how long someone was logged in for. I've checked everything and can't figure out why it's no longer working. When I remove the new site from the table, it works again. Here is the full source code: <?php if(!$session->get('s_isLoggedIn')) { redirect('/index.php', 'http://mysite.com'); } else { ?> <table class="sites" cellpadding="0" cellspacing="0" style="width: 350px; margin-left: 20px;"> <?php $sql = "SELECT *, UNIX_TIMESTAMP(time_opened) AS time FROM siteAccounts ORDER BY site DESC"; global $conn; $conn->open(); $stmt = $conn->prepare($sql); $stmt->execute(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { if(!isset($currentSite) || $row['site'] != $currentSite) { $currentSite = $row['site']; echo '<tr><th><img src="img/' . strtolower($currentSite) . '.gif" alt="' . $currentSite . '" /></th></tr>'; } echo '<tr><td class="site"><div class="userpass">Username: ' . $row['user'] . '<br />Password: ' . $row['pass'] . '</div><div>'; if(is_null($row['inits'])) { // No user logged into this account - show login link switch($currentSite) { case 'Google': // Automatically login to dice by emulating a submittal from their login form echo '<form style="margin-top: 3px;" action="http://googlelink/" method="post" target="_blank" onsubmit="new Ajax.Request(\'save_account.php\', { method: \'get\', onComplete: function(transport) { window.location.reload(); }, parameters: { account_id: ' . $row['account_id'] . ' } });"><input type="hidden" name="USERNAME" value="' . $row['user'] . '" /><input type="hidden" name="PASSWORD" value="' . $row['pass'] . '" /><input type="submit" value="Google" id="login" class="gbutton" /></form>'; break; case 'Yahoo': echo '<form style="margin-top: 3px;" action="http://yahoo.com" method="post" target="_blank" onsubmit="new Ajax.Request(\'save_account.php\', { method: \'get\', onComplete: function(transport) { window.location.reload(); }, parameters: { account_id: ' . $row['account_id'] . ' } });"><input type="submit" value="Visit Yahoo" class="ybutton" /></form>'; break; case 'Final': echo '<form style="margin-top: 3px;" action="http://final.com" method="post" target="_blank" onsubmit="new Ajax.Request(\'save_account.php\', { method: \'get\', onComplete: function(transport) { window.location.reload(); }, parameters: { account_id: ' . $row['account_id'] . ' } });"><input type="submit" value="Visit Final" class="fbutton" /></form>'; break; } } else { // User logged in - show time since login button was clicked $name = $session->get('s_name'); $names = explode(' ', $name); echo '<div style="margin-top: 10px; font-size: 125%;"><a href="save_account.php?logout=true&account_id=' . $row['account_id'] . '"><img src="img/reqlist/delete.png" border="0" alt="Logout" /></a> · <strong>Occupied</strong> · ' . $row['inits'] . ' for <div id="cpcontainer_' . $row['account_id'] . '"> </div>'; ?> <? } ?> <script type="text/javascript"> timer_<?=$row['account_id']?>.settime('<?=date('F j, Y G:i:s',$row['time'])?>'); timer_<?=$row['account_id']?>.oncountup=function(result){ var mycountainer=document.getElementById("cpcontainer_<?=$row['account_id']?>") mycountainer.innerHTML=result['minutes']+" minutes "+result['seconds']+" seconds" } </script> <? } ?> </div> </td> </tr> </table> <? } ?> Note: I changed a couple things to match the table example I provided, just so it's easier to follow. Here are the actual problem areas (or what I suspect are the problem areas): this is the same script as above, I've simply highlighted where I suspect something's gone wrong. <?php case 'Final': echo '<form style="margin-top: 3px;" action="http://final.com" method="post" target="_blank" onsubmit="new Ajax.Request(\'save_account.php\', { method: \'get\', onComplete: function(transport) { window.location.reload(); }, parameters: { account_id: ' . $row['account_id'] . ' } });"><input type="submit" value="Visit Final" class="fbutton" /></form>'; break; ?> This ^^ is the most recent addition to the sites as I explained earlier and <?php $name = $session->get('s_name'); $names = explode(' ', $name); echo '<div style="margin-top: 10px; font-size: 125%;"><a href="save_account.php?logout=true&account_id=' . $row['account_id'] . '"><img src="img/reqlist/delete.png" border="0" alt="Logout" /></a> · <strong>Occupied</strong> · ' . $row['inits'] . ' for <div id="cpcontainer_' . $row['account_id'] . '"> </div>'; ?> <?php } ?> <script type="text/javascript"> timer_<?=$row['account_id']?>.settime('<?=date('F j, Y G:i:s',$row['time'])?>'); timer_<?=$row['account_id']?>.oncountup=function(result){ var mycountainer=document.getElementById("cpcontainer_<?=$row['account_id']?>") mycountainer.innerHTML=result['minutes']+" minutes "+result['seconds']+" seconds" } This should show the time below the site name. Some things I've noticed, when I list the sites in Descending order (where the problematic site shows up last on the page) the countup script works properly for all the other sites, just not the problematic site. When it's listed in ascending order, the problematic site appears first and the countup script doesn't operate for any of the sites. Final note: "<?php" isn't continuously called as it is in the posted snippets, I simply did it so the colors would appear and (hopefully) it'd be easier to follow. Link to comment https://forums.phpfreaks.com/topic/123663-countup-script-not-displaying-time-10-if-you-can-solve/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.