Empty variable template in viewprofile?

This forum is now closed as part of retiring phpBB2.
Forum rules
READ: phpBB.com Board-Wide Rules and Regulations

This forum is now closed due to phpBB2.0 being retired.
Post Reply
tkills
Registered User
Posts: 32
Joined: Wed Feb 23, 2005 7:41 am

Empty variable template in viewprofile?

Post by tkills » Sat Mar 12, 2005 2:25 am

Alright, what I'm trying to do is make it so that in viewprofile if a user has no comments given to them or accepted, a sort of <--no comments--> type template would show up. It would work similar to how on Smartor's photo album mod where it says they have not yet uploaded any photos.

I'm pretty sure it should be coded somewhere in following sequence. If I could get some help with what to put in there, I would be really grateful. I keep getting the damn parse errors.

Here it is:

Code: Select all

$template->assign_vars(array(
	'FRIEND_COMMENTS' => $lang['Friend_comments'],
	'TOTAL_COMMENTS' => sprintf($lang['total_count'], $total_comments ))
);

if( $total_comments > 5)
{
	$template->assign_vars(array(
	'LINK_MORE_FCOMMENTS' => '<A href="' . append_sid("friends.$phpEx?u=" . $profiledata['user_id']) . '">more</a>' )
	);
}



for( $j=0; $j<count($commentsdata); $j++ )
{
	$template->assign_block_vars('commentsrow', array(
		'FROM' => $commentsdata[$j]['username'],
		'USERLINK' => "profile.php?mode=viewprofile&u=" . $commentsdata[$j]['user_id'],
		'COMMENT' => $commentsdata[$j]['comment'])
	);
}

juliekate
Registered User
Posts: 779
Joined: Sun May 05, 2002 5:32 pm
Location: Philadelphia
Contact:

Post by juliekate » Sat Mar 12, 2005 7:07 pm

Try something like this...I assumed some vars in your sql

Code: Select all

//u is for the viewprofile&u= var
$thisperson = $HTTP_GET_VARS['u'];

$sql = "SELECT comment_text, comment_user_id, profile_id, COUNT(comment_id) AS count FROM " . COMMENTS_TABLE . "
	WHERE user_id = '" . $userdata['user_id'] . "'
	ORDER BY comment_time DESC
	WHERE profile_id = '$thisperson';"
if( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not get comments', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_fetchrow($result);
$commentrow = array();
$total_comments = $row['count'];
if ( $total_comments > 0 )
{
	while ( $row = $db->sql_fetchrow($result) )
	{
		$commentrow[] = $row;
	}
	$comment_limit = 5;

	for ( $i = 0; $i < $comment_limit; $i++ )
	{
		$poster = '<a href="'. append_sid("profile.$phpEx?mode=viewprofile&". POST_USERS_URL .'='. $commentrow[$i]['comment_user_id']) .'" target="_blank" class="nav">'. $commentrow[$i]['comment_user_id'] .'</a>';
		
		//set your vars
		$template->assign_block_vars('comments',array(
			'POSTER' => $poster,
			'COMMENT_TEXT' => $commentrow['comment_text'])
				);
	}
	$more = ( $total_comments > 5 ) ? '<a href="' . append_sid("friends.$phpEx?u=" . $thisperson . ">&raquo; more</a>' : '';
	$template->assign_block_vars('comments.more',array(
		'MORE' = $more)
		);
}
else
{
	$template->assign_block_vars('no_comments',array());
}

//Then set your language vars, these can be used in a switch too without the switch name
$template->assign_vars(array(
	'TOTAL_COMMENTS' => $total_comments,
	'MORE' => $more,
	'L_FRIENDS_COMMENTS' => $lang['Friends_comments'],
	'L_TOTAL_COMMENTS' => $lang['Total_comments'],
	'L_NO_COMMENTS' => $lang['No_comments_yet'])
	);
profile_view_body.tpl

Code: Select all

<td class="row1"><span class="gen"><b>{L_FRIENDS_COMMENTS}</b></span></td>
<td class="row2">
	<table width="100%" cellpadding="0" cellspacing="0" border="0">
	<!-- BEGIN comments -->
		<tr>
			<td><span class="gen">{L_TOTAL_COMMENTS}: {comments.TOTAL_COMMENTS}</span></td>
		</tr>
		<tr>
			<td><span class="gen">{comments.COMMENT_TEXT}</span><br /><span class="gensmall">by {comments.POSTER}</span></td>
		</tr>
	<!-- BEGIN more -->
		<tr>
			<td><span class="gensmall">{comments.more.MORE}</span></td>
		</tr>
	<!-- END more -->
	<!-- END comments -->
	<!-- BEGIN no_comments -->
		<tr>
			<td><span class="gen">(L_NO_COMMENTS}</span></td>
		</tr>
	<!-- END no_comments -->
	</table>
</td>
</tr>

tkills
Registered User
Posts: 32
Joined: Wed Feb 23, 2005 7:41 am

Post by tkills » Sat Mar 12, 2005 9:23 pm

Hmm, that didn't seem to work but I think it's just my bad. I should of clearified more things. I didn't supply all the coding for it before, here's both of the sequences in viewprofile.

Here's the first part of the sequence for comments:

Code: Select all

$sql = "SELECT count(*) as total 
	FROM " . FRIENDS_COMMENTS_TABLE . "
	WHERE to_id = " . $profiledata['user_id'] . "
	AND status = 1";
if ( !($result = $db->sql_query($sql)) )
{
	message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
}
if($row = $db->sql_fetchrow($result))
{
	$total_comments = $row['total'];
}
else
{
	$total_comments = 0;
}
$db->sql_freeresult($result);

if($total_comments)
{
	$sql = "SELECT * 
		FROM ( " . FRIENDS_COMMENTS_TABLE . " c
		LEFT JOIN " . USERS_TABLE . " u ON c.from_id = u.user_id )
		WHERE c.to_id = " . $profiledata['user_id'] . "
		LIMIT 10000";
	if ( !($result = $db->sql_query($sql)) )
	{
		message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
	}
	
	while( $row = $db->sql_fetchrow($result) )
	{
		$commentsdata[] = $row;
	}
	$db->sql_freeresult($result);
}
Part two:

Code: Select all


$template->assign_vars(array(
	'FRIEND_COMMENTS' => $lang['Friend_comments'],
	'TOTAL_COMMENTS' => sprintf($lang['total_count'], $total_comments ))
);

if( $total_comments > 5)
{
	$template->assign_vars(array(
	'LINK_MORE_FCOMMENTS' => '<A href="' . append_sid("friends.$phpEx?u=" . $profiledata['user_id']) . '">more</a>' )
	);
}



for( $j=0; $j<count($commentsdata); $j++ )
{
	$template->assign_block_vars('commentsrow', array(
		'FROM' => $commentsdata[$j]['username'],
		'USERLINK' => "profile.php?mode=viewprofile&u=" . $commentsdata[$j]['user_id'],
		'COMMENT' => $commentsdata[$j]['comment'])
	);
}
Thank you, I appreciate any kind of help.

juliekate
Registered User
Posts: 779
Joined: Sun May 05, 2002 5:32 pm
Location: Philadelphia
Contact:

Post by juliekate » Sun Mar 13, 2005 12:37 am

Okay - try the below and let me know what errors you get. I have done this exact thing in my Bandster mod so trust me I've been through the wringer getting it to work.

To show you what I've done on my page, the code will show "no comments" like http://www.kate-eryn.com/bandster/phpBB ... song_id=25

and if there are comments, there is a limit like http://www.kate-eryn.com/bandster/phpBB ... ?song_id=2 - it only shows five and then there's a link to more.

I should be around, PM me your AOLIM name if you want to chat and get it working.

------------------

If I understand your mod, you are adding data to phpBB's profile.php?mode=viewprofile to show the last 5 comments about the user when their profile is viewed. This code I presume is in /includes/usercp_viewprofile.php. Then, if there are more than 5 comments, there's a link to the friends.php that will show them all.

You can do this in one hunk of code instead of splitting it up.

Is to_id the user_id of the person whose profile is being viewed? That's what I went on.

Code: Select all

$sql = "SELECT count(*) as total
   FROM " . FRIENDS_COMMENTS_TABLE . "
   WHERE to_id = '" . $profiledata['user_id'] . "'
   AND status = 1";
if ( !($result = $db->sql_query($sql)) )
{
   message_die(GENERAL_ERROR, 'Could not query forum moderator information', '', __LINE__, __FILE__, $sql);
}
$row = $db->sql_numrows($result);

$total_comments = ( $row > 0 ) ? $row['count'] : '0';
// Your code was setting a value for total comments no matter what, and then was saying if there's NO value, do this.  which is why it probably didn't work. 
if( $total_comments != '0' )
{
   $sql = "SELECT c.*, u.*
      FROM ( " . FRIENDS_COMMENTS_TABLE . " AS c
      LEFT JOIN " . USERS_TABLE . " AS u ON c.from_id = u.user_id )
      WHERE c.to_id = '" . $profiledata['user_id'] . "'
      LIMIT 10000";
   if ( !($result = $db->sql_query($sql)) )
   {
      message_die(GENERAL_ERROR, 'Could not query friends comments', '', __LINE__, __FILE__, $sql);
   }

	// Have to declare the array
   $commentsdata = array();
   
   while( $row = $db->sql_fetchrow($result) )
   {
	   // fill it
      $commentsdata[] = $row;
   }
   for( $j = 0; $j < count($commentsdata); $j++ )
	{
	   $from = '<a href="'. append_sid("profile.$phpEx?mode=viewprofile&". POST_USERS_URL .'='. $commentsdata[$j]['user_id']) .'" target="_blank">'. $commentsdata[$j]['username'] .'</a>'; 
		$template->assign_block_vars('commentsrow', array(
	      'FROM' => $from,
	      'COMMENT' => $commentsdata[$j]['comment'])
	   );
	} 

	$more = ( $total_comments > 5 ) ? '<a href="' . append_sid("friends.$phpEx?u=" . $profiledata['user_id'] . ">&raquo; more</a>' : '';

	// Have to assign block vars so it will show IF there are more to show
	$template->assign_block_vars('commentsrow.more',array(
		'MORE' = $more)
	); 
}
else
{
	$template->assign_block_vars('no_comments',array()); 
 }
 //Then set your language vars, these can be used in a switch too without the switch name
$template->assign_vars(array(
	'TOTAL_COMMENTS' => $total_comments,
	'MORE' => $more,
	'L_FRIENDS_COMMENTS' => $lang['Friends_comments'],
	'L_TOTAL_COMMENTS' => $lang['Total_comments'],
	'L_NO_COMMENTS' => $lang['No_comments_yet'])
   ); 
    $db->sql_freeresult($result);
Change the TPL to this

Code: Select all

<tr>
<td class="row1"><span class="gen"><b>{L_FRIENDS_COMMENTS}</b></span></td>
<td class="row2">
<!-- setting this in a table so it loops through its own results and does not bug out the profile page -->
   <table width="100%" cellpadding="0" cellspacing="0" border="0">
   <!-- BEGIN commentsrow -->
      <tr>
         <td><span class="gen">{L_TOTAL_COMMENTS}: {TOTAL_COMMENTS}</span></td>
      </tr>
      <tr>
         <td><span class="gen">{commentsrow.COMMENT}</span><br /><span class="gensmall">by {commentsrow.FROM}</span></td>
      </tr>
	<!-- this will not show if there are no "more" results -->
   <!-- BEGIN more -->
      <tr>
         <td><span class="gensmall">{commentsrow.more.MORE}</span></td>
      </tr>
   <!-- END more -->
   <!-- END commentsrow -->
   <!-- BEGIN no_comments -->
      <tr>
         <td><span class="gen">(L_NO_COMMENTS}</span></td>
      </tr>
   <!-- END no_comments -->
   </table>
</td>
</tr>

Post Reply

Return to “[2.0.x] MOD Writers Discussion”

cron