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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T18:20:29+00:00 2026-05-20T18:20:29+00:00

Using mysql and PHP, I’d like to setup a query which pulls a problem

  • 0

Using mysql and PHP, I’d like to setup a query which pulls a problem from the problems table which a particular user has not seen yet.

I have two tables, 1) problems table and 2) records table.

The problems table has two fields: p_id, prob. This table contains a list of problems to display to the user.

The records table has 4 fields: record_id, user_id, p_id, num_seen. Anytime a user sees a particular problem the user’s id gets recorded (user_id), the problem he/she saw gets recorded (p_id) and the number of times that user has seen it gets recorded (num_seen).

The query I’m trying to write would select a p_id from the problems table, under the condition that this p_id has not yet been viewed by a particular user (user_id).

This seems like it should be simple but my attempts to use “WHERE problems.p_id != records.p_id AND user_id=$id” haven’t worked. Any advice on the correct query or a better way to get the desired result would be awesome.

  • 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-05-20T18:20:30+00:00Added an answer on May 20, 2026 at 6:20 pm
    SELECT p.* 
    FROM   problems p 
           LEFT JOIN records r 
             ON r.user_id = 100 
                AND r.p_id = p.p_id 
    WHERE  p.p_id IS NULL 
           AND p.p_id >= Rand() * (SELECT Max(p_id) 
                                   FROM   problems) 
    LIMIT  1 
    

    Where 100 is the current user_id.

    you need indexes on

    • (problems.p_id)
    • (records.user_id,records.p_id)
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm building a wepage in php using MySQL as my database. Which way is
I am using MySQL and PHP for a project I am working. I have
Been using PHP/MySQL for a little while now, and I'm wondering if there are
I am developing a PHP/MySQL application using vertrigoserver. I need to enter the German
I have been using the mysql api in PHP, and am now converting to
Using PHP and MySQL, I have a forum system I'm trying to build. What
I'm planning to make a very simple program using php and mySQL. The main
I am part of a team creating a web application using PHP and MySQL.
I am part of a team creating a web application using PHP and MySQL.
I want to run a web application on php and mysql, using the CakePHP

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.