Jump to content

Tjk

Members
  • Posts

    27
  • Joined

  • Last visited

    Never

Everything posted by Tjk

  1. I wanted an opinion on this. I have created a text based game which requires multiple attributes to be used in the scripts. My question is whether or not it would be better just to pull all the data at the top of each page and store it in multi-dimensional arrays for example.... array(name of user array(data of user)) and then access this using array[user][data] or to use mysql queries throughout the script to select specific row data? Opinions appreciated
  2. Out of interest, if I load the script through my web browser should I see a blank page or should I get the error I'm getting which says "Warning: fopen(test.txt): failed to open stream: Permission denied"? Also, I tried it with CRON with no luck.
  3. Yeah. The code itself will work when embedded in HTML code but when trying to use CRON to load the pure PHP code itself to mail it to me it doesn't work.
  4. I've got CRON set up to run this file below every minute... (this is the entire contents of the file) [code=php:0] <?php $to= "myemail@emailprovider.com"; $subject= "cron test"; $message= "if you receive this cron is working!"; mail($to, $subject, $message); ?> [/code] Am I missing something about running PHP scripts using CRON or is it a server configuration problem? Help appreciated as always. -Tjk
  5. :) No it isn't. Basically if the $sum has the value 2.333333444445555 then the script will do something like add so much to another variable. But if the value is only 2 then it will do something like takeaway so much to this other variable. So far I've been unable to find a way of doing it. Thanks for any help you can give me.
  6. Is there a way of counting the number of numbers after the decimal point of a sum? For example... [code=php:0] <? $sum= 100/$a_number; //if $sum has so many numbers after a decimal point then do something else do something different ?> [/code] Help appreciated as always. :)
  7. I can't seem to find true inverse sine. I have tried asin and asinh and both give weird answers. Here's the code: [code] $opposite= 295; $hyp= 375.298547826; $sinx= $opposite/ $hyp; $x= asin($sinx); [/code] This gives me an answer of 1.10573218834 when it should give me an answer of ~51.813 Is there a setting in php.ini i need to change? The script is being run on a linux server and running the latest version of PHP. Any help is appreciated. -Tjk P.S: How do I use the php tags which colour the code. I haven't been able to find them. :) EDIT: I managed to solve my own problem. (For anyone with a similiar problem) the answer is that asin always returns in radians therefore you need to use rad2deg() to convert the angle into degrees.
  8. $campaign= "test";   $query= mysql_query("SELECT * from campaign INNER JOIN campaignd WHERE campaign.campaign='$campaign' campaignd.campaign='$campaign' ORDER BY minit LIMIT='1'")or die(mysql_error());   while($row= mysql_fetch_array($query)){     echo "<option value='".$row['commander']."'>". $row['commander']."</option>";   }    --------- Here I'm trying to select records from 2 tables- campaign and campaignd where the value of the row campaign is equal to the string stored in the variable of the name campaign, then ordering them by the row minit value (an integer) and setting the limit to 1 so it only selects the record with the highest value minit. It then echoes a select option with the value of the row commander. I can't seem to get it to do what I want. When i try loading the page i don't get any errors but instead just get an empty select box. Could anyone show me where I'm going wrong? regards -Tjk
  9. @ Crayon Violent: Earlier in the script the variable $battle is defined. Sorry, the original code I posted was a test script I set up to test if it was something wrong with my code. Everything is identical except in my example I used $var instead of $battle. $battle is definately set within the main script and ready to pass via the query string into the image creation script. I'm using a script called 'map.php' and through the img src I'm calling the script imagecreate2.php to generate the image. @joquius: I need the variable $battle to be set at all times so an else isn't really an option.
  10. I've added the header() function just above imagepng($im) and it doesn't work. Before I added the parameter into the query string for imagecreate2.php when I was just using a mysql statement with no WHERE condition everything was working fine and the map loaded. It was only when I added the parameter and to allow for the WHERE condition that it no longer works. Any ideas? Help appreciated as always.
  11. Sure. Here it is.... [taken from imagecreate2.php] [code] <?   $im= imagecreatefrompng('maptemp.png');      if(isset($_GET['battle'])){     $battle= $_GET['battle'];   }      mysql_connect("localhost", "user", "password")or die(mysql_error());   mysql_select_db("database");      $query= mysql_query("SELECT * from battles WHERE battle='$battle'")or die(mysql_error());   while($row= mysql_fetch_array($query)){     $unit= $row['unit'];     $unitx= $row['xcoord'];     $unity= $row['ycoord'];               $lcoordx= $unitx- 5;     $lcoordy= $unity - 5;        $rcoordx= $unitx + 5;     $rcoordy= $unity + 5;          $color= imagecolorallocate($im, 0xFF, 0xFF, 0xFF);       imagefilledrectangle($im, $lcoordx, $lcoordy, $rcoordx, $rcoordy, $color);   }   imagepng($im); ?> [/code]
  12. Code in main page... [code] <? $var= 1; ?> <form method="POST" action="map.php"> <input type="image" src="imagecreate2.php?var='$var'" height="300" width= "300" /> </form> [/code] Code in image create... [code]   if(isset($_GET['var'])){     $var= $_GET['var'];   }   mysql_query("SELECT * from table WHERE id='$var'") or die(mysql_error()); //does something to an image and outputs it using imagepng($img); [/code] The problem is that the image now doesn't load on the main page. Could anyone point out where I'm going wrong? Regards -Tjk
  13. Thanks for all your help Barand! **SOLVED**
  14. I managed to get that all working barand but here's my final problem in the myimage.php file... [code]   $im= imagecreatefrompng('maptemp.png');      mysql_connect("localhost", "user", "passwprd")or die(mysql_error());   mysql_select_db("simdoma_hermes");      $query= mysql_query("SELECT * from battles WHERE unit='1'")or die(mysql_error());   while($row= mysql_fetch_array($query)){     $unit= $row['unit'];     $unitx= $row['xcoord'];     $unity= $row['ycoord'];   }      $lcoordx= $unitx- 2;   $lcoordy= $unity + 2;      $rcoordx= $unitx + 2;   $rcoordy= $unity - 2;      $color= imagecolorallocate($im, 0xFF, 0xFF, 0xFF);     imagefilledrectangle($im, $lcoordx, $lcoordy, $rcoordx, $rcoordy, $color);      imagepng($im); [/code] I'm looking to take the coordinates of a unit from the DB then create a square 2 pixels each side of the unit's recorded coordinates in the database and draw a red rectangle on the map and then output it. When I try this the map outputs but there is no rectangle on it. Is it something wrong with my maths?
  15. That fixed it! Thanks Barand. One final question.. could I simply incorporate the code from myimage.php into my main page?
  16. I still haven't been able to get this one to work. Can anyone help?
  17. In the script below what I am trying to do is to create a counter whereby it takes a random variable from the arrays $stats adds it's value (taken from a mysql table and stored in a variable) to a string and then unsets the element so that on the next loop it will not show the value again. But when i try it, it displays more than one of the same element and i'm not sure why. I know it's a simple problem but could anyone point me in the right direction. [code]     $numElements = count($stats);     $numElements += "1";     $ss= "0";     $stats= array("command", "power", "agility", "knowledge", "acumen", "charisma");          for($i; $i < $numElements; $i++){           $dispstats= array_rand($stats);       $disp= $stats[$dispstats];       if($disp == "command"){         $dispfriend= $dispfriend. "-Command: ".$sfcomm."-";         unset($stats['command']);         $ss++;         }       else if($disp == "power"){         $dispfriend= $dispfriend. "-Power: ".$sfpow."-";         unset($stats['power']);         $ss++;       }       else if($disp == "agility"){         $dispfriend= $dispfriend. "-Agility: ".$sfagil."-";         unset($stats['agility']);         $ss++;       }       else if($disp == "knowledge"){         $dispfriend= $dispfriend. "-Knowledge: ".$sfknow."-";         unset($stats['knowledge']);         $ss++;       }       else if($disp == "acumen"){         $dispfriend= $dispfriend. "-Acumen: ".$sffacu."-";         unset($stats['acumen']);         $ss++;       }       else if($disp == "charisma"){         $dispfriend= $dispfriend. "-Charisma: ".$sfchar."-";         unset($stats['charisma']);         $ss++;       }       if($ss == $statview){         break;       }         } [/code] Help appreciated as always -Tjk
  18. Sorry, should've been more specific. I've tried the submit button idea to reload the page and it still doesn't work. By that i mean that when the page reloads anything below where the script is placed doesn't load (doesn't show on view page source either) and the image that should be created doesn't load. There is no error message at all. What I'm trying to do is create an image with a grid on it. The idea that eventually when someone clicks on it it will reload the page and display the x and y coordinates that were clicked on in the image.
  19. I'm having a real problem getting an image creation script to work... [code]    <form method="POST" action="imgoutput.php"> <?    //define png    header("Content-type: image/png");    $imgWidth= 300;    $imgHeight= 300;       //create image    $im= imagecreate($imgWidth, $imgHeight);    $colorBlack= imagecolorallocate($im, 0, 0, 0);    //create grid lines    for($i=1; $i > 11; $i++){      imageline($im, $i*30, 0, $i*30, 300, $colorBlack);      imageline($im, 0, $i*30, 300, $i*30,  $colorBlack);    }    //output png    imgpng($im);    imagedestroy($image);     ?>      </form> [/code] Could anyone point out where I'm going wrong on this? I have absolutely no idea why it won't work!
  20. Still getting to gribs with javascript. I've tried a basic form validation but I can't seem to get what I'm doing to work. Anyone point out where I'm going wrong? [code]    <script type="text/JavaScript">       <!--       function validate_this(){      valid= true;      if( document.signup.name.value == "" ){        alert ( "Please input your name");         valid= false;       }      if( document.signup.age.value == "" ){        alert ("Please input your age");        valid= false;       }     return valid;       }       //-->    </script>    </head>    <body bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">    <form name="signup" method="POST" action="signup.php" onSubmit="return validate_form ( );">     <p>Name: <input type="text" name="name"></p>     <p>Age: <input type="text" name="age"></p>     <p><input type="submit" value="submit">      </form>    </body> [/code] Cheers for any help. [img src=\"style_emoticons/[#EMO_DIR#]/smile.gif\" style=\"vertical-align:middle\" emoid=\":smile:\" border=\"0\" alt=\"smile.gif\" /]
  21. EDIT: Thanks for all your help. I had play around with it a bit but I understand it and have been able to get it to work. Regards, -Tjk
  22. I'm having some trouble coming up with a method of doing this... Run a mysql query and select userids from one table. I then don't want these userids to be selected/displayed in the second query I run in a different table. [code] $query= mysql_query("SELECT * from friends WHERE friend1='$userid'") or die(mysql_error()); while($row= mysql_fetch_assoc($query)){ echo $row['userid']; } //some more code // this query should not display the userids from displayed in the query above $query= mysql_query("SELECT * from information WHERE userid='$userid'") or die(mysql_error()); while($row= mysql_fetch_assoc($query)){ echo $row['userid']; } [/code] I was wondering if I could create an array of the userids selected from the 1st query and then tell the mysql to exclude them in the second query but I wasn't sure if this was possible. Any ideas on how I can do this? Regards, -Tjk
  23. I'm having a problem with this little statement and I was wondering if someone could put me right on where i'm going wrong. [code] $query= mysql_query("SELECT * from friend WHERE {friend1='$userid' AND friend2='$_POST[friend]'} OR {friend1='$_POST[friend] AND friend2='$userid'}")or die("could not select friends record from friends"); [/code] I only want to select the record (and as i have it setup there can only be one record) where either the user of the page's id is in either friend1 or friend 2 and the other use that they have selected in a pulldown list is in the other friend column. So for example if user of the page's id was 1 and the person they had selected had an id of 3 then it would select either when friend1 has the id 1 and friend2 has the id3 in it or friend1 has the id of 3 and friend 2 has the id of 1. Hope this is clear enough for you to understand. Help appreciated as always. -Tjk
  24. [a href=\"http://pastebin.com/692931\" target=\"_blank\"]http://pastebin.com/692931[/a] $pingtime just echos as "ARRAY" on the page at the moment. What I'm trying to do from here is to create a way of registering if a server responds to a ping and if not then display "offline". Any ideas how I could do this from here? ((Had to use postbin because of the forum security feature bug)) :) Regards
  25. I like to know what I'm using. :) I was wondering if you could explain a few things to me... Firstly the function icmpChecksum. Could you run through how it works with me? And secondly how can I create my own package IE if i wanted to make $data= "ping" etc etc (any articles I could look at to improve my understanding in explaining what each part of the package is)? The bottom half of the script (dealing with the sockets) I understand but I'm a little lost on the actual creation of the package. Help appreciated as always, Regards :)
×
×
  • 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.