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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T17:20:00+00:00 2026-06-17T17:20:00+00:00

How could I fetch a specific record only and if a condition is met?

  • 0

How could I fetch a specific record only and if a condition is met?

I have the code as

"SELECT a.id, a.text, a.uid, a.time 
FROM story a INNER JOIN friends b 
         ON ((a.uid = '" . $uid . "') OR 
             (b.uid = '" . $uid . "' AND accepted='1')  OR 
             (b.fid = '" . $uid . "' AND accepted='1')) 
ORDER BY a.time DESC 
LIMIT 3";

It works fine except that when the friends table is empty, it will not show the story records.

what i want to achieve is

  • if the uid in table story is equal to logged in uid (user), then show the text from table story (meaning it is his own story)

  • if the uid in table story is equal to uid in table friends and its friendship is accepted OR if the uid in table story is equal to fid in table friends and its friendship is accepted then show the text in table story (meaning the story is from a friend and its shown only if friendship is accepted)

  • if there is no friendships at all, just show own stories from table story and omit others

  • 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-17T17:20:01+00:00Added an answer on June 17, 2026 at 5:20 pm

    I think you are not using proper join format. It should be as :

        SELECT field_name 
        FROM table1 t1 
        INNER JOIN table2 t2 
        ON t1.id = t2.some_id 
        WHERE..
    

    You can check the basics here.

    In your case you should write query as following:

        "SELECT a.id, a.text, a.uid, a.time 
        FROM story a INNER JOIN friends b 
        ON a.id = b.some_id WHERE ((a.uid = '" . $uid . "') OR
        (b.uid = '" . $uid . "' AND accepted='1')  OR 
        (b.fid = '" . $uid . "' AND accepted='1')) 
        ORDER BY a.time DESC 
        LIMIT 3";
    

    I think it will help.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to fetch objects from core data within specific time periods; i.e. weekly
I have often SQL statements of the kind SELECT LENGTH(col_name) FROM `table` WHERE *condition*
I have a paginated collection that could be simultaneously making multiple fetch()es. E.G. a
I need to fetch revisions from SVN into GIT. I have two types of
Could someone please suggest why this is happening... I’ve got some code to pretty
Could someone help me to add A-atype B-btype C-ctype ONLY as a legend to
Please could someone help im building my first website that pulls info from a
I have created a module that lists out the specific list of articles .
I want to place a warning before deleting a specific row from mysql using
I have the following quite simple test PHP code that extracts the data and

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.