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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T21:39:57+00:00 2026-06-05T21:39:57+00:00

Quick method description: I have two tables, lets name them table ONE and table

  • 0

Quick method description:

I have two tables, lets name them table ONE and table TWO.
Every table record has an id of its author (user). There are no limits for records per user.

I would like to run a statistics page for each user.

For example, when John logs in:

John | 20 of A (list) | 150 of B (list)

Demo code

$a = mysql_query("SELECT * FROM A WHERE userID='$userID'");
$b = mysql_query("SELECT * FROM B WHERE userID='$userID'");

$a_num=mysql_num_rows($a);
$b_num=mysql_num_rows($b);

$echo "$userID | $a_num of A <a href='/a/$userID'>(list)</a> | $b_num of B <a href='/b/$userID'>(list)</a> ";

The question:

So, is check for number of records (every time user visits his stats page) an optimal solution when number of table records come to few hundred or maybe thousand?
Is there any better way to run statistics? Maybe a separate table which counts records for each user?

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-05T21:39:59+00:00Added an answer on June 5, 2026 at 9:39 pm

    As you don’t seem to be using the resultset itself,

    $a = mysql_query("SELECT COUNT(*) FROM A WHERE userID='$userID'");
    

    will get you the count you need in 1 step. Also, it’s very likely a whole lot faster than what you’re doing.

    Second, the kind of optimisation you’re thinking of is definitely possible (just a group by userID is all you need, and run that script every hour or day or whatever, depending on the required accuracy) but I’d really wait with that kind of stuff until you’re dead sure you need it as it means extra work for the server and extra code to maintain.

    Third and last, get rid of the deprecated mysql_query calls, and also look up prepared statements. A lot safer and not harder once you get used to them.

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

Sidebar

Related Questions

Just a quick newbie question here. I have a method that calculates a value
Quick one folks. Have a quick look at the code snippet below. I alloc
I have a class that has to take product information from one system's database
Anyone have a quick method for de-duplicating a generic List in C#?
Does anyone have a quick and easy method for removing dynamically added buttons from
I have only one column roll number in my oracle table. Lots of data
I need to write effective and quick method to search byte array for given
Is there a quick way ( existing method) Concatenate array element into string with
Quick question, is there a way to call your main method whatever you like
Just a quick question. Say a call a method like so mysql_pconnect(server,tator_w,password) or die(Unable

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.