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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:34:13+00:00 2026-05-25T23:34:13+00:00

this is my working code: while ($list = mysql_fetch_assoc($result)) { $sql2 = SELECT *

  • 0

this is my working code:

while ($list = mysql_fetch_assoc($result)) {
$sql2 = "SELECT * FROM stock WHERE gID=".$list['gID'];
$result2 = mysql_query($sql2, $conn) or trigger_error("SQL", E_USER_ERROR);
$totalgid = mysql_num_rows($result2);
$sql3 = "SELECT * FROM stockcount WHERE gID=".$list['gID']." AND date='".$list['date']."' AND affectstock=1";
$result3 = mysql_query($sql3, $conn) or trigger_error("SQL", E_USER_ERROR);
$dategid = mysql_num_rows($result3);
$calculategid = $totalgid - $dategid;
    if ($calculategid < 0) {

    if(isset($arr[$list['date']][$list['gID']])){
    //increment
} else {
    //set to initial value of 1
    $arr[$list['date']][$list['gID']]=$calculategid;
}

    }

}
print_r($arr);
  • 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-25T23:34:13+00:00Added an answer on May 25, 2026 at 11:34 pm

    do you have a loop outside this that is something like foreach($someList as $list){ ...do this code... }? I only ask because you should never have duplicate values because if you try to set a value into the same exact key, will overwrite the previous value. I can only assume based on the code you posted that you are appending this array to another array inside a loop. If that is the case, something like this might help:

    //initialize the output array
    $arr = array();
    //loop through somelist
    foreach($someList as $list){
        //check if the key exists, if so increment.
        if(isset($arr[$list['date']][$list['gID']])){
            //increment
            $arr[$list['date']][$list['gID']]++;
        } else {
            //set to initial value of 1
            $arr[$list['date']][$list['gID']]=1;
        }
    }
    print_r($arr);
    

    essentially, just check if the key isset() and if so, increment, if not set to 1.

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

Sidebar

Related Questions

This is my new code, its almost working, but I think my while loop
i got this code working and it to return the last tweet from my
I have this code: while (list ($key, $val) = each ($ethnicity)) { if ($val
I have this working code, but now i need to be able to change
I have this (working) CPU code: #define NF 3 int ND; typedef double (*POT)(double
I want to know i can do something similar to this (not working) code
As a beginner in Ocaml, I have this current working code: ... let ch_in
This is my Working Code DriftMul:=99; WriteProcessMemory(HandleWindow, ptr($4E709C), @DriftMul, 2, Write); I want to
I have this code working in C#: var request = (HttpWebRequest)WebRequest.Create(https://x.com/service); request.Method = GET;
Why isn't this code working? I've been stuck on this for 2 days. public

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.