Jump to content

Redundant data display based on multi-value fields -- Newbie Help!!!!


Recommended Posts

Hi All,

 

I have a website where I want to send an email out to a bunch of users of all the new content posted that day. My content is tagged in different genres or groups. A piece of content can have multiple tags. So an example would be that my content is called "Video Program A" and it has been tagged in the vocabulary "Genre" as "Horror" and also as "Narrative". So in my email, if a piece of content has been tagged more than once, all the other fields get printed out multiple times, too. How can I make it so that even if the there are multiple termname and vocabname data, the rest of the data (title, description) only gets printed out once? I am totally stumped on this and would appreciate any insight you can give. Thanks!

<?php

$myDate = date("l \\t\h\e jS \of F Y");

$sql = "SELECT DISTINCT a.nid, a.type, a.title, a.uid, a.status, a.created, a.changed, b.nid, b.field_description_0_value, c.uid, c.name,
d.nid, d.tid, e.tid, e.name as termname, e.vid, f.vid, f.name AS vocabname
FROM node AS a LEFT JOIN node_content_statewide_program AS b ON (a.nid = b.nid) 
LEFT JOIN users AS c ON (a.uid = c.uid)
LEFT JOIN term_node AS d ON (a.nid = d.nid)
LEFT JOIN term_data AS e ON (d.tid = e.tid)
LEFT JOIN vocabulary AS f ON (e.vid = f.vid)
WHERE a.type = 'content_statewide_program' AND a.status = '1' AND a.changed >= '".strtotime($myDate." 08:00:00")."' limit 50";
$rval = mysql_query($sql);
$rows = mysql_num_rows($rval);

$message = "<html><body><br><br><b>There were ".$rows." new submissions on ".$myDate.".";

while ($data = mysql_fetch_assoc($rval)) {

// Here is where the issue is. The tables are all connected on the nid field, and both vocabname and termname fields 
// can have multiple values for the same piece of content. Because of this, everything is getting put out multiple times.
    $message .= "</b> 
    <br><br>
    Submitted By: ".strtoupper($data["name"])."<Br>
    Program Title: ".$data["title"]."<br>Program Description: ".$data["field_description_0_value"]."
    <br>".$data["vocabname"].": ".$data["termname"]."<br><br><hr>";

  
}

  $to = "me@email.com";
  $from = "admin@email.com";
  $subject = "New Content";

  $headers  = "From: $from\r\n";
  $headers .= "Content-type: text/html\r\n";

$message .= "</body></html>";

mail($to, $subject, $message, $headers);


?>

maybe this

 

$message = "<html><body><br><br><b>There were ".$rows." new submissions on ".$myDate.".";

while ($data = mysql_fetch_assoc($rval)) {

// Here is where the issue is. The tables are all connected on the nid field, and both vocabname and termname fields 
// can have multiple values for the same piece of content. Because of this, everything is getting put out multiple times.

$gtitle = strtoupper($data["title"]);
    $Games[$gtitle] = "</b> 
    <br><br>
    Submitted By: ".strtoupper($data["name"])."<Br>
    Program Title: ".$data["title"]."<br>Program Description: ".$data["field_description_0_value"]."
    <br>".$data["vocabname"].": ".$data["termname"];
}
$message .= implode ("<br><br><hr>", $Games )

  $to = "me@email.com";
  $from = "admin@email.com";
  $subject = "New Content";

  $headers  = "From: $from\r\n";
  $headers .= "Content-type: text/html\r\n";

$message .= "</body></html>";

mail($to, $subject, $message, $headers);


?>

Well, this makes it so only the first instances of $data["vocabname"] and $data["termname"] get output, when in face there may be up to 10 of these. I'm not sure how to deal with it-- maybe I have to have 2 mysql queries? Any ideas?

Thanks.

How can I make it so that even if the there are multiple termname and vocabname data, the rest of the data (title, description) only gets printed out once?

 

Well, this makes it so only the first instances of $data["vocabname"] and $data["termname"] get output, when in face there may be up to 10 of these.

 

its based by Title.. whats do you NOT want to be duplicated ?

I want title, description to be displayed only once, but to list as many vocabname and termname as there are. So here's an example:

 

Title: My program's Title

Description: Something Really long

(vocabname1)Series: (termname1) My Series Name

(vocabname2)Producer: (termname2) John Smith

(vocabname3)Subject: (termname3) Literature

 

Am I making sense yet? In my first scenario, the title and description would have gotten printed out for each of the three vocabname/termname pairs. Now, title and description get printed once, but only vocabname1 and termname1 get output, the other 2 do not show up...Thanks!

i see,

so like this, (requires a little clean up)

 

$message = "<html><body><br><br><b>There were ".$rows." new submissions on ".$myDate.".";

while ($data = mysql_fetch_assoc($rval)) {

// Here is where the issue is. The tables are all connected on the nid field, and both vocabname and termname fields 
// can have multiple values for the same piece of content. Because of this, everything is getting put out multiple times.

$gtitle = strtoupper($data["title"]);
    $Games[$gtitle][0] = "</b> 
    <br><br>
    Submitted By: ".strtoupper($data["name"])."<Br>
    Program Title: ".$data["title"];

    $Games[$gtitle][] = "<br>Program Description: ".$data["field_description_0_value"]."
    <br>".$data["vocabname"].": ".$data["termname"];
}
foreach($Games as $game)
{
$message .= implode ("<br>", $game);
$message .= "<br><br><hr>;
}

  $to = "me@email.com";
  $from = "admin@email.com";
  $subject = "New Content";

  $headers  = "From: $from\r\n";
  $headers .= "Content-type: text/html\r\n";

$message .= "</body></html>";

mail($to, $subject, $message, $headers);


?>

 

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.