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 8822753
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T06:10:58+00:00 2026-06-14T06:10:58+00:00

something like the following is what I’m looking to do SELECT id, status, Gid,

  • 0

something like the following is what I’m looking to do

SELECT id, status, Gid, Uid, note FROM notes LIMIT 10

but the status id could be different and it would need to be something like the following

SELECT a.id, a.status, a.Gid, a.Uid, a.note
FROM notes as a
WHERE
  IF(a.status < 2, DONT SELECT),
  IF(a.status == 2, 
    (SELECT approved FROM friends WHERE Uid = a.Uid AND Fid = ".$_SESSION['Uid'].") 
      IF(approved = 1, SELECT ROW, else DONT)
  )
  IF(a.status == 3, SELECT)
  IF(a.status == 4,
     (SELECT Gid FROM friends WHERE Uid = a.Uid AND Fid = ".$_SESSION['Uid'].")
     IF(Gid == a.Gid, SELECT ROW, else DONT)
ORDER BY id DESC
LIMIT 10

I looked up the CASE command, but not sure how to use that, but I can see that being the way to do it, but yeah.. I’m not sure how to.
The above is an example of what I’m trying to do, the a.Uid can be different ids, so when the status == 2 or 4 we need to see if the viewing user is an approved friend or within the groupId (Gid)

any help fixing this query would be much appreciated.. I could change the notes table up a little if need be as its not in production yet, but is discouraged. I’m open to suggestions though

Thanks in advance!

  • 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-06-14T06:11:01+00:00Added an answer on June 14, 2026 at 6:11 am

    I think this will do what you want:

    select a.id, a.status, a.Gid, A.Uid, a.note
    FROM notes a
    LEFT JOIN friends f ON f.Uid = a.Uid AND f.Fid = $_SESSION[Uid]
    WHERE (a.status = 2 AND f.approved = 1)
    OR a.status = 3
    OR (a.status = 4 AND f.Gid = a.Gid)
    ORDER BY a.id DESC
    LIMIT 10
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want something like the following but would like it to be reusable for
I'm doing something like following to transfer value from PHP to javascript: var str
Can I do something like following to remove specific strings from the end of
I'm getting text from an API and it's something like following: text = 'replied
Why something like following is not allowed. I mean why the following method will
I want something like the following: foo.should_receive(:bar).with(an_instance_of(Bla))..... Is this possible? Edit: According to the
I'm doing something like the following: Validate number of nested attributes . I'm checking
I have something like the following data structure: Category StartDateTime EndDateTime =============================================== 1 12/1/2009
Suppose I have something like the following in test.cxx (and that I do the
I'm attempting something like the following: switch ($p) { foreach ($modules as $m) {

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.