Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7055477
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:45:13+00:00 2026-05-28T03:45:13+00:00

So this seems like a simple little problem, but I haven’t been successful with

  • 0

So this seems like a simple little problem, but I haven’t been successful with getting this to work properly. I have a comments table, a posts table, and a notifications table. Previously I stored the postID in a column called “uniqueID” for notifications and for comments. Now I have changed it so that the comments unique id is stored in that column instead. So all I need to do is for each row that is a comment in notifications, go to the comments table where uniqueID==id and then return the value in that table called postID.

Here is a photo showing my question better.

http://i41.tinypic.com/nyzolg.png


The information from the photo is:

Table: Notifications

id  UserID  FromID  UniqueID    Action  State   Read_Date   Date
1   1       2       1           1       0       0           1325993600
2   1       6       2           1       0       0           1325993615
3   1       2       1           2       0       0           1325993622
4   1       6       2           2       0       0           1325993661
5   2       6       2           2       0       0           1325993661

Action = 1 means UniqueID identifies a row in Posts;
Action = 2 means UniqueID identifies a row in Comments.

Table: Posts

id  ToID    FromID  Post        State   Date
1   1       2       Hey         0       1325993600
2   1       6       okay yeah   0       1325993615

Table: Comments

ID  PostID  FromID  Comment     State   Date
1   1       2       lol         0       1325993622
2   1       6       ohh         0       1325993661

So, in the Notifications table where action is 2, the UniqueID’s are for the ‘id’ in the Comments table.
What I want to return is the PostID, so in the query it would just be as if the UniqueID was this instead:

1
2
1
1
1

But the UniqueID would stay the same where Action is 1.


My current query is this, and it worked fine before I changed my database values around.

$notificationsq = mysql_query("
SELECT
    N.*,
    P.*,
MAX(N.date) AS newDate
 FROM
    notifications N,
    posts
WHERE
    N.userID='$session'
AND
    (
            (
                   N.action='1'
                AND
                   (N.state = 0 OR N.state=1)
             )
            OR
                N.action='2'
     )
AND P.state='0'
AND
    N.uniqueID=P.id
GROUP BY
    N.uniqueID
ORDER BY
    N.state ASC,
    newDate DESC

") or die(mysql_error());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T03:45:14+00:00Added an answer on May 28, 2026 at 3:45 am

    Try adding “C.*” to your select clause, “comments C” to your from clause, and change ” N.action=’2′” to

    (N.action='2' and (N.uniqueId = C.id))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This seems like a simple problem: I have a WF4 activity that guides the
All, this seems like a simple problem but it's giving me fits. Lets say
This seems like it would be fairly simple, but I've been unable to find
This seems like a really, really simple problem, but I can't figure it out.
This seems like it should be simple enough but I'm having a little trouble.
This seems like a pretty common problem, but I haven't found any sort of
This seems like a simple question, but it is difficult to search for. I
this seems like a simple enough question but I can't seem to find a
This seems like a simple question, but has proven to be difficult to find
This seems like such a simple issue but I cannot find an elegant solution.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.