Jump to content

oliverj777

Members
  • Posts

    98
  • Joined

  • Last visited

    Never

Everything posted by oliverj777

  1. Okay, so this works nicely... My wood increases by 1 every 5 seconds, one major floor though (sorry for the pun ), is that my code forces my wood to be fixed, by that I mean that I can't subtract wood due to it being measured in my cached time, and relative time. What I was hoping for, was something like my wood has a default value of, say 20 on my database and my 'time setup' would just add 1 every 5 seconds to that value... Instead, what happening is that my time setup IS my wood value. Any ideas? Would really appreciate it, thanks
  2. Hello, I'm working on a simple project so bear with me, I have a variable called 'wood' on my SQL database, and I want to somehow increase the 'wood' value (int) every 5 seconds... Even when the user is not currently view that page. So what I'm thinking is saving the current mktime() to my database once - for sake of argument, this is going to be called 'time_cache', as well as the wood(int) variable. Then, when the user logs in to see how much wood there is, the PHP will, take the mktime() and subtract the 'cache_time' to see how many seconds have passed... Now I want to increase the wood int by 1 every 5 seconds that have passed. So I guess I need to do a division such as $seconds_passed = (mktime() - $time_cache) / 5. Which will give me the amount of 5 seconds that have passed, right? Then, surely my $wood will just equal $seconds_passed? I'm not sure if this is the best way to do something like this? Any one else have an idea? Also, my wood value doesn't 100% work as it give a decimal... I just want the wood value to increase by 1, every 5 seconds.
  3. Thanks, your first option works like a charm. Thanks!
  4. This doesn't let me search for a specific word/value
  5. Hello, I have an array, and I want to search the array for a particular 'word' and return how many times that 'word' is in the array. I tried using the search_array, but that just seems to find the first 'word' and return it. What I want it this: $array = array(0-blue, 1-yellow, 2-red, 3-blue, 4-blue, 5-blue, 6-yellow); Lets say I want to see how many times the word 'blue' is in the array: $counter = 4; How would I achieve this? Thanks
  6. Hello, I'm working on a form that once submitted, it inserts the result into my SQL table, but I'm trying to get it so it will update an imploded array. EG: current SQL table is "red,blue,green". Then user submits 'white', the SQL table should then update to: "red,blue,green,white" (notice how its added to the end). This is what I have so far: $attack_out = $info['attack_out']; $attack_out_split = explode(",", $attack_out); if(isset($_POST["submit_attack"])){ $attack_user = $_GET["attack"]; // user - sent from form //$troops_send = $_POST["troop_send"]; // ammount - sent from form $attack_user_array = array(); $i = 0; $max = (count($attack_out_split) + 1); while($i < $max){ $reverse = ($max - 1) - $i; $attack_user_array[$i] = $attack_out_split[$reverse]; $attack_user_array[$max - 1] = $attack_user; $i++; } $attack_user_glue = implode(",",$attack_user_array); $result = mysql_query("UPDATE users SET attack_out='$attack_user_glue' WHERE username='$username'"); } I can't figure out the algorithm in my while loop. Would appreciate any help, thanks
  7. Hello, I'm working on an error form, and I want to check if the user inserted a number into the name field, and if so return an error. I thought this might of worked, but it doesn't: if(is_int($_POST['name'])){ $arrErrors['name'] = 'Invalid name, remove numbers.'; } Many thanks
  8. Hello, I'm working on a very simple strategy based game site (mainly to expand my knowledge). What I basically want it to do is, you send a solider to an area which takes, say 20 seconds. After 20 seconds, he battles for 30 seconds, and then arrived back home which takes another 20 seconds. All the user is going to be seeing is a 'status' echo'ed text saying "Arriving in 00:??", "Battle Over in 00:??", and "Home in 00:??". So its just using a time counter. But what makes it more complicated, is that I want the time progress to be saved (datebase), so say I have to wait 50 seconds, I can sign off, go on another computer, sign in and still see my timer going down according to the time that has just passed. So, what I've done so far is, have 4 variables: $realTime - Holds the actual time in seconds. $waitingTime - Holds how long I need to wait. (this is stored in my DB) $differenceTime - Difference between real time and my waiting time. (loaded from my DB) $soliderProgress - Progress of the solider, so: Arriving, Battle ... (stored on DB) $realTime = date("s"); //soliderProgress is 'Starting' by default if(soliderProgress == "Starting"){ //solider is moving to area $differenceTime = $realTime + $waitingTime; $SQL = ("UPDATE users SET differenceTime='$differenceTime' WHERE username='$username'"); soliderProgress = "Arriving"; $SQL = ("UPDATE users SET soliderProgress='$soliderProgress' WHERE username='$username'"); } if(soliderProgress == "Arriving"){ echo "Arriving to area"; if($realTime >= $differenceTime){ //timer is complete soliderProgress = "Battle"; $SQL = ("UPDATE users SET soliderProgress='$soliderProgress' WHERE username='$username'"); } } This kind of works, but sometimes my $differenceTime is higher than 60 which messes it up, and also the timer isn't live ... so I have to keep refreshing the page
  9. Please elaborate, I'm not that advanced at PHP. I sure would appreciate it.
  10. Hello, I'm working on a dynamic text form (I guess thats what its called). Basically, I have a html page that echos in some PHP code. What the PHP code does is show different strings of text depending on a variable: <PHP? $brief1_info = "brief info goes here"; $brief1 = 0; if (isset($_POST['brief1Go'])) { $brief1 = $brief1 + 1; } else if (isset($_POST['brief1Back'])) { $brief1 = $brief1 - 1; } $breif1Controller = " <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Back\" id=\"brief1Back\" value=\"BACK\" /> </form> <form action=\"".$_SERVER['PHP_SELF']."\" method=\"post\"> <input type=\"submit\" name=\"brief1Go\" id=\"brief1Go\" value=\"CONTINUE\" /> </form>"; if($brief1 == 0){ $brief1_info = "<b>Welcome Commander,</b> you are currently viewing the Mission Control Brief page, here you can view all your missions that you need to complete in order to advance through your prestiges. You will need to follow your briefs carefully in order to succeed. <br /><br /> "; } else if($brief1 == 1){ $brief1_info = "Okay, let me show you around the place ..."; } else if($brief1 == 2){ $brief1_info = "brief is on 2"; } ?> The problem is, the BACK and CONTINUE buttons don't work. If $brief1 equals 0, and the user presses continue, the is should go to 1, and the brief1_info string is changed (so some different text shows in my html). It actually works when brief1 is on '0', but when its on 1 and the user pressed continue, the brief1 is changed to 1, but because the submit button refreshes the page, the variable is re-read again, and thus is reset back to 0. Is there a way around this? Or is there a better method than what I'm doing? Thanks
  11. Hello, I'm having a little trouble getting my head around my code here. Basically, I have a table based PHP form in my html page that loops and adds a new row to the table depending on my variables The table itself displays the amount of 'squads' you have, the name of the individual squads, how many people are in your squad, and an 'add button': Your Squads: | People | Form Button Squad 'name' | 2/5 | Add More? Squad 'name' | 3/5 | Add More? Squad 'name' | 1/5 | Add More? Etc ..... Code for this table: <p><strong> Add Soliders To Squads:</strong> <br />Soliders avalible: <? echo $solidersToAdd ?> <form action="<?php echo $_SERVER['PHP_SELF']?>" method="post"> <table width="500" border="0" cellspacing="0" cellpadding="0"> <?PHP $max = $squadNumbers - 1; $i = 0; while($i <= $max){ $print = $i + 1; echo"<tr>"; echo"<td width=\"200\" height=\"30\"><strong>Squad: ".$names_split[$i]."</strong></td>"; echo"<td width=\"200\" height=\"30\">".$content_split[$i]."/5</td>"; if($content_split[$i] != 5){ echo"<td height=\"30\">"; echo"<input name=\"submitAdd\" type=\"submit\" class=\"SquadWeaponSelector\" id=\"submitAdd_".$i."\" value=\"Add (".$solidersToAdd.")\" /></td>"; } else{ echo"<td height=\"30\">Squad is full</td>"; } $i++; } ?> </table> </form> This all works fine, but its the action form I'm struggling with, what I want is to be able to add a person to the specific squad the user pushed the button for and add to the database. NOTE: my database stores the content (players in squad) like so: 2,3,1 as a varchar and I use explode to split it into an array (this is the same with my squad names too). So here is a snippet of what I got at the top of my document, the form action: $squadNumbers = $info['squadNumbers']; // = 3 $squadNames = $info['squadNames']; // = Alpha,Beta,Oscar $squadContent = $info['squadContent']; // = 2,3,1 // split the squad content \\ $content_split = explode(",", $squadContent); // split the squad names \\ $names_split = explode(",", $squadNames); $solidersToAdd = 3; // will soon be retrieving off DB if (isset($_POST['submitAdd']) && $solidersToAdd != 0) { $i = 0; $max = $squadNumbers - 1; $newContentArray = array(); while($i <= $max){ $print = $i + 1; $newContentArray[whatever button was pressed] = 1 + $squadContent[whatever button was pressed]; $i++; } //$solidersToAdd--; $glueContent = $_POST['submitAdd_1']; //implode(",",$newContentArray); $result = mysql_query("UPDATE users SET squadContent='$glueContent' WHERE username = '$username'") or die(mysql_error()); } First of, I dont know how to have a button actually pass on a value such as '+1', and I need it to talk specifically to that squad. I would appreciate any help, many thanks in advance.
  12. I figured it out. It was to do with white spacing ... that was all! I had to make sure that there was no white spacing before or after the PHP opening/closing tags. Thanks anyway
  13. Hello, I have a simple login script that basically, when if you go to a page and you are NOT logged in (saved in cookie) then you get redirected to the login page, else the content is shown. It works, but I currently have my database connection details on the same page, I like to have them on a separate PHP and use require 'connet.php'. So I've gone ahead and done that, but now I get an error saying "Warning: Cannot modify header information - headers already sent". This only happens if I'm NOT logged in. It has something to do with my require "connect.php"; because if I comment that out, it works fine. Here is the script: <?php //require "connect.php"; // < causes header error // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); //checks cookies to make sure they are logged in if(isset($_COOKIE['ID_my_site'])) { $username = $_COOKIE['ID_my_site']; $pass = $_COOKIE['Key_my_site']; $check = mysql_query("SELECT * FROM users WHERE username = '$username'")or die(mysql_error()); while($info = mysql_fetch_array( $check )){ //if the cookie has the wrong password, they are taken to the login page if ($pass != $info['password']){ header("Location: index.php"); } //otherwise they are shown the admin area else{ ?> - content - <a href=logout.php>Logout</a> <? } } } //if the cookie does not exist, they are taken to the login screen else{ header("Location: index.php"); } ?> My connect.php page is just: <? // Connects to your Database mysql_connect("localhost", "user", "pass") or die(mysql_error()); mysql_select_db("db") or die(mysql_error()); ?> Why is the require causing this error, and how do I fix it? Thanks
  14. Hello, I have a variable that holds a piece of text that looks something like this: "world,blue,big". Is there anyway to split the text into the separate words as an array, and remove the commas? $text_to_split = "world,blue,big"; $splitArray = array(); //Do some kind of php function that splits text\\ echo splitArray[0]; // world echo splitArray[1]; //blue echo splitArray[2]; //big Would appreciate it, thanks
  15. Hello, I'm working on a PHP register form, all I want to do, is to be able to insert an extra variable into the database: // now we insert it into the database $insert = " INSERT INTO users (username, password) VALUES ('".$_POST['username']."', '".$_POST['pass']."') "; $add_member = mysql_query($insert); right, so I have the username and password variable being passed. But I also want to pass a variable into a column called 'weaponAttachments', all I want for this variable to be is 5000. So, in other words, something like this: 5000['weaponAttachments'] Thanks
  16. Hello, I have an online scoreboard, and right now it just displays all the players from highest score to lowest score. How would I be able to only display 20 players, and have a 'next' button that then displays the next 20 players down the line of scores? So, below is the code I use to display my score table: mysql_connect("localhost", "user", "pass"); mysql_select_db("data"); $fetch = "SELECT * FROM highscores ORDER BY score desc"; $result = mysql_query($fetch); $grab = $_POST["grabUser"]; $count = 1; while($row = mysql_fetch_array($result)){ echo "<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">"; echo "<tr>"; echo "<td width=\"30\" align=\"left\" class=\"scoreBoard-content\">".$count."</td>"; echo "<td width=\"50%\" align=\"left\" class=\"scoreBoard-content\">".$row['player']."</td>"; echo "<td align=\"right\" class=\"scoreBoard-content\">".$row['score']."</td>"; echo "<td width=\"60\" align=\"right\" class=\"scoreBoard-content\">"; $count ++; }
  17. Hello, I working on a very simple 'Create User' script, and I'm struggling to have a 'anti duplicate' system. Where it connects to SQL and checks to see if a username is already being used. This is what I have: mysql_connect("localhost", "username", "pass") or die(mysql_error()); mysql_select_db("database") or die (mysql_error()); $fetch = "SELECT * FROM highscores"; $result = mysql_query($fetch) or die (mysql_error()); $AddNewPlayer = $_POST["PHPnewPlayer"]; $AddNewScore = $_POST["PHPnewScore"]; $row = mysql_fetch_array($result); if($AddNewPlayer == $row['player']){ //this is always false - so it adds a username regardless echo "Profile already in use"; } else if($AddNewPlayer == ""){ echo "Please enter a profile name"; } else{ mysql_query("INSERT INTO highscores (player, score) VALUES('".$AddNewPlayer."', '".$AddNewScore."') ") or die (mysql_error()); echo "Profile Added"."-".$AddNewPlayer; } It never seems the check to see if a username is already in use, and so it just adds a username regardless. What am I doing wrong? Thanks
  18. Hello, I have an SQL table called 'highscores' and I want to find a field called 'player' which matches - $PlayerToChangeScore, and then to replace 'score' that is associated with the player, an replace it with - $ChangeScore. $ChangeScore = $_POST["PHPnewScoreChange"]; $PlayerToChangeScore = $_POST["PHPcurrentPlayerChange"]; Hope that makes sense, thanks
  19. Hello, Its been a while since I've done a bit of PHP - and I have literally forgotten everything. Okay, so I have this variable that holds a 'players name': $CurrentPlayer = $_POST["PHPcurrentPlayer"]; And all I want to do, it check against my SQL to find any matches that are the same to PHPcurrentPlayer in the row of "player". So basically, if(CurrentPlayer == SQL player), once it has found the row, I want it to pull a out a 'score' data from the player. Hope that makes sense? No? I have a table in SQL called 'highscore' - which has fields of: player and score. I want to check CurrentPlayer against the highscore[player] and retrieve [score] in a variable. I really need help. Thanks
  20. Okay - So now I've done this --> global $database; $q = "SELECT username" ."FROM ".TBL_USERS." ORDER BY username"; $result = $database->query($q); echo "<select name=\"my_select_name\">"; while ($array = mysql_fetch_assoc($result)) { echo "<option value=\"{$array['id']}\">{$array['username']}</option>"; } echo "</select>"; $result = mysql_query($query) or die( mysql_error() ); Nothing still is being displayed - and the $result = 'Query was empty' - which I guess means that there is nothing in that field? (because there is!) Help ....
  21. I want the username to show up and also be the value ... how do I go about doing that?
  22. Okay, So I've done it like this: $query = "SELECT username"."FROM ".TBL_USERS; $result= mysql_query($query); echo "<select name=\"my_select_name\">"; while ($array = mysql_fetch_assoc($result)) { echo "<option value=\"{$array['id']}\">{$array['username']}</option>"; } echo "</select>"; But nothing shows up in the box - its empty. What now?
  23. I'm getting a syntax error on: while ($array = mysql_fetch_assoc($result)) {
×
×
  • 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.