On your first email you loop through all the news in the $newsfetch 
resource. I think you need to then do a mysql_data_seek() call against 
that to reset it for the next time through the loop. Otherwise you'll 
just get a null result because you're already at the end of the data.

-Steve

On Wednesday, April 3, 2002, at 02:30  PM, Gerard Samuel wrote:

> (made a correction in sudo code)
>
> 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>';
>          $message2 = '';
>          foreach($container as $foo) {
>              $message2 .= $foo;
>          }
>          mail(Send mail to $data[0], $message2);
>          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

Reply via email to