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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T10:12:02+00:00 2026-06-16T10:12:02+00:00

I have the following table: **id** **username** **activity** 1 user1 activity-like 2 user1 activity-share

  • 0

I have the following table:

**id**         **username**         **activity**
1              user1                  activity-like
2              user1                  activity-share
3              user3                  activity-like
4              user4                  activity-like
5              user1                  activity-share
6              user6                  activity-like
8              user1                  activity-share
9              user3                  activity-like
10             user5                  activity-share

(Note: there is no id = 7)

I am trying to use php-mysql to fetch the activity made by user1 and get the id. In this case the activities have the id (1, 2, 5, and 8).

$currentId = 5;

I want to get the next and previous ids if they exist (in this case 2 and 8).

$fetch = mysql_query("SELECT * FROM `main` WHERE `username` = 'user1' AND id > '$id'");
if(mysql_num_rows($fetch) == 1){
while (){

}
$result = $fetch['id'];
}

I am not sure how to write the query for that.

  • 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-16T10:12:04+00:00Added an answer on June 16, 2026 at 10:12 am

    You can do something like this:

    For next id,

    SELECT id from tablename where username = 'user1' AND id > $currentId ORDER BY ID ASC LIMIT 1;
    

    For previous id,

    SELECT id from tablename where username = 'user1' AND id < $currentId ORDER BY ID DESC LIMIT 1;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In SQL Server 2008 I have a user table like the following: Userid Username
I have the following database design: Employee Table: Username, Name, DivisionCode Division Table: SapCode,
I have the following database design: Employee Table: Username, Name Quiz Table: QuizID, Title,
Let's say I have following table like this <!DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0
I have the following table: Table: UserName Userid User UserUpdate 1 Dan 1/1/2005 1
I have the following table in the database: id, username, email, old_ip, current_ip Everytime
I have the following tables: USERS table id username email password status FRIENDS table
I have the following table structure: <tr> <th><label for=ctl00_bodyContent_username>username:</label></th> <td class=field><input name=ctl00$bodyContent$username type=text id=ctl00_bodyContent_username
I have following LINQ statement: (from o in Table where (o.Username == username &&
I have the following table in PostgreSQL database: CREATE TABLE maclist ( username character

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.