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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:15:35+00:00 2026-05-11T21:15:35+00:00

I have a table in MySQL with text, date_posted, and user. I currently query

  • 0

I have a table in MySQL with “text”, “date_posted”, and “user”. I currently query all text from user=Andy, and call those questions. All of the other text fields from other users are answers to the most recent question.

What I want is to associate those answers with the most recent question, with a loop similar to “for each text where user=Andy, find the text where user!=Andy until date>the next user=Andy (question)”

This seems awfully contrived, and I’m wondering if it can be done roughly as I’ve outlined, or if I can save myself some trouble in how I’m storing the data or something.

Thanks for any advice.

EDIT: I’ve added in the insert queries I’ve been using.

$url = "http://search.twitter.com/search.json?q=&ands=&phrase=&ors=&nots=RT%2C+%40&tag=andyasks&lang=all&from=amcafee&to=&ref=&near=&within=1000&units=mi&since=&until=&tude%5B%5D=%3F&rpp=50)";
$contents = file_get_contents($url);
$decode = json_decode($contents, true);
foreach($decode['results'] as $current) {
    $query = "INSERT IGNORE INTO andyasks (questions, date, user) VALUES ('$current[text]','$current[created_at]','Andy')";
    mysql_query($query);
}

$url2 = "http://search.twitter.com/search.json?q=&ands=&phrase=&ors=&nots=RT&tag=andyasks&lang=all&from=&to=amcafee&ref=&near=&within=15&units=mi&since=&until=&rpp=50";
$contents2 = file_get_contents($url2);
$decode2 = json_decode($contents2, true);
foreach($decode2['results'] as $current2) {
    $query2 = "INSERT IGNORE INTO andyasks (questions, date, user) VALUES ('$current2[text]','$current2[created_at]','$current2[from_user]')";
    mysql_query($query2);
}

And then on the SELECT side, this is where I am currently:

    $results = mysql_query("SELECT * FROM andyasks");
$answers = mysql_query("SELECT * FROM andyasks WHERE 'user' != 'Andy'");
while($row = mysql_fetch_array($results))
{
    if ($row['user'] == 'Andy') {
    print(preg_replace($pattern, $replace, "<p>".$row["questions"]."</p>"));
}
}
while($row = mysql_fetch_array($answers))
{
    print(preg_replace('/@amcafee/', '', "<p>".$row["questions"]."</p>"));
}
  • 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-11T21:15:36+00:00Added an answer on May 11, 2026 at 9:15 pm

    What you have in mind could, I believe, be done with subtle use of JOIN or nested SELECT, ORDER BY, LIMIT, etc, but, as you surmise, it would be “awfully contrived” and likely pretty slow.

    As you suspect, you would save yourself a lot of trouble at SELECT time if you added a column to the table, which, for answers, has the primary key of the question they’re answering (that could be easily obtained at INSERT time, since it’s the latest entry with user equal Alex). Then the retrieval would be easier!

    If you can alter your schema this way, but need help with the SQL, pls comment or edit your answer to indicate that and I’ll be happy to follow up (similarly, I’d be happy to follow up if you’re stuck with this schema and need the “awfully contrived” SQL — I just don’t know which of the two possibilities applies!-).

    Edit: since the schema’s changed, the INSERT could be (using form :name to indicate parameters you should bind):

    INSERT IGNORE INTO andyasks
      (questions, date, user, answering)
      SELECT :text, :created_at, :from_user,
        IF(:from_user='Andy', NULL, aa.id)
      FROM andyasks AS aa
      WHERE user='Andy'
      ORDER BY date DESC
      LIMIT 1
    

    i.e.: use INSERT INTO ... SELECT' to do a query-within-insertion, which picks the latest post by Andy. I'm assuming you do also have a primary keyid` that’s auto-increment, which is the normal arrangement of things.

    Later to get all answers to a given question, you only need to select rows whose answering attribute equals that question’s id.

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

Sidebar

Related Questions

I have a MySQL table with approximately 3000 rows per user. One of the
I have a table in MySQL that has 3 fields and I want to
If I have a table in MySQL which represents a base class, and I
I have a MySQL table containing domain names: +----+---------------+ | id | domain |
I have a MySQL table LOGIN_LOG with fields ID, PLAYER, TIMESTAMP and ACTION. ACTION
I have a mysql table that relies on the unix epoch time stamp equivalent
I have a MySQL table consisting of: CREATE TABLE `url_list` ( `id` int(10) unsigned
I have a MySQL table that will only have one row. What should my
I have a MySQL table with utf8 general ci collation. In the table, I
I have a MySQL table holding lots of records that i want to give

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.