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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:49:44+00:00 2026-06-16T00:49:44+00:00

Database: xx_users (id, name, user_id, email, location) xx_questions (id, question, description, user_id) Code: $friends

  • 0

Database:

  • xx_users (id, name, user_id, email, location)
  • xx_questions (id, question, description, user_id)

Code:

$friends = $facebook->api('/me/friends');
$arr= $friends['data'];
$friend_ids_arr = array();
foreach($arr as $friend) {
    $friend_ids_arr[] = $friend['id'];
}

$sql = "SELECT (SELECT * FROM xx_questions WHERE user_id IN (" . implode(',', $friend_ids_arr) . ") OR user_id = '$user' ORDER BY time DESC) (SELECT * from questions INNER JOIN users ON users.user_id = questions.user_id WHERE users.location = 'Cambridge, Cambridgeshire')";    
$data = mysql_query($sql) or die(mysql_error());

while ($row = mysql_fetch_assoc($data)) {
       // echo values from what's been selected
}

I am trying to select questions from xx_questions (that have been posted by users) should any of three situations arise:

  1. Those values where the poster’s user_id matches that of one of the current user’s friends (i.e. the poster and the user are friends)
  2. Those values where the poster’s user_id matches that of the user (i.e. the poster is the user)
  3. Those values where the poster’s location matches that of the current user (i.e. the poster and user are currently in the same city)

I have managed to make 1 and 2 work, but the problems arise when I try to introduce 3, so my two questions are:

  1. What is the correct MySQL for 3?
  2. How is that integrated with 1 and 2?

Thanks in advance, let me know if you need more information.

  • 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-16T00:49:46+00:00Added an answer on June 16, 2026 at 12:49 am

    To get the information that you want, you need to join xx_questions to xx_users. Something like the following returns questions that match any one of the three conditions:

    select *
    from xx_questions q join
         xx_users u
         on q.user_id = u.user_id
    where q.user_id in (<implode(',', $friend_ids_arr)>) or
          q.user_id = '$user' or
          u.location = (select location from xx_users where USER_ID = $user)
    

    I have written this more like SQL than as a string, so it is easier to read.

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

Sidebar

Related Questions

Database: xx_users (id, name, user_id, email, location) xx_questions (id, question, description, user_id) Original code:
Following is the VBA code to fetch data from oracle database to excel. Instead
I'm using the EntityManager to persist data into my database. public void save(X x){
I'm attempting to copy the database located, as an example, in: /data/data/com.x.x.x/databases/mydb.db This works
database name customdata jobNo CustomerName Country Tel Item 1 John USA 045 Mouse 2
Database is OracleXE and here is the problem: data gets entered in tables UPS
I fetch record from database using following code. for (LocWiseProfileBeans cn : LocWiseProfile) {
I need a query, so before entering into question I will introduce the database
i am programming in php talking to mysql database. the code requires the use
I want to connect to a remote database (SQL Server 2008) through code using

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.