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

  • Home
  • SEARCH
  • 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 1086847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:51:49+00:00 2026-05-16T22:51:49+00:00

I have currently created a facebook like page that pulls notifications from different tables,

  • 0

I have currently created a facebook like page that pulls notifications from different tables, lets say about 8 tables. Each table has a different structure with different columns, so the first thing that comes to mind is that I’ll have a global table, like a table of contents, and refresh it with every new hit. I know inserts are resource intensive, but I was hoping that since it is a static table, I’d only add maybe one new record every 100 visitors, so I thought “MAYBE” I could get away with this, but I was wrong. I managed to get deadlocks from just three people hammering the website.

So anyways, now I have to redo it using a different method. Initially I was going to do views, but I have an issue with views. The selected table will have to contain the id of a user. Here is an example of a select statement from php:

$get_events = "

    SELECT id, " . $userId . ", 'admin_events', 0, event_start_time
        FROM admin_events
        WHERE CURDATE() < event_start_time AND 
              NOT EXISTS(SELECT id
                         FROM admin_event_registrations
                         WHERE user_id = " . $userId . " AND admin_events.id = event_id) AND
              NOT EXISTS(SELECT id
                         FROM admin_event_declines
                         WHERE user_id = " . $userId . " AND admin_events.id = event_id) AND
              event_capacity > (SELECT COUNT(*) FROM admin_event_registrations WHERE event_id = admin_events.id)
           LIMIT 1

Sorry about the messiness. In any event, as you can see, I need to return the user Id from the page as a selected column from the table. I could not figure out how to do it with views so I don’t think views are the way that I will be heading because there’s a lot more of these types of queries. I come from an MSSQL background, and I love stored procedures, so if there are stored procedures for MYSQL, that would be excellent.

Next I started thinking about temp tables. The table will be in memory, the table will be probably 150 rows max, and there will be no deadlocks. Is it still very expensive to do inserts on a temp table? Will I end up crashing the server? Right now we have maybe 100 users per day, but I want to try to be future proof when we get more users.

After a long thought, I figured that the only way is the user php and get all the results as an array. The problem is that I’d get something like:

$my_array[0]["date_created"] = <current_date>

The problem with the above is that I have to sort by date_created, but this is a multi dimensional array.

Anyways, to pull 150 to 200 MAX records from a database, which approach would you take? Temp Table, View, or php?

  • 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-16T22:51:50+00:00Added an answer on May 16, 2026 at 10:51 pm

    Some thoughts:

    Temp Tables:
    temporary tables will only last as long as the session is alive. If you run the code in a PHP script, the temporary table will be destroyed automatically when the script finishes executing.

    Views:
    These are mainly for hiding complexity in that you create it with a join and then access it like a single table. The underlining code is a SELECT statement.

    PHP Array:
    A bit more cumbersome than SQL to get data from. However, PHP does have some functions to make life easier but no real query language.

    Stored Procedures:
    There are stored procedures in MySQL – see: http://dev.mysql.com/doc/refman/5.0/en/stored-routines-syntax.html

    My Recommendation:
    First, re-write your query using the MySQL Query Analyzer: http://www.mysql.com/products/enterprise/query.html

    Now I would use PDO to put my values into an array using PHP. This will still leaves the initial heavy lifting to the DB Engine and keeps you from making multiple calls to the DB Server.

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

Sidebar

Related Questions

No related questions found

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.