Get $commentID of last $match user.

Greetings all.
I’m trying to modify a snipped of code from my website. It deals with mentions within the forum. You can reply @user and if clicked, the link would take you to their profile. But I’d like to change it so that it takes you up in the same thread to their last comment, as an anchor link.

But I’m having a lot of troubles reading the comment ID from the array being output. I’m a newie at PHP. I understand some of what the code is doing and modify simple bits, but this kept me up until 5am last night.

Any help would be so appreciated! Below is the code, I commented where I attempted to make it work. Below the code is also a sample of the array output.

Thank you for any input you may provide in this!

[php]function bp_qna_get_mention_on_answer($answer) {
global $bp;

$matches = preg_split("/ /", $answer);

$patterns = array();
$replacements = array();

 

	// THIS IS WHERE I COME IN: Attempt to get CommentID of last mentioned ($match) user's answer.
	$ques = bp_qna_screen_single_content();
	$ans = bp_qna_answers($ques->id);	// Gives array with answer id, question id, user id, answer detail, votes, status, answer date //
	$keys = array_keys($ans);
	$commentId = print $ans[$key[0]]->id;
 
 


foreach($matches as $match) {
	if($match[0] == '@') {
		$patterns[] = '/'.$match.'/';
		//$replacements[] = "<a href='".$bp->root_domain."/members/".str_replace('@','',$match)."/"."'>".$match."</a>";
		$replacements[] = "<a class=\'mention\' href=" . bp_core_get_root_domain() . '/' . BP_QNA_SLUG . '/' .  bp_qna_slug_single_root() . '/' . $ques->id . '/' .bp_qna_format_url($ques->title). '#' . $commentId . ">".$match."</a>";
		
		 
					
	}
}

$newAnswer = preg_replace($patterns, $replacements, $answer);

return $newAnswer;

//echo "<pre>"; print_r($newAnswer); echo "</pre>";

}[/php]

// ---- ARRAY SAMPLE ---- //


Array ( 

[0] => stdClass Object ( [id] => 93 [question_id] => 43 [user_id] => 8 [detail] => No tengo tatuajes, pero si no estas muy seguro de hacerlo hasta uno pequeño en un área no muy visible y así si no te sientes bien puedes cubrirlo o posteriormente eliminarlo usando láser, pues ya tecnología existe para ello. Cuidarte mucho [vote] => 1 [status] => 1 [answer_date] => 1275415697 ) 

[1] => stdClass Object ( [id] => 104 [question_id] => 43 [user_id] => 22 [detail] => lo único que le puedo decir es que cuando se lo haga que sea algo que a usted le guste y después no se arrepienta por lo menos yo tengo 20 y no me e arrepentido hasta ahora pero lo que si puede hacer es pensarlo mucho antes de hacerlo [vote] => 1 [status] => 1 [answer_date] => 1275483162 ) 

[2] => stdClass Object ( [id] => 128 [question_id] => 43 [user_id] => 37 [detail] => Pienso que si lo decides debes hacer algo que para ti signifique algo por lo que estés segura que luego no te arrepentirás, los tatuajes son hermosos a mi modo de ver, la piel es el lienzo perfecto para el arte eterno,suerte en tu elección. [vote] => 1 [status] => 1 [answer_date] => 1276022515 ) 

[3] => stdClass Object ( [id] => 131 [question_id] => 43 [user_id] => 38 [detail] => Un tatuaje es algo que cargaras contigo por el resto de tu vida ,si estas seguro de que quieres uno en tu cuerpo,también debes de estar seguro,que te lo haces por las razones correctas y no simple por imitar al resto. tengo un tatuaje del cual no me arrepiento(el gran Poder De Jesucristo) en mi brazo derecho ,jamas me arrepentiré de habérmelo hecho,pero es porque lo deseaba. Existen tatuajes que denigran el carácter de la persona ,no deseas denigrar quien eres en tu interior.Un tatuaje es algo que no es necesario,que en vez de darte puede quitarte,lo llevaras por el resto de tu vida.Valdría la pena pensar si realmente lo deseas? Un tatuaje es como si te pusieras un sello. [vote] => 1 [status] => 1 [answer_date] => 1276027173 ) 

[4] => stdClass Object ( [id] => 138 [question_id] => 43 [user_id] => 9 [detail] => Gracias por sus opiniones a todos, la verdad que lo voy a pensar un poco mas ya que aun no estoy tan segura. Pero luego algo me invento! Gracias. [vote] => 0 [status] => 1 [answer_date] => 1276120120 ) 

[5] => stdClass Object ( [id] => 58023 [question_id] => 43 [user_id] => 6 [detail] => Esto es un test @ruki [vote] => 1 [status] => 1 [answer_date] => 1290386758 ) 

[6] => stdClass Object ( [id] => 58024 [question_id] => 43 [user_id] => 5 [detail] => Esto es un test @jack [vote] => 0 [status] => 1 [answer_date] => 1290405716 ) 

Sponsor our Newsletter | Privacy Policy | Terms of Service