help with class function and query result

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
djdavedawson
Forum Newbie
Posts: 9
Joined: Tue Jul 29, 2008 10:13 am

help with class function and query result

Post by djdavedawson »

:banghead: Hello,

I'm trying to modify this function to send the result of a query. This function creates the message of an email.

Here is the part the class function i need to modify:

Code: Select all

function send($newsletter_id) {
      global $db;
      $audience_select = get_audience_sql_query($this->query_name, 'newsletters');
      $audience = $db->Execute($audience_select['query_string']);
      $records = $audience->RecordCount();
      if ($records==0) return 0;
    $i=0;
 
      while (!$audience->EOF) {
    $i++;
      $html_msg['EMAIL_FIRST_NAME'] = $audience->fields['customers_firstname'];
      $html_msg['EMAIL_LAST_NAME']  = $audience->fields['customers_lastname'];
      $html_msg['EMAIL_MESSAGE_HTML'] = $this->content_html;
       }
Ok so "$this->content_html;" is pulling the info from the db to send, but I need the info modified and then sent.

So i have this little scrpt here that modifies the info for another page on the site:

Code: Select all

<?
$result = mysql_query("SELECT * FROM newsletters WHERE newsletters_id ='" . ($_GET['ID']) . "'");
 
echo "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#00FF00\">";
 
while($r=mysql_fetch_array($result))
 
{
 
$items = explode(", ", $r['content_html']);
 
   $num = count($items);
   $row++;
    for ($c=0; $c < $num; $c++) 
    {echo  "<tr><td>".$items[$c]."</td></tr>";}
}
 
echo "</table>";
 
?>

So what i'm looking at is having the result of this script equate to the "$this->content_html;" part of the function.

I've been trying to figure this out for a few days and it's really frustrating.

Please help

Thanks

DD
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: help with class function and query result

Post by Chalks »

you could do this pretty easily, just modify your class to include this:

Code: Select all

 function createHTML()
{
  $result = mysql_query("SELECT * FROM newsletters WHERE newsletters_id ='" . ($_GET['ID']) . "'");
  $html = "<table width=\"100%\" border=\"1\" cellpadding=\"0\" cellspacing=\"0\" bgcolor=\"#00FF00\">";
 
  while($r=mysql_fetch_array($result))
  {
    $items = explode(", ", $r['content_html']);
    $num = count($items);
    $row++;
    for ($c=0; $c < $num; $c++) 
      $html .=  "<tr><td>" . $items[$c] . "</td></tr>";
  }
  $html .= "</table>";
  return $html;
}
function send($newsletter_id)
{
  global $db;
  $audience_select = get_audience_sql_query($this->query_name, 'newsletters');
  $audience = $db->Execute($audience_select['query_string']);
  $records = $audience->RecordCount();
  if ($records==0) return 0;
    $i=0;
 
  while (!$audience->EOF)
  {
    $i++;
    $html_msg['EMAIL_FIRST_NAME'] = $audience->fields['customers_firstname'];
    $html_msg['EMAIL_LAST_NAME']  = $audience->fields['customers_lastname'];
    $html_msg['EMAIL_MESSAGE_HTML'] = $this->createHTML();  //note, I changed this to $this->createHTML().  Everything else in this function is the same.
  }
}
Just make sure you have a connection to a database present while you run createHTML(), and you'll be fine.
djdavedawson
Forum Newbie
Posts: 9
Joined: Tue Jul 29, 2008 10:13 am

Re: help with class function and query result

Post by djdavedawson »

You Rock !! this is great Thanks.

1 Question, cause I am new to working with classes.

Why are there "." before the equal signs on these :


$html .=  "<tr><td>" . $items[$c] . "</td></tr>";
$html .= "</table>";
 
User avatar
Chalks
Forum Contributor
Posts: 447
Joined: Thu Jul 12, 2007 7:55 am
Location: Indiana

Re: help with class function and query result

Post by Chalks »

djdavedawson wrote:Why are there "." before the equal signs on these :

$html .=  "<tr><td>" . $items[$c] . "</td></tr>";
$html .= "</table>";
 
this is exactly the same as saying
$html = $html . "<tr><td>" . $items[$c] . "</td></tr>";

It's just a shortcut.
djdavedawson
Forum Newbie
Posts: 9
Joined: Tue Jul 29, 2008 10:13 am

Re: help with class function and query result

Post by djdavedawson »

Thanks Again
Post Reply