Jump to content

How do I track an integer for an unknown string?


kenw232

Recommended Posts

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.

 

 

Link to comment
Share on other sites

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";
}
Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.