Jump to content

gibigbig

Members
  • Posts

    125
  • Joined

  • Last visited

Everything posted by gibigbig

  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?
  13. $query= mysql_query("SELECT * FROM table WHERE field = 'value'"); while ($row = mysql_fetch_assoc($query)) { // code here example: used as $row['field_name'] or $row['username'] etc... }
  14. This is a sample html code i have to work with: <div class="spaceit_pad"><span class="dark_text">English:</span> Fullmetal Alchemist: Brotherhood</div><div class="spaceit_pad"><span class="dark_text">Synonyms:</span> Hagane no Renkinjutsushi (2009), Fullmetal Alchemist (2009), FMA</div><div class="spaceit_pad"><span class="dark_text">Japanese:</span> 鋼の錬金術師</div> I want to extract Specifically these lines: 1) Fullmetal Alchemist: Brotherhood 2) Hagane no Renkinjutsushi (2009), Fullmetal Alchemist (2009), FMA 3) 鋼の錬金術師 from that, and all this is loaded from a thrid party website, like wikipedia. please help?
  15. i saw this in a php function page here: http://php.net/manual/en/function.stristr.php the line is if(stristr($string, 'earth') === FALSE) { specifically this this code <?php $string = 'Hello World!'; if(stristr($string, 'earth') === FALSE) { echo '"earth" not found in string'; } // outputs: "earth" not found in string ?> what is the significance of the '===' in there does it mean something? is there any difference from the '==' or the '=' ?
  16. i think you're better off with flash, but i did use a mobile internet speed test once that did use only php and a dummy file. try searching 'mobile internet test' in google and confirm that it exists before continuing
  17. how exactly do i go about doing that with php? I plan to do something similar to facebook notifications (the little popup in the bottom left), i have the javascript down, and i got the database to update itself how i want, all i need is to connect them by adding something that will check the database every 10 seconds and activate my javascript to display it. can any of you give me some actual code? i'd find that way more useful than instructions.
  18. I'd like to make an sql request every x seconds with php. is it possible?
  19. thank you both of you for your input, this helped my project greatly
  20. I have a string, and I have a variable $var = 5; $str = '<img src="img.jpg" />'; i want to display a $str (the image) $var amount of times (5). how can I do this?
  21. the more source code i see this in, =. , the more intrigued i am by it, i cant find tuts on it anywhere it cant be searched. please explain what it is and how to use it please.
×
×
  • 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.