kenw232 Posted September 16, 2016 Share Posted September 16, 2016 I have a variable with a string that changes in a loop. while { $Name = "unique name1"; $Name = "unique name2"; $Name = "unique name3"; } I want to dynamically update a unique integer associated with $Name. How can I do this? So "unique name1" might get a number of 34, but I don't know the string will be "unique name1" entering into the loop. I can't wrap my head around this. Quote Link to comment Share on other sites More sharing options...
Barand Posted September 16, 2016 Share Posted September 16, 2016 So far you have posted code that makes no sense at all, and a description of the problem that makes even less sense. Do you want to start again? Quote Link to comment Share on other sites More sharing options...
kenw232 Posted September 16, 2016 Author Share Posted September 16, 2016 I have a while loop of mysql results. I need to keep track of the total number of X for employee_name's. How do I do that? while ($sqlEmployeeRow = $sqlGetEmployees -> fetch()) { // "This" employee_name gets 5 added to it's x. echo $sqlEmployeeRow['employee_name'] . " now has " . $x . " minutes"; } Quote Link to comment Share on other sites More sharing options...
ginerjm Posted September 16, 2016 Share Posted September 16, 2016 You show us a loop that does nothing but show us some output that we have no idea of its origins. Where did $x come from? How are you incrementing it? All you have done with this latest post is show us an echo statement of something. You really need to listen Barand if you want help. He can really help you IF YOU GIVE HIM/US and idea of what you are doing. Is this all the code you have so far that is related to this 'problem'? I hope not because that would imply that you want us to write it for you, not 'help' you with it. Quote Link to comment Share on other sites More sharing options...
kenw232 Posted September 16, 2016 Author Share Posted September 16, 2016 Its ok, I figured it out. I'm tracking it in two different arrays. # Add employee to array if not in array already if (!in_array($sqlEmployeeRow['employee_name'], $aTimeTotal)) { $aTimeTotal[] = $sqlEmployeeRow['employee_name']; } # Get index of this employee and update second array with time value $iIndexTemp = array_search($sqlEmployeeRow['employee_name'], $aTimeTotal); $aTimeTotalVals[$iIndexTemp] = $aTimeTotalVals[$iIndexTemp] + $sMinsOut; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.