I think the following code will work for you. I have moved the
mail($row['email'], Title, $body); out of the while ($ds=mysql_fetch_array($url_q)) {
loop.
<?php
require_once "_functions.php";
// retrieve those userids that have a corresponding entry in the ufJoin table
$query = "SELECT users.userid AS userid, users.email AS email
FROM users, ufJoin
WHERE users.userid=ufJoin.userid
GROUP BY users.userid";
$result = safe_query($query);
// deal with each user separately
while ($row = mysql_fetch_assoc($result)) {
// retrieve those urls that correspond to this userid
$url_query = "SELECT feeds.url AS url
FROM feeds, ufJoin
WHERE ufJoin.feedid=feeds.feedid
AND ufJoin.userid={$row['userid']}";
$url_q = safe_query($url_query);
// generate
$cnt =0;
while ($ds=mysql_fetch_array($url_q)) {
$url_row=$ds['url'];
//myfunction here
$body .= $url_row;
$cnt++;
}
mail($row['email'], Title, $body);
unset($body);
unset($url_row);
echo "Mail complete.";
}
?>