You only want to retrieve the news from your table once.
So, pull pull this code:
> $container[] = $message;
> while (list($news, $date) = mysql_fetch_row($newsfetch)) {
> $container[] = '<a href='newslink.php'>' . $news . '</a>';
> $container[] = '<br><hr><br>';
> }
> $container[] = '</body></html>';
outside of (before) this loop:
> while ($data = mysql_fetch_row($emailfetch)) {
~Chris /"\
\ / Microsoft Security Specialist:
X The moron in Oxymoron.
/ \ http://www.thebackrow.net
On Wed, 3 Apr 2002, Gerard Samuel wrote:
> Ok, this one is breaking my back all day.
> First some sudo-code ->
>
> fuction email_to_user() {
> $sql = 'select distinct(email) from user';
> $emailfetch = mysql_query($sql);
>
> $sql = 'select news, date from news order by sid desc limit 10';
> $newsfetch = mysql_query($sql);
>
> while ($data = mysql_fetch_row($emailfetch)) {
> $container = array();
> $container[] = '<html><head><title></head><body>';
>
> $message = 'Have a nice day';
> $container[] = $message;
> // PROBLEM IN THIS WHILE LOOP MAYBE //
> while (list($news, $date) = mysql_fetch_row($newsfetch)) {
> $container[] = '<a href='newslink.php'>' . $news . '</a>';
> $container[] = '<br><hr><br>';
> }
> $container[] = '</body></html>';
> $message = '';
> foreach($container as $foo) {
> $message .= $foo;
> }
> mail(Send mail to $data[0]);
> unset($container);
> }
> }
>
> Basically it grabs all the user's email addresses, then loop them.
> On each loop grab all news items.
> Then emails results to the user and moves on to the next user.
>
> Im running this on my test box, that only has two users, but the 2nd
> user never gets the expected results.
> The first user get the message and the news.
> The second only gets the message.
> The code structure is pretty much unchanged from a working example till
> I started using $container to hold array elements.
>
> Could anyone see bad logic in the above code??
> Thanks
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php