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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T22:09:08+00:00 2026-06-13T22:09:08+00:00

really didn’t want to ask this because I’m sure its simple but: I have

  • 0

really didn’t want to ask this because I’m sure its simple but:

I have a database of users which include fields for postcode(zipcode) and Date of Birth.

A visitor can search for a user by age and distance to their own location. To do this, I have to SELECT all users, then calculate their age, and then calculate their distance, something like this:

$result = queryMysql("SELECT user FROM table WHERE user !='$user' ORDER BY joindate DESC ");
$num = mysql_num_rows($result);

for ($j = 0 ; $j < $num ; ++$j)
{
$row = mysql_fetch_row($result);
if ($row[0] == $user) continue;

$query = "SELECT * FROM table WHERE user='$row[0]'";
$res=mysql_query($query);
$users=mysql_fetch_assoc($res);

//Get Date of Birth and Calculate Age
$dob = $users['age'];
$age = ...

//Get Profile's Postcode and Calculate Distance 
$profilepc = $views['postcode'];
$distance = ...

if(($distance <200) AND ($age >18 AND <30)) {

}

So far, no problem. However I then want to run another query (for pagination) selecting ONLY those users who fit within the age and distance parameters set by the visitor, which i can echo in the above IF statement, but i don’t know how to include in a new Query.

So, HOW do I place the results of the first query into something(an array?), and then user the user_id’s (which are unique) from that first query to only select the required users for my pagination? Something like:

SELECT * FROM $table WHERE user_id=(filtered user_id's) ORDER BY joindate DESC 

I hope that makes sense.
Thanks

  • 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-13T22:09:09+00:00Added an answer on June 13, 2026 at 10:09 pm

    You can use a subquery for your IN clause, or if you already have a PHP array of IDs:

    // assuming your array of IDs is
    $user_ids = array(1, 2, 3, 4);
    
    // use implode() to create a comma separated list for use in your IN clause
    $query = "SELECT * FROM {$table}
    WHERE user_id IN (" . implode(',', $user_ids) . ") 
    ORDER BY joindate DESC;"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I really didn't want to have to waste people's time and ask this, but
I really didn't know how to ask this question in a simple fashion. I
i didn't really know how to title this question, but here's a thing that
Someone posted something similar but it didn't really solve the problem. I want to
I have googled this a little and didn't really find the answer I needed.
I have searched a bit on google, but didn't really found an answer to
I really didn't want to ask for help as I know I'll eventually figure
Apologies if this has been asked before but I really didn't know what to
I really didn't know what title to give this question, but I'll explain here:
I got this from one test and really didn't get the point. Which one

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.