newsletter subscription
Posted: Sun Feb 06, 2011 2:45 am
hello guys, i need some help for a newsletter subscription. i have 3 tables: subscription(user_id, category_id), article(article_id, category_id, article), and newsletter(user_id, article_id, newsletter). what i want to do is select the article_id from article table where the category_id is the same as in subscription table so that i get all the articles that a user has subscribed and then check whether that article is already in the newsletter table for the user that has subscribed to it. or not. if it is then echo no new update else echo new updates available. what i have been able to do up to now is:
but i don't get the expected results!
can any1 tell me how i can achieve what i want. i believe this part should be modified:
Code: Select all
$query = "SELECT article.article_id, article.category_id, subscription.user_id FROM subscription, article WHERE subscription.category_id = article.category_id";
$query_result =mysql_query($query);
while ($row = mysql_fetch_array($query_result))
{
$query2 = "SELECT * FROM newsletter WHERE article_id = '".$row['article_id']."' AND user_id = '".$row['user_id']."'";
$query_result2 =mysql_query($query2);
while ($row1 = mysql_fetch_array($query_result2))
{
foreach ($row1 as $rows)
{
if ($rows['article_id']==$row['article_id'])
echo "no new update!<br/>";
...
else if ($rows['article_id']!=$row['article_id'])
echo "new updates available!<br/>";
...
}
}
}
can any1 tell me how i can achieve what i want. i believe this part should be modified:
Code: Select all
foreach ($row1 as $rows)
{
if ($rows['article_id']==$row['article_id'])
echo "no new update!<br/>";
...
else if ($rows['article_id']!=$row['article_id'])
echo "new updates available!<br/>";
...
}