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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:14:25+00:00 2026-05-22T21:14:25+00:00

Table with data: id score inputid 1 1 1 2 4 1 3 3

  • 0
Table with data:

id   score   inputid
1      1        1
2      4        1
3      3        1
4      1        2
5      2        2
6      3        5
7      1        6
8      1        6

while ($stmt_score->fetch())
{
 if($bind_inputid == '1') $array['score'][0] += $bind_score;
 if($bind_inputid == '2') $array['score'][1] += $bind_score;
 if($bind_inputid == '5') $array['score'][2] += $bind_score;
 if($bind_inputid == '6') $array['score'][3] += $bind_score;
}

As stated above I want to sum all results with specific ID. But since there will be more $bind_inputid ID’s, my question is, how to make automatic statements for more results of an Id’s ?

It has to be done in while loop not with mysql select.
PHP Lang.
Thx.

  • 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-22T21:14:26+00:00Added an answer on May 22, 2026 at 9:14 pm

    Assume your result is sorted by inputid:

    $inputid_curr = -1;
    $score_array_index = -1;
    while ($stmt_score->fetch())
    {
     if($inputid_curr != $bind_inputid)
     {
      $score_array_index = $score_array_index + 1;
      $inputid_curr = $bind_inputid;
     }
    
     $array['score'][$score_array_index] += $bind_score;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to update data table for those who score exam id 1,2 more
I have table to test score data that I need to pivot and I
I want to store a data structure thats a table with one column Strings
I have UserScores Table with data like this: Id userId Score 1 1 10
I have a data table like: <h:dataTable id=box-score-away value=#{individualAwayBoxScoreQuery.resultList} var=_bssl> <f:facet name=header> <h:outputText value=Away
I have a simple Table of data (nickname, score) for a simple android game.
I have created an archive table which will store data for selecting only. Daily
What is the best data structure to store an oracle table that's about 140
I am using an sqlite database to store log data. My table has a
I have a table of over 1 million test score records that basically have

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.