Jump to content

gibigbig

Members
  • Posts

    125
  • Joined

  • Last visited

Profile Information

  • Gender
    Not Telling

gibigbig's Achievements

Regular Member

Regular Member (3/5)

0

Reputation

  1. This is my database structure: http://www.awesomescreenshot.com/image/733881/57d01b042ca99b9a36dde90dd6640cdc I would like to loop through all the child elements (those who's parent_id is set to the data_id within the same table). Therefore those with "parent_id" as "0" are parents, and those with parent_id with a number in it is a child. I would like help creating a function that will generate tables, with the table itself as the parent, and all the rows within it would be children of that parent. There is only one layer of depth in this project (one parent and one child layer always. ). Can anyone help, or would want a more detailed description? Thank you, and looking forward to a reply.
  2. Hey, I need a bit of help replacing some variables in a string. I know its done with preg_replace. Here is the string: Header 1 <|header 2|> header 3 <b>header 4</b> I would like to get ONLY <|header 2|> from the above string. But "header 2" is variable so please its useless if the preg_replace isn't flexible to find whatever word is in there regardless. Thanks you.
  3. I am making an online game and when making a character, I want the gender chosen to be random, but controlled by a percentage. Example: $male = 80; // in % $female = 20; //in % Is there a function that will output "male" or "female" depending on the percentage of odds. Or do I have to make my own
  4. yes it was an easy fix, i had already fixed it myself, but what i really wanted was a better way to get this output. im not comfortable using foreach() at all, my instincts are telling me there is a much easier and better way to do this
  5. lol ok let me explain it from a coder's pov. I have this multidimensional array: $array = array( array("4" => 'poison'), array("4" => 'tackle'), array("6" => 'sleep powder'), array("44" => 'giga drain'), array("32" => 'synthesis'), array("23" => 'growth'), array("1" => 'double edge'), array("5" => 'take down') ); It is for a game, and it is in the format array("level_number" => "attack_name") You learn new attacks based on the level you are at, if i just moved up to level 4, i want to get a code that gets the new attacks i will learn from this multidimensional array like so: foreach($array as $a){ $attacks[] = $a['4']; } print_r($attacks); and the output is: Array ( [0] => poison [1] => tackle [2] => [3] => [4] => [5] => [6] => [7] => ) This code is bad because it has empty fields and I am not comfortable with the way it is made. I want to know if there is a prettier way to to code this.
  6. hmm, what im working on is a pokemon online game, and I want store the attacks in the level they will learn them, example $array = array( "4" => 'poison', "4" => 'scratch', "5" => 'tackle'); so when a pokemon levels up, I want to call on the level it just reached $array["4"] and get all the attacks it should learn at this level. is there any solution
  7. I use it for reusing blocks of code, i love it. saves time and makes my code much easier to understand. another benefit of OOP is that when you make an edit, only that block of code is affected and the site remains still generally usable. This means you can have a team of coders working on the same site without much conflicts. That is the most modern approach.
  8. my array here: $array = array("4" => 'first',"4" => 'second',"5" => 'third'); echo $array['4']; will one output "second", when i want it to output ALL values with the key "4"; is there anyway to get this without a foreach?
  9. My project requires me to make sql queries based on the month you are currently in as well as the subsequent months months before this. Example: to get the month number in php you use $month_num = date("n"); and for the month before you use: $month_before - date("n") - 1; what i need is a way of converting the $month_before to epoch timestamps. so i can do make a sql query for all user's activity in that month. Please help
  10. I would like to call upon an array variable from its key, say for example: $array = array("value" => 1); the code: echo $array["value"]; will easily output "1" however, i when i try this code: $array["1"]; or even: $array[0]; for the first instance in the array, all outputs are empty, why is this? and is there a solution?
  11. well not really, that is formatting decimals and stuff, not really what i want im looking for the opposite of sprintf
  12. Is there any function to convert numbers like 099,129,009 to just 99,129 and 9?
×
×
  • 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.