deepermethod
Members-
Posts
33 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
deepermethod's Achievements
Newbie (1/5)
0
Reputation
-
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
I scrapped my script altogether. I used your script, including creating the new table. All it shows is the offline image. I have the session_start(); at the top of each page and still only the offline image. When I look in the table in my database there is nothing there, it isn't getting inserted some how. Not looking for a script rewrite, just some advice. -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
I'll keep looking at it. I did include <?php session_start();?> to the top of both pages and it still isn't working. Some how it isn't getting inserted into my database. -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
Even if I am using the online.inc.php as an include? -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
Well, I adjusted it to what I need and it initially worked (showed online image). When I go to another page and back to the page with the online.php script it shows the offline image. My code: <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "online.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $timestamp = time(); $timeout = $timestamp - 180; $mem_id = $_SESSION['member_id']; $rem_add = $_SERVER['REMOTE_ADDR']; $php_self = $_SERVER['PHP_SELF']; $sql=("SELECT * FROM $tbl_online WHERE id = $_SESSION[member_id]") or die("Error in user online result query!"); $count=mysql_num_rows($result); if($count=="0"){ $sql1=("INSERT INTO $tbl_online(id, timestamp, ip)VALUES('$mem_id', '$timestamp', '$rem_add')"); $result1=mysql_query($sql1); } else { $sql2=("UPDATE `tbl_online` SET count = count + 1 WHERE id = '$mem_id'"); $result2=mysql_query($sql2); } $sql3=("SELECT * FROM $tbl_online"); $result3=mysql_query($sql3); if(mysql_num_rows($result3)){ echo"<img src='./gr_image/online.jpg'>"; } else { echo"<img src='./gr_image/offline.jpg'>"; } echo $img; // if over 10 minute, delete session $sql4=("DELETE FROM $tbl_online WHERE timestamp<$timeout"); $result4=mysql_query($sql4); ?> -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
Yes, I am in the process of adapting it to my needs. I just wanted to make sure that is what the code did. -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
That looks good, but is that to count the number of users online? I was looking to show 2 different images - one if a user was online and another if the user was offline. Thanks -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
So is this possible or should I just scrap the idea? -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
Okay. I'm stumped. After doing some more searching, here's my current code (unfinished): <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "online.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $timestamp = time(); $timeout = $timestamp - 180; $mem_id = $_SESSION['member_id']; $rem_add = $_SERVER['REMOTE_ADDR']; $php_self = $_SERVER['PHP_SELF']; $result = mysql_query("SELECT DISTINCT ip FROM $tbl_online WHERE id = $_SESSION[member_id]") or die("Error in user online result query!"); if(mysql_num_rows($result) > 0) { $update = mysql_query("UPDATE $tbl_online WHERE timestamp<$timeout")or die("Error in who's online update query!".mysql_error()); } else { $insert = mysql_query(("INSERT INTO $tbl_online (id, timestamp, ip, file, ol_user, ol_id) VALUES('$mem_id', '$timestamp', '$rem_add', '$php_self', '$ol_user', '$ol_id')") or die("Error in who's online insert query!".mysql_error()); } //Delete Users $delete = mysql_query("DELETE FROM $tbl_online WHERE timestamp<$timeout") or die("Error in who's online delete query!"); Now, how do I get it to echo/print the online or offline images? Here's how I had it before: //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_online WHERE id = $_SESSION[member_id]") or die("Error in user online result query!"); if(mysql_num_rows($result) > 0) { echo"<img src='./gr_image/online.jpg'>"; } else { echo"<img src='./gr_image/offline.jpg'>"; } Thanks in advance. -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
Been trying to do a fix all day and can't seem to get it to work. Any help? -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
Thanks maq and zenag. I got the online image to show, initially. Now, a new error. When I go to another page and then come back to where the online/offline image is I get this error: "Error in who's online insert query!Duplicate entry '4' for key 1". Any ideas? Is my Delete Users query not working correctly? <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "online.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $timestamp = time(); $timeout = $timestamp - 180; $mem_id = $_SESSION['member_id']; $rem_add = $_SERVER['REMOTE_ADDR']; $php_self = $_SERVER['PHP_SELF']; //Insert User $insert = mysql_query("INSERT INTO $tbl_online (id, timestamp, ip, file, ol_user, ol_id) VALUES('$mem_id', '$timestamp', '$rem_add', '$php_self', '$ol_user', '$ol_id')") or die("Error in who's online insert query!".mysql_error()); //Delete Users $delete = mysql_query("DELETE FROM $tbl_online WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_online WHERE id = $_SESSION[member_id]") or die("Error in user online result query!"); if(mysql_num_rows($result) > 0) { echo"<img src='./gr_image/online.jpg'>"; } else { echo"<img src='./gr_image/offline.jpg'>"; } ?> -
Show users online/offline with image
deepermethod replied to deepermethod's topic in PHP Coding Help
I am getting this error= "Error in who's online insert query!" I am just learning php, so be patient please. Here's the current code: <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "online.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $timestamp = time(); $timeout = $timestamp - 180; //Insert User $insert = mysql_query("INSERT INTO $tbl_online (id, timestamp, ip, file, ol_user, ol_id) VALUES(\"$_SESSION[member_id]\",'$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','$ol_user','$ol_id')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_online WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_online WHERE id = $_SESSION[member_id]") or die("Error in user online result query!"); if(mysql_num_rows($result) > 0) { echo"<img src='./gr_image/online.jpg'>"; } else { echo"<img src='./gr_image/offline.jpg'>"; } ?> -
I have a personal website that show the number of users on my site as a whole (like = 12 members online). The site has profile pages so I would like to show if a user is online or offline with an image. I have searched and searched here and haven't found what I was looking for. Can I alter my current file to fit what I want? <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "online.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $timestamp = time(); $timeout = $timestamp - 180; if(session_is_registered("valid_user")) { $ol_user = "$valid_user"; } else { $ol_user = "guest"; } if(session_is_registered("valid_user")) { $ol_id = "$member_id"; } else { $ol_id = "0"; } //Insert User $insert = mysql_query("INSERT INTO $tbl_online (timestamp, ip, file, ol_user, ol_id) VALUES('$timestamp','".$_SERVER['REMOTE_ADDR']."','".$_SERVER['PHP_SELF']."','$ol_user','$ol_id')") or die("Error in who's online insert query!"); //Delete Users $delete = mysql_query("DELETE FROM $tbl_online WHERE timestamp<$timeout") or die("Error in who's online delete query!"); //Fetch Users Online $result = mysql_query("SELECT DISTINCT ip FROM $tbl_online") or die("Error in who's online result query!"); $users = mysql_num_rows($result); if($users == 1) { $ol_label = "user"; } else { $ol_label = "users"; } ?> <table align="center" cellpadding="0" cellspacing="0"> <tr> <td class="online"> <p><?php echo "<b>$valid_user</b> $ol_label"; ?> online</p> </td> </tr> </table> Thanks in advanced.
-
You have made my day corbin. Now that you got it working, I will go and read the tut's that you posted so I can understand it better. I am sorry for any inconvenience.
-
Sorry to bother you corbin. Can someone tell me why I am getting this error: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in /home/xxxxx/public_html/xxxxx/include/main_new_members.inc.php on line 61 The code is below. See "LINE 61 IS HERE" <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "newestmember.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT p.*, i.* FROM images i JOIN profiles p ON p.profile_id = i.image_id WHERE i.displayname != 'Community' AND default_pic = 'yes' ORDER BY image_id DESC LIMIT 0, 2"; $result = @mysql_query($sql,$connection) or die(mysql_error()); $num=mysql_num_rows($result); if($num < 1){ echo "<center>No Members with pictures found.</center>"; } else { ?> <table style='text-align: left; width: 100%;' border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td>new to lounge{in}</td> </tr> </tbody> </table> <? while ($row = mysql_fetch_array($result)) { $url = $row['url']; $image = $row['image']; $member = $row['displayname']; $fullurl = "$userurl/$url"; $src = "$userdir/$url/$image"; LINE 61 IS HERE --> $age = "$row['age']"; echo " <table style='text-align: left; width: 100%;' border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td><a href=\"$fullurl\"><img src=\"thumbs/phpThumb.php?src=/$src&w=50\" border=\"0\"></a></td> <td align='undefined' valign='undefined'> <table style='text-align: left; width: 100%;' border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td><a href=\"$fullurl\">$member</a>$age </td> </tr> <tr> <td align='undefined' valign='undefined'>location</td> </tr> </tbody> </table> </td> </tr> <tr> <td align='undefined' valign='undefined'>sgl div</td> <td align='undefined' valign='undefined'>sgl div</td> </tr> </tbody> </table> "; } ?> </table> <? } ?>
-
Change the HTML? So, the query matched the image_id and the profile_id. How do I pull the age from the profiles table? If you look in the code below I want to have the age appear where it says INSERT AGE HERE (in the HTML part). How do I define the age and the print it? <?php //Prevent the included file from being called directly. if(basename($_SERVER['PHP_SELF']) == "newestmember.inc.php") { header("Location: /index.php"); exit; } $connection = @mysql_connect("$db_host", "$db_user", "$db_pass") or die("Couldn't connect."); $db = @mysql_select_db($db_name, $connection) or die("Couldn't select database."); $sql = "SELECT p.*, i.* FROM images i JOIN profile p ON p.profile_id = i.image_id WHERE i.displayname != 'Community' AND default_pic = 'yes' ORDER BY image_id DESC LIMIT 0, 5"; $result = @mysql_query($sql,$connection) or die("Couldn't execute query."); $num=mysql_num_rows($result); if($num < 1){ echo "<center>No Members with pictures found.</center>"; } else { ?> <table align="center" cellpadding="4" cellspacing="0" width="100%"> <? while ($row = mysql_fetch_array($result)) { $url = $row['url']; $image = $row['image']; $member = $row['displayname']; $fullurl = "$userurl/$url"; $src = "$userdir/$url/$image"; echo "<table style='text-align: left; width: 100%;' border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td>new to lounge{in}</td> </tr> </tbody> </table> <table style='text-align: left; width: 100%;' border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td><a href=\'$fullurl\'><img src=\'thumbs/phpThumb.php?src=/$src&w=50\' border=\'0\' alt=\'$member\'></a></td> <td align='undefined' valign='undefined'> <table style='text-align: left; width: 100%;' border='0' cellpadding='0' cellspacing='0'> <tbody> <tr> <td><a href=\"$fullurl\">$member</a>INSERT AGE HERE</td> </tr> <tr> <td align='undefined' valign='undefined'>location</td> </tr> </tbody> </table> </td> </tr> <tr> <td align='undefined' valign='undefined'>sgl div</td> <td align='undefined' valign='undefined'>sgl div</td> </tr> </tbody> </table>"; } ?> <? } ?>