Page 1 of 1
help with class function and query result
Posted: Tue Jul 29, 2008 10:29 am
by djdavedawson

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
Re: help with class function and query result
Posted: Tue Jul 29, 2008 1:20 pm
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.
Re: help with class function and query result
Posted: Tue Jul 29, 2008 2:12 pm
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>";
Re: help with class function and query result
Posted: Tue Jul 29, 2008 3:09 pm
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.
Re: help with class function and query result
Posted: Wed Jul 30, 2008 10:36 am
by djdavedawson
Thanks Again