Jump to content

HELP!!! GROUP fetch_assoc by SAME data


Stella_r

Recommended Posts

I'm having trouble separating an element from an array that I've taken from the database.  ???

 

and here is how it displays.....

 

Title one

2009-03-08 20:53:25 new comment by UserID4

 

Title Two

2009-03-09 01:35:29 new comment by UserID4

 

Title Two

2009-03-09 01:39:08 new comment by UserID4

 

Title Three

2009-03-10 22:26:54 new comment by UserID10

 

But what I want to do is:

 

if Entry_ID's are identical, display the corresponding Entry_Title only once with the rest of the info following

as below...

 

Title one

2009-03-08 20:53:25 new comment by 4

 

Title Two

2009-03-09 01:35:29 new comment by 4

2009-03-09 01:39:08 new comment by 4

 

Title Three

2009-03-10 22:26:54 new comment by 10

 

Here is a print_r of the arrays.....from my query:"SELECT Entry_Title, Entry_Date, comment.Dream_ID, Comment_Date, comment.User_ID FROM comment, entry WHERE comment.Entry_ID=entry.Entry_ID AND dentry.User_ID=$User_ID AND Comment_Read='FALSE'";

 

Array

 

(

[Entry_Title] => Title One

 

[Entry_Date] => 2009-02-26

[Entry_ID] => 31

 

[Comment_Date] => 2009-03-08 20:53:25

[user_ID] => 4

 

)

Array

(

 

[Entry_Title] => Title Two

[Entry_Date] => 2009-02-26

 

[Entry_ID] => 27

[Comment_Date] => 2009-03-09 01:35:29

 

[user_ID] => 4

)

Array

 

(

[Entry_Title] => Title Two

 

[Entry_Date] => 2009-02-26

[Entry_ID] => 27

 

[Comment_Date] => 2009-03-09 01:39:08

[user_ID] => 4

 

)

Array

(

 

[Entry_Title] => Title Three

[Dream_Date] => 2009-02-26

 

[Entry_ID] => 25

[Entry_Date] => 2009-03-10 22:26:54

 

[user_ID] => 10

)

 

 

 

Here is my function...

 

 

protected function displayNewComments()

 

{

$new_comment = $this->model->getReadComment($_SESSION['User_ID']);

 

 

$html ='<div id="user">'."\n";

 

$html .="<div class='entry_header_space'>".$new_comment."</div>";

echo $html;

 

 

$rso=$this->model->getUnreadComments($_SESSION['User_ID']);

 

 

 

while($comments=$rso->fetch_assoc())

 

{

 

 

 

$html="<h2>".$comments['Entry_Title']."</h2>";

$html .=$comments['Comment_Date'] ." new comment by ".$comments['User_ID'] ;

 

echo $html;

 

}

 

(I've tried various things but none of them work quite right.) ???

Link to comment
https://forums.phpfreaks.com/topic/149214-help-group-fetch_assoc-by-same-data/
Share on other sites

try

protected function displayNewComments()

{
$new_comment = $this->model->getReadComment($_SESSION['User_ID']);
$html ='<div id="user">'."\n";
$html .="<div class='entry_header_space'>".$new_comment."</div>";
echo $html;
$rso=$this->model->getUnreadComments($_SESSION['User_ID']);
$last_title = '';
while($comments=$rso->fetch_assoc())
{
	if ($last_title != $comments['Entry_Title']){
		$last_title = $comments['Entry_Title'];
		$html="<h2>".$comments['Entry_Title']."</h2>";
	}
	$html .=$comments['Comment_Date'] ." new comment by ".$comments['User_ID'] ;
	echo $html;
}
}

Thanks! it's a start towards what I want to display,

but it still prints out the same title twice, adding another comment on with each loop....

 

Title one

2009-03-08 20:53:25 new comment by UserID4

 

Title Two

2009-03-09 01:35:29 new comment by UserID4

 

Title Two

2009-03-09 01:39:08 new comment by UserID4

2009-03-09 01:35:29 new comment by UserID4

Title Three

2009-03-10 22:26:54 new comment by UserID10

 

 

oops

try

protected function displayNewComments()

{
$new_comment = $this->model->getReadComment($_SESSION['User_ID']);
$html ='<div id="user">'."\n";
$html .="<div class='entry_header_space'>".$new_comment."</div>";
echo $html;
$rso=$this->model->getUnreadComments($_SESSION['User_ID']);
$last_title = '';
while($comments=$rso->fetch_assoc())
{
	if ($last_title != $comments['Entry_Title']){
		$last_title = $comments['Entry_Title'];
		$html="<h2>".$comments['Entry_Title']."</h2>";
	} else $html = '';
	$html .=$comments['Comment_Date'] ." new comment by ".$comments['User_ID'] ;
	echo $html;
}
}

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.