
law
Members-
Posts
91 -
Joined
-
Last visited
Never
Profile Information
-
Gender
Not Telling
law's Achievements

Member (2/5)
0
Reputation
-
Thank you DavidAM, I found the error was due to my stupidity at checking the cleanliness of my code. Both your array suggestion and $projected_points = $data_stats->body->player_stats->{$id}->FPTS; work and are very helpful. Thank you guys for the help.
-
KevinM1 here is a snippet of the print r (it contains 100,000+ entries): stdClass Object ( [body] => stdClass Object ( [player_stats] => stdClass Object ( [1749143] => stdClass Object ( [_empty_] => 0 [TM] => SEA [FPTS] => 0 [GS] => 16.0 [G] => 16.0 [Pos] => LB ) [1616752] => stdClass Object ( [_empty_] => 0 [CmpPct] => 0 [FPTS] => 0 [RuAvg] => 0 [YAtt] => 0 [GS] => 16.0 [Pos] => RB [TM] => PIT [ReAvg] => 0 [G] => 16.0 ) My goal is to access these ids to pull the FPTS out. DavidAM: I am getting a T_VARIABLE issue. How should I describe this question? Sorry for the ignorance.
-
This works and is tested. PHP Code: $data_stats = json_decode($ret); $projected_points = $data_stats->body->player_stats->42550689->FPTS I just need to know how to do it using a variable. Something like this: PHP Code: $data_stats = json_decode($ret); $projected_points = $data_stats->body->player_stats->$id->FPTS How can I make $id work here? Also is this called extending a class? I don't even know the correct terminology to describe my question.
-
I agree reidel. I would love to pass the variables into the function. The issue is that I only have two files given to me by my boss. I have no idea where these functions are actually being initially called. Nightslyr, I have read that globals are discouraged for security reasons. As I mentioned I am a novice at OO. I just need to get this thing working. Then I can fix over arching issues with its design. You mentioned creating a new object instance. Would this be the correct way to do that in the example I previously listed: include('Tons of files included here'); $myarray = array( 0 => array("question" => "answer"), 1 => array("question1" => "answer1") ); class BigClass { var $a var $b function fiststep(){ global $myarray; foreach($myarray as $anarray) { $this->$anarray = new includedfunction1($anarray["question"]); $this->$anarray->Values = array(array("yes", "yes"), array("no", "no")); $this->$anarray->Multiple = true; } } function nthstep(){ global $myarray; $myarray = (object) $myarray; //object added as per nightslyr's discussion foreach($myarray as $anarray) { $this->$anarray->astep(); // Error occurs: Call to a member function on a non-object } } } include('Tons of files included here'); I tested this out, and I received the exact same error. I clearly don't understand something.
-
Ok, so I don't really understand a lot about OOP. I was given a two big files full of classes and functions. We were hand coding this file for each use. My objective was to make an array we could use to ease the pain of coding these features. Here is an example of what is happening to me. Can someone advise me conceptually on what to do. include('Tons of files included here'); $myarray = array( 0 => array("question" => "answer"), 1 => array("question1" => "answer1") ); class BigClass { var $a var $b function fiststep(){ global $myarray; foreach($myarray as $anarray) { $this->$anarray = new includedfunction1($anarray["question"]); $this->$anarray->Values = array(array("yes", "yes"), array("no", "no")); $this->$anarray->Multiple = true; } } function nthstep(){ global $myarray; foreach($myarray as $anarray) { $this->$anarray->astep(); // Error occurs: Call to a member function on a non-object } } } include('Tons of files included here'); There seem to be a number of steps that occur in one of the 10-20 include files before the data comes back to the nthstep. Once it comes back. I cannot seem to get it to be recognized as an object. If I were to manually type out the contents of $anarray. I get NO error. I am very over my head. Does anyone have a conceptual idea of my issue?
-
On the odd chance this might help someone, I used str_split($str, 3) to convert $a to a string. Then used array_splice($a, $i, 1, $b[$i]); to swap out the two values.
-
In this example $a = 120358 a[3] = 3 b[3] = 20 a[3] = b[3] a[3] = 2 <- not 20 I am trying to replace a specific section of a string with essentially another string. Does that make sense? I would assume there is some functions I am missing. *Going to re-check the manual*
-
I have some for loops that are rolling through various arrays. When a certain array value satisfies an if statement, I would like to overwrite another array with information from that array. Rough Example: $num1 = 30; //just example data $b[3] = 20; $b[6] = 15; $a = 120358; //number string given to me for($i=0; $i < $num1; $i++){ if(isset($b[$i])){ //when it finds that $b has data $a[$i] = $b[$i]; // I need to replace $a[$i] with b's data. I have a large number of processes that go below this point that rely on $a. What is the best way to do this? The current example sets $a[$i] = 2 NOT 20 because A is a string not really an array. } } Ideas? or a fundamental concept issue? I am open to suggestions.
-
Google comes through.. apparently these are called "Reserved Words" http://dev.mysql.com/doc/refman/5.1/en/reserved-words.html To fix my issue all I need to do is refer to the column in question by TableName.left!
-
Ok.. as a novice coder.. I am not aware of all the functions associated with any language.. well it has bitten me in the rump! Here is an Example: Table Name: LocationOfClothes ----------------------------------------------------------------------------------------------------------------------------------------------- | id | left | right | head | chest | ----------------------------------------------------------------------------------------------------------------------------------------------- | 1 glove 0 hat 0 | Ok in this example left, right,head,chest are places you can put clothing. Well if you try to update column "left" you get an error bc "left" is a predefined mysql function? You can SELECT * the table without an error. Due to this. I have written myself into a pickle. I have been using the col names all throughout my code. It would be a headache to "redo" it. I may have to.. I just thought I would toss it out to you guys to see if you know of a way I can update the "left & right" Columns
-
I am trying to identify the last pass through of my foreach loop. I am doing a lot of other things utilizing the loop. I have stripped all of that out as it has nothing to do with this question. I am only using the $last_item to identify the last item in the array. The if() then checks to make sure in my code, that is not included, that there were no identified errors in the loop. As each time the loop runs it does many things which might have resulted in a error due to the way the user inputted the string I am parsing. This whole thing prevents the same error from being printed out to the user more than one time. With out the if() it would show the error every time the error was encountered. Hope that made some sense? I commented where the missing code would have been in my previous post if that helps visualize what I am talking/typing about.
-
UGH! and I just learned that $p2 was the individual elements of the array earlier today! Apparently my brain is on vacation. $last_piece = end($pieces); //echo $last_piece; foreach ($pieces as &$p2){ // lots of unimportant code here if($p2 == $last_piece && !isset($error)) { $error = "No Error"; } } Works like a charm! Thanks again
-
According to a comment in the manual this should work: <?php $array = array('apples','bananas','cranberries','durians'); $last_item = end($array); foreach($array as $item) { if ($item == $last_item) { print "I like to eat " . $item; } } ?> source : http://us3.php.net/manual/en/control-structures.foreach.php comment by grobemo here is my code: foreach ($pieces as &$p2){ $last_piece = end($p2); if($p2 = $last_piece && !isset($error)) { $error = "No Error"; } } Here is my error message: "Warning: end() [function.end]: Passed variable is not an array or object in C:\wamp\www\index.php on line 2 (in my example)" Thanks guys I have been posting on the board all day. You guys have been a savior helping me meet this deadline.
-
[SOLVED] checking to see if a string contains a specific word?
law posted a topic in PHP Coding Help
I need to search a string for a set of key words. I need to match up these key words regardless of whitespace and capitalization. Can anyone tell me how I can accomplish this in a similar construct to my function example below? Here is my really ugly example: function does_contain ($string, $input){ $var = strrpos($string, $input); if ($var === false) { $var= "no"; } else { $var = "yes"; } return $var; } $in = does_contain("IN"," IN "); echo $in; -
wow thank you for the time to put it into plain english LispWriter .. I really appreciate the help guys