Jump to content

law

Members
  • Posts

    91
  • Joined

  • Last visited

    Never

Everything posted by law

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. 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?
  6. 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.
  7. 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*
  8. 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.
  9. 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!
  10. 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
  11. 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.
  12. 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
  13. 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.
  14. 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;
  15. wow thank you for the time to put it into plain english LispWriter .. I really appreciate the help guys
  16. wow.. i hate when an answer is that simple! Thank you guys.. As Per the & question: I thought i read in the manual that "&" created a pointer to the original $string variable rather then creating a duplicate string. In my actual code my string is a few thousand characters long. I was trying to minimize the impact on my servers ram/cpu. Am I really far off on that concept? I would love any thoughts on how to do this? Because this forloop will be running every 5 seconds to sort massive amounts of data.
  17. $string = "Hello this is a string"; $string = explode(" ", $string); foreach ($string as $key => &$a){ echo $a[0]; } outputs : "Htias" <-- The fist letter of each key from the array I want $a to contain the entire array piece. $a[0] == $string[0] . Not just the first letter of the array piece. Anyone know what I'm doing wrong. I could not find this issue in the PHP manual, but 80% of that manual is far beyond my comprehension. Should I just do a for loop and manually advance the pointer?
  18. If he has a really long string of data in those foreach loops wouldn't that kill the computer he is working on? Would adding the & help speed up a long array by making it a pointer instead of a duplicate array? I am asking because I am in a similar situation. foreach ($test as $k1 => &$v1){ foreach ($v1 as $k2 => &$v2){ $tmp[] = array( 'value' => $v2, 'key1' => $k1, 'key2' => $k2); } }
  19. I could set up a scheduled task if needed, or I can log the time in the database and have php check every 30 min for a scheduled task for it to perform. I can fight that battle when I get there. I just need to figure out how to take 3 arrays and keep the data that matches up in 2 of the 3 arrays. What is the best way to take an array of data and search it using another array of search terms?
  20. This example was an incredible help to me when I first started reading into AJAXish concepts http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm
  21. Unless you are trying to make a real fancy gallery you could always just dump all the pictures into one directory and increment the names of the photos. (fotosizer does a great job of that set it to photo%n not images%n. I have seen a bug that adds random spaces on images%n and makes it impossible to call from php.) <code> <?php $thumbs = "./gallery/thumbs/" $images = "./gallery/images/" $num_img = 52; for ($i=0,$i <= $num_img, $i++){ ?> <img src="<?php echo $thumbs."photo".$i;?>" alt = ""/> <img src="<?php echo $images."photo".$i;?>" alt = ""/> <?php } ?> </code> *disclaimer: I wrote this in the quick reply box. I have not ran this or debugged it. I just was throwing out another option. You can also implement pagination on something like this script to create several galleries from the same code.*
  22. well i am like a kid with a new hammer.. i want to re purpose this code to run on multiple machines of mine once it is finished.. that is the reason i am using a database to add commands in and out.. here is my current database schema Table : location Column : id, building_name, building_symbol Building name is the full name of a place. The building symbol is the abbreviation of that building. These are my possible locations. I want to be able to add them via a database and eventually I will add additional fields to accompany specific time slots. As well as % of cpu cycles available. IE if I am at a friends house. I would like to be able to log into my computer to get gamefiles/maps if we needed them. I would only want it to use 60% of the excess cycles in this case. Table : commands Column : id, command_name, command_symbol, command_description, required_id *Description : The commands table holds commands such as @,DO,START these commands are kept in a table so that I may add more in the future without having to modify my parsing code.* Example: ID: 1 CommandName: At Location CommandSymbol: @ CommandDescription: My current location RequiredID: 0 Required id would be used for a command such as DO. I would like for DO to only work if it is given a START time. So the required id is the number of the start command. Example Email MSG : "@work DO defrag START 13:00" I would like to parse the message and tell the script a) I'm at work (use all extra cpu cycles and ram) b) Run the Defrag program c) Start the program at 1:00pm Once I can get the php logic down, I can use it to talk to the command line to handle all of my needs. I just need to get all of the filtering logic in line.
  23. I apologize I am a self taught coder... I just write it in my own logic.. which is dangerous! "array1 is from a database of commands array2 is from a database of names array3 is a imap request to an email account. I then read the newest email and make it this array." Array 1 = $commands_row (what i would like to happen) <code>$q="SELECT command_symbol FROM commands"; $sql = mysql_query($q) $commands_row = mysql_fetch_array($sql); </code> Array 2 = $buildings_row (places i could be) <code>$q="SELECT building_symbol FROM locations"; $sql = mysql_query($q); $buildings_row = mysql_fetch_array($sql);</code> Array3= $pieces (email message) <code>$message = nl2br(imap_body ($mbox , 4)); $pieces = explode(" ", $message);</code> The places/locations/buildings concept is added to this because i have a similar routine every day. I go to the office I complete my tasks. Then I am free to go. At this point I travel to a laboratory and do research as a second job. I only get paid for 2 hours a day at the lab (the maximum amount they can afford to pay me). So if i message my email account @lab. I can add logic to tell it to stop what it is doing in 2 hours because I will be home. At that point I will want to use the computer for gaming/ect ect.. needing all cpu cycles possible. If I can get this working it will be a huge help to the Staph lab I work at because my computer will be much more efficient allowing me to crunch and extensive amount of their data for correlations through regression analysis. ================For those who want a concise version of my problem ================================ "foreach ($pieces as $b)" print_r ($pieces) gives me a full word print_r ($b) is out putting the first letter of the word? I need this issue resolved so that I may move on with the project.
  24. Ok I have never done anything like this before and it shows! I have 3 arrays array1 is from a database of commands array2 is from a database of names array3 is a imap request to an email account. I then read the newest email and make it this array. I would like to text a message to my email account. My message will include something like: "@work DO math." I would like to process the message and have the computer understand that I am not home so it should use its extra cpu cycles to run X program in this case Math. Well here is how I am doing this "so far." I am up for suggestions bc I know there must be a more efficient way of doing this. <?php include_once('./dbconfig.php'); $mbox = imap_open ("{imap.googlemail.com:993/imap/ssl}INBOX", "email name", "email password", OP_READONLY) or die("can't connect: " . imap_last_error()); $status = imap_status($mbox, "{imap.googlemail.com:993/imap/ssl}INBOX", SA_ALL); if ($status) { $total_msgs = $status->messages; echo "Messages: " . $status->messages . "\n"; echo "Recent: " . $status->recent . "\n"; echo "Unseen: " . $status->unseen . "\n"; echo "UIDnext: " . $status->uidnext . "\n"; echo "UIDvalidity:" . $status->uidvalidity . "\n<br/>"; } else { echo "imap_status failed: " . imap_last_error() . "\n"; } $message = nl2br(imap_body ($mbox , 4)); ////////////////////////////////// Checking for parts //////////////////// $pieces = explode(" ", $message); print_r($pieces); function funct_symbol ($piece, $symbol){ $var = strrpos($piece, $symbol); if ($var === false) { $var= "no"; } else { $var = "yes"; } return $var; } $q="SELECT building_symbol FROM locations"; $sql = mysql_query($q); $buildings_row = mysql_fetch_array($sql); $q="SELECT command_symbol FROM commands"; $sql = mysql_query($q); while ($commands_row = mysql_fetch_array($sql)){ $i = 0; //pieces array foreach ($pieces as $b){ //echo $b[0]; $msg[$commands_row[0]][$i] = funct_symbol($b[0], $commands_row[0]); //echo $msg[$commands_row[0]][$i] ."=".$b[0]." which may contain ". $commands_row[0]."<br/>"; $i++; } } echo "<br/><br/><br/>----------------------------<br/>"; echo $msg['@'][0] . $pieces[0]; echo "<br/><br/><br/>----------------------------<br/>"; imap_close($mbox); ?> My first major problem hits @ the for each loop.. here is an example of my $message string: Array ( [0] => @work [2] => ?processlist /> -- /> ================================================================== /> This [5] => mobile [6] => text [7] => message [8] => is [9] => brought [10] => to [11] => you [12] => by [13] => AT&T /> ) Here is what $b[0] outputs as the pointer gets moved through the array @?///mtmibtybA/ I'm really lost here on this one..
  25. ** UPDATE ** I'm an idiot.. i just inverted the black.gif and the orange.gif.. it gave the visual look as if I had placed the EQ upside down.. Apparently my brain isn't as useless as i had thought!
×
×
  • 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.