Jump to content

echo how long ago an action was made


searls03

Recommended Posts

here is a code I have to echo how long ago a post was made.......it works, sorta, but it starts counting up minutes and when it reaches like 2 hours, it says 1minute ago.  do you see wht is wrong with this logic?

 

 $days = floor($row['TimeSpent'] / (60 * 60 * 24));
		$remainder = $row['TimeSpent'] % (60 * 60 * 24);
		$hours = floor($remainder / (60 * 60));
		$remainder = $remainder % (60 * 60);
		$minutes = floor($remainder / 60);
		$seconds = $remainder % 60;

		if($days > 0){
		echo date('F d Y', $row['date_created']);
		}else if($days == 0 && $hours == 0 && $minutes == 0){
		echo "few seconds ago";		
		}elseif($days == 0 && $hours == 0){
		echo $minutes.' minutes ago';
		}else {
echo $minutes.' minutes ago';}

Link to comment
Share on other sites

What is the value of $row['TimeSpent']? It is a mysql Timestamp, a PHP timestamp or what? I'm not sure I even understand what it's purpose is. You have a field called $row['date_created'] - isn't that the value you should be using for your calculations?

 

Edit: Same question for $row['date_created'] as to field type/value.

Link to comment
Share on other sites

here is entire code, it may clear stuff up:

<?php
session_start();
include('dbcon.php');
$username1 = $_SESSION['username'];
$name1 = $_SESSION['name'];
// set time of last activity
$userTime = time();
mysql_query("update `sessions` set  `activity` = '$userTime' where username='$username1'");
$inactivityTime = time() - 120; // 2 minutes
mysql_query("update `sessions` set `loggedin` = '0' where `activity` < '$inactivityTime' ");
$username = $rows['f_name'];
$sql = mysql_query("SELECT * from pics WHERE user='$username1'");
while($row = mysql_fetch_array($sql)){
$link123 = $row["link"];
}
function checkValues($value)
{
	 $value = trim($value);

	if (get_magic_quotes_gpc()) {
		$value = stripslashes($value);
	}

	 $value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));

	 $value = strip_tags($value);
	$value = mysql_real_escape_string($value);
	$value = htmlspecialchars ($value);
	return $value;

}	

function clickable_link($text = '')
{
	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
	$ret = ' ' . $text;
	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
	$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
	$ret = substr($ret, 1);
	return $ret;
}

$next_records = 10;
$show_more_button = 0;
if(checkValues($_REQUEST['value']))
{
	$userip = $_SERVER['REMOTE_ADDR'];
	echo "INSERT INTO facebook_posts (post,f_name,userip,date_created, pic) VALUES('".checkValues($_REQUEST['value'])."','$name1','".$userip."','".strtotime(date("Y-m-d H:i:s"))."','$link123')";

	mysql_query("INSERT INTO facebook_posts (post,f_name,userip,date_created, pic) VALUES('".checkValues($_REQUEST['value'])."','$name1','".$userip."','".strtotime(date("Y-m-d H:i:s"))."', '$link123')");

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 1");

}
elseif($_REQUEST['show_more_post']) // more posting paging
{
	$next_records = $_REQUEST['show_more_post'] + 10;

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit ".$_REQUEST['show_more_post'].", 10");

	$check_res = mysql_query("SELECT * FROM facebook_posts order by p_id desc limit ".$next_records.", 10");

	$show_more_button = 0; // button in the end

	$check_result = mysql_num_rows(@$check_res);
	if($check_result > 0)
	{
		$show_more_button = 1;
	}
}
else
{	
	$show_more_button = 1;
	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 0,10");

}

while ($row = mysql_fetch_array($result))
{
	$comments = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS CommentTimeSpent FROM facebook_posts_comments where post_id = ".$row['p_id']." order by c_id asc");		?>
   <div class="friends_area" id="record-<?php  echo $row['p_id']?>">
        <img src="<?php echo $row['pic'];//////////////////////////////////////////////////////////////////////////////////////////////////////here are comments, one spot where i having issues ?>" width="40" class="CommentImg" style="float:left;" alt="" />
     <label style="float:left" class="name">

	   <b><?php echo $row['f_name'];?></b>

	   <em><?php  echo clickable_link($row['post']);?></em>
	   <br clear="all" />

	   <span>
	   <?php  
	   
	    // echo strtotime($row['date_created'],"Y-m-d H:i:s");
   		    
	    $days = floor($row['TimeSpent'] / (60 * 60 * 24));
		$remainder = $row['TimeSpent'] % (60 * 60 * 24);
		$hours = floor($remainder / (60 * 60));
		$remainder = $remainder % (60 * 60);
		$minutes = floor($remainder / 60);
		$seconds = $remainder % 60;

		if($days > 0){
		echo date('F d Y', $row['date_created']);
		}else if($days == 0 && $hours == 0 && $minutes == 0){
		echo "few seconds ago";		
		}elseif($days == 0 && $hours == 0){
		echo $minutes.' minutes ago';
		}else {
echo $minutes.' minutes ago';}

	   ?>
	   
	   </span>
	   <a href="javascript: void(0)" id="post_id<?php  echo $row['p_id']?>" class="showCommentBox">Comments</a>

	   </label>
	   <?php
		$userip = $_SERVER['REMOTE_ADDR'];
		if($row['userip'] == $userip){?>
	  	<a href="#" class="delete"> Remove</a>
	   <?php
		}?>
	    <br clear="all" />
		<div id="CommentPosted<?php  echo $row['p_id']?>">
			<?php
			$comment_num_row = mysql_num_rows(@$comments);
			if($comment_num_row > 0)
			{
				while ($rows = mysql_fetch_array($comments))
				{
					$days2 = floor($rows['CommentTimeSpent'] / (60 * 60 * 24));
					$remainder = $rows['CommentTimeSpent'] % (60 * 60 * 24);
					$hours = floor($remainder / (60 * 60));
					$remainder = $remainder % (60 * 60);
					$minutes = floor($remainder / 60);
					$seconds = $remainder % 60;						
					?>
				<div class="commentPanel" id="record-<?php  echo $rows['c_id'];?>" align="left">
                    <img src="<?php echo $rows['pic'];//////////////////////////////////////////////////////////////////////////////////////////////////////here are comments, one spot where i having issues ?>" width="40" class="CommentImg" style="float:left;" alt="" />
				  <label class="postedComments" >          <strong><font color="#3B5998">   <?php echo $rows['f_name'];?></font></strong>

					  <?php  echo clickable_link($rows['comments']);?>
				  </label>
					<br clear="all" />
					<span style="margin-left:43px; color:#666666; font-size:11px">
					<?php

					if($days2 > 0){
					echo date('F d Y', $rows['date_created']);}
					elseif($days2 == 0 && $hours == 0 && $minutes == 0){
					echo "few seconds ago";		
					}elseif($days2 == 0 && $hours == 0){
					echo $minutes.' minutes ago';
					}else{
echo $minutes.' minutes ago';}
					?>
					</span>
					<?php
					$userip = $_SERVER['REMOTE_ADDR'];
					if($rows['userip'] == $userip){?>
					  <a href="#" id="CID-<?php  echo $rows['c_id'];?>" class="c_delete">Delete</a>
					<?php
					}?>
				</div>
				<?php
				}?>				
				<?php
			}?>
		</div>
		<div class="commentBox" align="right" id="commentBox-<?php  echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?> >

			<label id="record-<?php  echo $row['p_id'];?>" >
				<textarea class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" name="commentMark" cols="60"></textarea>
			</label>
			<br clear="all" />
			<a id="SubmitComment" class="small button comment"> Comment</a>
		</div>
   </div>
<?php
}
if($show_more_button == 1){?>
<div id="bottomMoreButton">
<a id="more_<?php echo @$next_records?>" class="more_records" href="javascript: void(0)">Older Posts</a>
</div>
<?php
}?>

 

 

and I think they are basically the number of seconds from like 1900 or something like that.  some year anyway.

Link to comment
Share on other sites

OK, I would use PHP to do all the logic and remove the dynamic creation of 'Timespent' from the database query - you can get what you need just using $row['date_created'].

 

Here is a function that you can use to get a text description for when the record was created. Just pass $row['date_created'] to the function. The function will return an appropriate value based upon whether the record was created seconds, minutes, hours or days ago. Currently, it will show 1 day (or n days), but you can change that the the date by un-commenting the line shown and removing the one after it.

 

function timeSince($timestamp)
{
    $minute = 60;
    $hour   = $minute * 60;
    $day   =  $hour * 24;

    $secondsSince = time() - $timestamp;

    if($secondsSince >= $day)
    {
        $daysSince = floor($secondsSince/$day);
        $s = ($daysSince>1) ? 's' : '';
        //return date('F d Y', $row['date_created'])
        return "{$daysSince} day{$s} ago.";
    }

    if($secondsSince >= $hour)
    {
        $hoursSince = floor($secondsSince/$hour);
        $s = ($hoursSince>1) ? 's' : '';
        return "{$hoursSince} hour{$s} ago.";
    }

    if($secondsSince >= $minute)
    {
        $minutesSince = floor($secondsSince/$minute);
        $s = ($minutesSince>1) ? 's' : '';
        return "{$minutesSince} minute{$s} ago.";
    }

    $s = ($secondsSince>1) ? 's' : '';
    return "{$secondsSince} second{$s} ago.";
}

Link to comment
Share on other sites

here is what I have, but i get an error saying it can't redeclare the function timespent on line 101

 

<?php
session_start();
include('dbcon.php');
$username1 = $_SESSION['username'];
$name1 = $_SESSION['name'];
// set time of last activity
$userTime = time();
mysql_query("update `sessions` set  `activity` = '$userTime' where username='$username1'");
$inactivityTime = time() - 120; // 2 minutes
mysql_query("update `sessions` set `loggedin` = '0' where `activity` < '$inactivityTime' ");
$username = $rows['f_name'];
$sql = mysql_query("SELECT * from pics WHERE user='$username1'");
while($row = mysql_fetch_array($sql)){
$link123 = $row["link"];
}
function checkValues($value)
{
	 $value = trim($value);

	if (get_magic_quotes_gpc()) {
		$value = stripslashes($value);
	}

	 $value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));

	 $value = strip_tags($value);
	$value = mysql_real_escape_string($value);
	$value = htmlspecialchars ($value);
	return $value;

}	

function clickable_link($text = '')
{
	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
	$ret = ' ' . $text;
	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
	$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
	$ret = substr($ret, 1);
	return $ret;
}

$next_records = 10;
$show_more_button = 0;
if(checkValues($_REQUEST['value']))
{
	$userip = $_SERVER['REMOTE_ADDR'];
	echo "INSERT INTO facebook_posts (post,f_name,userip,date_created, pic) VALUES('".checkValues($_REQUEST['value'])."','$name1','".$userip."','".strtotime(date("Y-m-d H:i:s"))."','$link123')";

	mysql_query("INSERT INTO facebook_posts (post,f_name,userip,date_created, pic) VALUES('".checkValues($_REQUEST['value'])."','$name1','".$userip."','".strtotime(date("Y-m-d H:i:s"))."', '$link123')");

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 1");

}
elseif($_REQUEST['show_more_post']) // more posting paging
{
	$next_records = $_REQUEST['show_more_post'] + 10;

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit ".$_REQUEST['show_more_post'].", 10");

	$check_res = mysql_query("SELECT * FROM facebook_posts order by p_id desc limit ".$next_records.", 10");

	$show_more_button = 0; // button in the end

	$check_result = mysql_num_rows(@$check_res);
	if($check_result > 0)
	{
		$show_more_button = 1;
	}
}
else
{	
	$show_more_button = 1;
	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 0,10");

}

while ($row = mysql_fetch_array($result))
{
	$comments = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS CommentTimeSpent FROM facebook_posts_comments where post_id = ".$row['p_id']." order by c_id asc");		?>
   <div class="friends_area" id="record-<?php  echo $row['p_id']?>">
        <img src="<?php echo $row['pic'];//////////////////////////////////////////////////////////////////////////////////////////////////////here are comments, one spot where i having issues ?>" width="40" class="CommentImg" style="float:left;" alt="" />
     <label style="float:left" class="name">

	   <b><?php echo $row['f_name'];?></b>

	   <em><?php  echo clickable_link($row['post']);?></em>
	   <br clear="all" />

	   <span>
	   <?php  
	   
	    // echo strtotime($row['date_created'],"Y-m-d H:i:s");
   		    
	    function timeSince($timestamp)
{
    $minute = 60;
    $hour   = $minute * 60;
    $day   =  $hour * 24;

    $secondsSince = time() - $timestamp;

    if($secondsSince >= $day)
    {
        $daysSince = floor($secondsSince/$day);
        $s = ($daysSince>1) ? 's' : '';
        //return date('F d Y', $row['date_created'])
        return "{$daysSince} day{$s} ago.";
    }

    if($secondsSince >= $hour)
    {
        $hoursSince = floor($secondsSince/$hour);
        $s = ($hoursSince>1) ? 's' : '';
        return "{$hoursSince} hour{$s} ago.";
    }

    if($secondsSince >= $minute)
    {
        $minutesSince = floor($secondsSince/$minute);
        $s = ($minutesSince>1) ? 's' : '';
        return "{$minutesSince} minute{$s} ago.";
    }

    $s = ($secondsSince>1) ? 's' : '';
    return "{$secondsSince} second{$s} ago.";
}

	   ?>
	   
	   </span>
	   <a href="javascript: void(0)" id="post_id<?php  echo $row['p_id']?>" class="showCommentBox">Comments</a>

	   </label>
	   <?php
		$userip = $_SERVER['REMOTE_ADDR'];
		if($row['userip'] == $userip){?>
	  	<a href="#" class="delete"> Remove</a>
	   <?php
		}?>
	    <br clear="all" />
		<div id="CommentPosted<?php  echo $row['p_id']?>">
			<?php
			$comment_num_row = mysql_num_rows(@$comments);
			if($comment_num_row > 0)
			{
				while ($rows = mysql_fetch_array($comments))
				{
					$days2 = floor($rows['CommentTimeSpent'] / (60 * 60 * 24));
					$remainder = $rows['CommentTimeSpent'] % (60 * 60 * 24);
					$hours = floor($remainder / (60 * 60));
					$remainder = $remainder % (60 * 60);
					$minutes = floor($remainder / 60);
					$seconds = $remainder % 60;						
					?>
				<div class="commentPanel" id="record-<?php  echo $rows['c_id'];?>" align="left">
                    <img src="<?php echo $rows['pic'];//////////////////////////////////////////////////////////////////////////////////////////////////////here are comments, one spot where i having issues ?>" width="40" class="CommentImg" style="float:left;" alt="" />
				  <label class="postedComments" >          <strong><font color="#3B5998">   <?php echo $rows['f_name'];?></font></strong>

					  <?php  echo clickable_link($rows['comments']);?>
				  </label>
					<br clear="all" />
					<span style="margin-left:43px; color:#666666; font-size:11px">
					<?php

					if($days2 > 0){
					echo date('F d Y', $rows['date_created']);}
					elseif($days2 == 0 && $hours == 0 && $minutes == 0){
					echo "few seconds ago";		
					}elseif($days2 == 0 && $hours == 0){
					echo $minutes.' minutes ago';
					}else{
echo $minutes.' minutes ago';}
					?>
					</span>
					<?php
					$userip = $_SERVER['REMOTE_ADDR'];
					if($rows['userip'] == $userip){?>
					  <a href="#" id="CID-<?php  echo $rows['c_id'];?>" class="c_delete">Delete</a>
					<?php
					}?>
				</div>
				<?php
				}?>				
				<?php
			}?>
		</div>
		<div class="commentBox" align="right" id="commentBox-<?php  echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?> >

			<label id="record-<?php  echo $row['p_id'];?>" >
				<textarea class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" name="commentMark" cols="60"></textarea>
			</label>
			<br clear="all" />
			<a id="SubmitComment" class="small button comment"> Comment</a>
		</div>
   </div>
<?php
}
if($show_more_button == 1){?>
<div id="bottomMoreButton">
<a id="more_<?php echo @$next_records?>" class="more_records" href="javascript: void(0)">Older Posts</a>
</div>
<?php
}?>

Link to comment
Share on other sites

Is that error with "timespent" or "timesince".

 

"timespent" is the dynamically created MySQL value that you are suing which I suggested was not necessary.

 

"timesince" is the function I provided. So, I am assuming the error is with that. But, I only see you defining that function once in the code above.

Link to comment
Share on other sites

You should find out what functions are and how they work. What means declaring a function and what means using it after it has been declared. After you understand these things you can continue working on the script. When you understand these things, you find the answer for the error in this thread already.

Link to comment
Share on other sites

Good luck to you. I'm done with this post.

I feel the same way about this poster.  Waay too much work and poorly asked questions.  If there was a stat to track the "average number of replies per thread" I'd bet the OP has one of the longest as he/she asks very very vague questions and posts a lot of "well how do I fix it?" and "what would you do?" replies.  This causes a ton of dragging on back/forth in the posts.  It's funny cause you even have it in your signature "The quality of the responses received is directly proportional to the quality of the question asked." ;-)
Link to comment
Share on other sites

and to all of u that wonder, I am teaching myself php I am not taking a class from anywhere, that is why I ask so many questions.  This forum is my main source of help.  I will try to post better questions in the future, just sometimes I don't know how to say what I am thinking, I am a much better shower than putting those thoughts into words.  I am sorry for vague posts, and I will try to stop.  Just please remember, some people, like me, are starting out with php and don't know as much as others.  I am sorry for any trouble/grief I have caused you. 

Link to comment
Share on other sites

No grief.  I too am a self taught php user.  No classes ever.  You need to show more effort in your posts that you actually tried things.  Saying stuff like "it didn't work" or "is there a way to fix that?" shows that you didn't even try.  For your previous question of what a variables value is.  What did you try to figure it out?  Did you try to echo it to the screen?  What did it say??

Link to comment
Share on other sites

there is no vale when I echo it.  do you think it is supposed to be date_created or what?  I think that is now the problem as to why it doesn't work.  I will include my new code so someone could also tell me if I wrote the function right(this is after I took echo $timestamp out).  I am pretty sure I wrote it correctly. 

 

<?php
session_start();
include('dbcon.php');
$username1 = $_SESSION['username'];
$name1 = $_SESSION['name'];
// set time of last activity
$userTime = time();
mysql_query("update `sessions` set  `activity` = '$userTime' where username='$username1'");
$inactivityTime = time() - 120; // 2 minutes
mysql_query("update `sessions` set `loggedin` = '0' where `activity` < '$inactivityTime' ");
$username = $rows['f_name'];
$sql = mysql_query("SELECT * from pics WHERE user='$username1'");
while($row = mysql_fetch_array($sql)){
$link123 = $row["link"];
}   		  

function timeSince($timestamp)
{
    $minute = 60;
    $hour   = $minute * 60;
    $day   =  $hour * 24;

    $secondsSince = time() - $timestamp;

    if($secondsSince >= $day)
    {
        $daysSince = floor($secondsSince/$day);
        $s = ($daysSince>1) ? 's' : '';
        //return date('F d Y', $row['date_created'])
        return "{$daysSince} day{$s} ago.";
    }

    if($secondsSince >= $hour)
    {
        $hoursSince = floor($secondsSince/$hour);
        $s = ($hoursSince>1) ? 's' : '';
        return "{$hoursSince} hour{$s} ago.";
    }

    if($secondsSince >= $minute)
    {
        $minutesSince = floor($secondsSince/$minute);
        $s = ($minutesSince>1) ? 's' : '';
        return "{$minutesSince} minute{$s} ago.";
    }

    $s = ($secondsSince>1) ? 's' : '';
    return "{$secondsSince} second{$s} ago.";
}

function checkValues($value)
{
	 $value = trim($value);

	if (get_magic_quotes_gpc()) {
		$value = stripslashes($value);
	}

	 $value = strtr($value,array_flip(get_html_translation_table(HTML_ENTITIES)));

	 $value = strip_tags($value);
	$value = mysql_real_escape_string($value);
	$value = htmlspecialchars ($value);
	return $value;

}	

function clickable_link($text = '')
{
	$text = preg_replace('#(script|about|applet|activex|chrome):#is', "\\1:", $text);
	$ret = ' ' . $text;
	$ret = preg_replace("#(^|[\n ])([\w]+?://[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"\\2\" target=\"_blank\">\\2</a>", $ret);

	$ret = preg_replace("#(^|[\n ])((www|ftp)\.[\w\#$%&~/.\-;:=,?@\[\]+]*)#is", "\\1<a href=\"http://\\2\" target=\"_blank\">\\2</a>", $ret);
	$ret = preg_replace("#(^|[\n ])([a-z0-9&\-_.]+?)@([\w\-]+\.([\w\-\.]+\.)*[\w]+)#i", "\\1<a href=\"mailto:\\2@\\3\">\\2@\\3</a>", $ret);
	$ret = substr($ret, 1);
	return $ret;
}

$next_records = 10;
$show_more_button = 0;
if(checkValues($_REQUEST['value']))
{
	$userip = $_SERVER['REMOTE_ADDR'];
	echo "INSERT INTO facebook_posts (post,f_name,userip,date_created, pic) VALUES('".checkValues($_REQUEST['value'])."','$name1','".$userip."','".strtotime(date("Y-m-d H:i:s"))."','$link123')";

	mysql_query("INSERT INTO facebook_posts (post,f_name,userip,date_created, pic) VALUES('".checkValues($_REQUEST['value'])."','$name1','".$userip."','".strtotime(date("Y-m-d H:i:s"))."', '$link123')");

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 1");

}
elseif($_REQUEST['show_more_post']) // more posting paging
{
	$next_records = $_REQUEST['show_more_post'] + 10;

	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit ".$_REQUEST['show_more_post'].", 10");

	$check_res = mysql_query("SELECT * FROM facebook_posts order by p_id desc limit ".$next_records.", 10");

	$show_more_button = 0; // button in the end

	$check_result = mysql_num_rows(@$check_res);
	if($check_result > 0)
	{
		$show_more_button = 1;
	}
}
else
{	
	$show_more_button = 1;
	$result = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS TimeSpent FROM facebook_posts order by p_id desc limit 0,10");

}

while ($row = mysql_fetch_array($result))
{
	$comments = mysql_query("SELECT *,
	UNIX_TIMESTAMP() - date_created AS CommentTimeSpent FROM facebook_posts_comments where post_id = ".$row['p_id']." order by c_id asc");		?>
   <div class="friends_area" id="record-<?php  echo $row['p_id']?>">
        <img src="<?php echo $row['pic'];//////////////////////////////////////////////////////////////////////////////////////////////////////here are comments, one spot where i having issues ?>" width="40" class="CommentImg" style="float:left;" alt="" />
     <label style="float:left" class="name">

	   <b><?php echo $row['f_name'];?></b>

	   <em><?php  echo clickable_link($row['post']);?></em>
	   <br clear="all" />

	   <span>
	   <?php  
	   
	    // echo strtotime($row['date_created'],"Y-m-d H:i:s");

		timeSince($timestamp);





	   
	   ?>
	   
	   </span>
	   <a href="javascript: void(0)" id="post_id<?php  echo $row['p_id']?>" class="showCommentBox">Comments</a>

	   </label>
	   <?php
		$userip = $_SERVER['REMOTE_ADDR'];
		if($row['userip'] == $userip){?>
	  	<a href="#" class="delete"> Remove</a>
	   <?php
		}?>
	    <br clear="all" />
		<div id="CommentPosted<?php  echo $row['p_id']?>">
			<?php
			$comment_num_row = mysql_num_rows(@$comments);
			if($comment_num_row > 0)
			{
				while ($rows = mysql_fetch_array($comments))
				{
					$days2 = floor($rows['CommentTimeSpent'] / (60 * 60 * 24));
					$remainder = $rows['CommentTimeSpent'] % (60 * 60 * 24);
					$hours = floor($remainder / (60 * 60));
					$remainder = $remainder % (60 * 60);
					$minutes = floor($remainder / 60);
					$seconds = $remainder % 60;						
					?>
				<div class="commentPanel" id="record-<?php  echo $rows['c_id'];?>" align="left">
                    <img src="<?php echo $rows['pic'];//////////////////////////////////////////////////////////////////////////////////////////////////////here are comments, one spot where i having issues ?>" width="40" class="CommentImg" style="float:left;" alt="" />
				  <label class="postedComments" >          <strong><font color="#3B5998">   <?php echo $rows['f_name'];?></font></strong>

					  <?php  echo clickable_link($rows['comments']);?>
				  </label>
					<br clear="all" />
					<span style="margin-left:43px; color:#666666; font-size:11px">
					<?php

					if($days2 > 0){
					echo date('F d Y', $rows['date_created']);}
					elseif($days2 == 0 && $hours == 0 && $minutes == 0){
					echo "few seconds ago";		
					}elseif($days2 == 0 && $hours == 0){
					echo $minutes.' minutes ago';
					}else{
echo $minutes.' minutes ago';}
					?>
					</span>
					<?php
					$userip = $_SERVER['REMOTE_ADDR'];
					if($rows['userip'] == $userip){?>
					  <a href="#" id="CID-<?php  echo $rows['c_id'];?>" class="c_delete">Delete</a>
					<?php
					}?>
				</div>
				<?php
				}?>				
				<?php
			}?>
		</div>
		<div class="commentBox" align="right" id="commentBox-<?php  echo $row['p_id'];?>" <?php echo (($comment_num_row) ? '' :'style="display:none"')?> >

			<label id="record-<?php  echo $row['p_id'];?>" >
				<textarea class="commentMark" id="commentMark-<?php  echo $row['p_id'];?>" name="commentMark" cols="60"></textarea>
			</label>
			<br clear="all" />
			<a id="SubmitComment" class="small button comment"> Comment</a>
		</div>
   </div>
<?php
}
if($show_more_button == 1){?>
<div id="bottomMoreButton">
<a id="more_<?php echo @$next_records?>" class="more_records" href="javascript: void(0)">Older Posts</a>
</div>
<?php
}?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.