Jump to content

rows with duplicate data in one column-- only display once


fwapah

Recommended Posts

i have a table that has multiple reviews tied to multiple reviewers. the columns for each row are reviewer, product id, product score. ed jones reviewed product 1 and product 2, and shirley smith reviewed product 2 and product 3. each reviewer/review combo has its own row.

 

my question is, how do i display

Product 1, Score Jones

Product 2, Score Jones, Score Smith

Product 3, Score Smith

 

I am not sure how I can get the scores from each row to correlate with the product in one row.

 

thanks so much for your help.. can't quite wrap my head around this one.

Link to comment
Share on other sites

Sorry, don't think I was clear on the first post.

 

I have a table, reviews, that looks like this

Reviewer Prod Num Score

Jones12.1

Jones21.6

Smith21.5

Smith32.7

 

I'm trying to get it to output this:

Prod Num Reviewer1 Score Reviewer2 Score

1Jones2.1

2Jones1.6Smith1.5

3Smith2.7

 

Thanks again for the help!!

Link to comment
Share on other sites

i guess i would query the database like this:

 

SELECT * FROM reviews ORDER BY Reviewer, Prod;

 

Then I would loop over the records, creating an array of arrays, $bigArray, with keys Reviewer and values an array for each reviewer, using the product number as key and score as value.

 

$sql = "SELECT * FROM reviews ORDER BY Reviewer, Prod";
$result = mysql_query($sql) or die(mysql_error());

$bigArray = array();
$current_reviewer = "";
while (list($reviewer, $prodnum, $score) = mysql_fetch_row($result) {
     if ($reviewer != $current_reviewer) {
          if ($current_reviewer > "") {
                $bigArray["$current_reviewer"] = $reviewer_array;
          }
          $reviewer_array = array();
          $current_reviewer = $reviewer;
     }

     $reviewer_array[$prodnum] = $score;
}

 

Then I would loop over the stored results...

 

for ($i=0;$i<$number_of_products;$i++) {
     foreach ($bigArray AS $reviewer_name=>$prod_scores) {
          echo "$i $reviewer_name $prod_scores[$i] <BR>";
     }
}

 

or something like that...

 

yikes, barand has a possibly much simpler solution above me.    :D

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.