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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T11:04:03+00:00 2026-06-16T11:04:03+00:00

I currently have a table setup for the opinion (either 1 or 0) of

  • 0

I currently have a table setup for the opinion (either 1 or 0) of a user on an article.

CREATE TABLE IF NOT EXISTS `opinion_article` 
(
`id`                INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
`uid`               INT UNSIGNED NOT NULL, /* user with an opinion on the article */
`aid`               INT UNSIGNED NOT NULL, /* article ID */
`opinion`           BOOL NOT NULL, /* opinion on the article, 1 = good, 0 = bad */
FOREIGN KEY (`uid`) REFERENCES `user`(`id`) ON UPDATE CASCADE ON DELETE RESTRICT,
FOREIGN KEY (`aid`) REFERENCES `article`(`id`) ON DELETE CASCADE ON UPDATE CASCADE,
UNIQUE (`uid`, `aid`)
) ENGINE=InnoDB;

I want to get a user’s “article score,” which is just how many other users have voted their article as good. The trick is that a user can have many articles. Is there a way to do this without returning all opinions on all articles for a user, then using a for loop to check for opinion==1?

  • 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-16T11:04:05+00:00Added an answer on June 16, 2026 at 11:04 am

    In your Article model, add the following relation:

    'score'=>array(self::STAT, 'OpinionArticle', 'aid', 'condition'=>'opinion=1')
    

    Then $Article->score should return that number for you.

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

Sidebar

Related Questions

I currently have database setup like so: CREATE TABLE `article` ( `id` int(11) NOT
I have the following table in SQL Server: CREATE TABLE [dbo].[Users]( [Id] [int] IDENTITY(1,1)
Currently, I have a table view that the user can add items and delete
I currently have a setup that links the models User, Dealer and Role together.
Currently I have a setup with firstTabViewController hosting 5 buttons each loading a table
Say I have a table like so: CREATE TABLE big_table (UUID varchar(32) not null,
I have a job setup that currently selects records from a table that does
I need some advice of how to setup my tables I currently have a
I have jQuery draggable set up and working ok on a table row. Currently
I currently have a table of concentrations, which are linked to a table of

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.