PHP - Increase Value In Database Every 5 Seconds
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. Similar TutorialsHave started to program my own cricket management game and wish to have the database update every 60 seconds; this is to facilitate players who are not watching the actual game. Games are starting (and finishing) at all times so it is not possible to allow the user to be the only one to activate the game code; it is also not possible to only play the games when the human players are online because other games depend on the results. The only answer I can think of at the moment is to have a copy of firefox running on the server which runs the PHP code to update all current games and have this page automatically refresh every 60 seconds. Is this even viable? Any other suggestions? James
Hi, echo '<div style="float:right;width:60%;color:#666666">'. TeamSpeak3_Helper_Convert::version($ts3->virtualserver_uptime) .'</div>'; Edited June 24, 2020 by Lux05 My code reads: <a href="index.php?action=delete&id=" >Delete</a> How do i change it so the id=1,2,3 etc with each link?? Probably an easy question but I can't find a solution on Google. I have this code: Code: [Select] $sql = "SELECT * FROM store WHERE id LIKE '$id'"; $result = mysql_query($sql); while ($rows = mysql_fetch_array($result)) { echo $rows['title']; } before the title i would like to have a number, starting at 1. so for example if it echoed out 10 titles each would have a corresponding number - 1, 2, 3, etc. anyone know an easy solution? thanks I have a text file with the following: HA11QS, 200, house1.jpg, 4 HA22BR, 280, house2.jpg, 10 HA33AB, 390, house3.jpg, 3 HA44CD, 320, house4.jpg, 8 I have a form: Code: [Select] <?php if (isset($_POST['price'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r"); $max = $_POST['price']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); if (((int) $item_array[1]) <= $max) { ?> <form action='visit2.php' method='post'> <?php echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3]. "<br>"); ?> <input type='checkbox' name='mybox'> <input type='submit' value='Visit Property'> </form> <?php } } fclose($fileOpen); } ?> and i also have "visit.php" Code: [Select] <?php if (isset($_POST['mybox'])) { $filename = "houses.txt"; $fileOpen = fopen($filename, "r+"); $filename2 = "houses2.txt"; $fileWrite = fopen($filename2, "w"); $visit = $_POST['mybox']; $rowsArr = file ($filename); foreach ($rowsArr as $row) { $lineDetails = $row; $item_array = explode (",", $row); $fileText = $item_array[3]+1; if ($visit == true) { echo("Post Code - " . $item_array[0]. "<br>"); echo("Price - " . $item_array[1]. ",000 <br>"); echo("Picture - " . $item_array[2]. "<br>"); echo("Number of Visits - " . $item_array[3] . "<br>"); echo("<br>"); fwrite($fileWrite, $fileText); } } fclose($fileOpen); fclose($fileWrite); } ?> What i need is , when the user in the form, clicks on the checked box, it sends the information to 'visits.php' and it writes to the text file, increasing the selected value by one Please can anyone help, im really struggling with this Thank You For the section of code below, is there a way to say, "first time through the query print on A2, B2,etc, then each query following add increase the number besides column name to be A3, B3, etc, then A4, B4, etc"...? $result = mysqli_query($connection,"SELECT * FROM table") or die(mysqli_error($connection)); while($row = mysqli_fetch_array($result)) { //get all rows you want from the table $var1 = $row['var1']; $var2 = $row['var2']; $var3 = $row['var3']; $var4 = $row['var4']; $objPHPExcel->setActiveSheetIndex(0) ->setCellValue('A2', $var1) ->setCellValue('B2', $var2) ->setCellValue('C2', $var3) ->setCellValue('D2', $var4); } This is for an excel spreadsheet. The code is currently printing/exporting one row only from the table. Thanks I have a proposal solicitation application where I select typically 5 or so individuals and they get individual emails such as "Hello Bob, please click <here> if you wish to provide pricing for the following scope of work..." It uses PHPmailer with a smtp gmail account. The FROM name is my name, the FROM email is an email account associated with the application <bidding@bidsoliciationapp.com>, and the REPLY-TO name and email are both mine. A while back, individuals have told me that my emails often windup in their spam folder. What might be causing this and what can be done to decrease its likelihood? One potential culprit is all of the emails have a small footer with a disclaimer and a link back to a website, but the link utilized https which was no longer supported on the site and was broken. Maybe related? Thanks I'm using the following function/php code to create some JSON for some NVD3 charts I am using. The problem I have is that for each KEY, the $i variable will count even and odd numbers. Here is the data below as you can see in the first line, every x:counts as 0, 2, 4 , 6.
and for KEY:IDNB it counts 1,3,5,7.
I need them all to count equally so that they are against the same line on my graph.
How can I make them count 1,2,3,4 for both "keys"
[{"key":"IDNA","values":[{"x":0,"y":387.73},{"x":2,"y":388.57},{"x":4,"y":388.04},{"x":6,"y":387.94},{"x":8,"y":388.24},{"x":10,"y":388.44},{"x":12,"y":387.99},{"x":14,"y":388.53},{"x":16,"y":388.79},{"x":18,"y":388.6},{"x":20,"y":388.55},{"x":22,"y":388.48},{"x":24,"y":388.72},{"x":26,"y":389.02},{"x":28,"y":388.59},{"x":30,"y":388.07},{"x":32,"y":388.14},{"x":34,"y":388.58},{"x":36,"y":388.12},{"x":38,"y":388.76},{"x":40,"y":388.15},{"x":42,"y":388.26},{"x":44,"y":388.09},{"x":46,"y":388.58},{"x":48,"y":386.85},{"x":50,"y":388.23},{"x":52,"y":388.16},{"x":54,"y":388.83},{"x":56,"y":388.79},{"x":58,"y":388.74},{"x":60,"y":388.78},{"x":62,"y":388.54},{"x":64,"y":388.36},{"x":66,"y":388.7},{"x":68,"y":388.54},{"x":70,"y":388.02},{"x":72,"y":388.05},{"x":74,"y":388.31},{"x":76,"y":388.65},{"x":78,"y":388.98},{"x":80,"y":387.78},{"x":82,"y":389.42},{"x":84,"y":388.86},{"x":86,"y":388.66},{"x":88,"y":388.51},{"x":90,"y":388.27},{"x":92,"y":389},{"x":94,"y":387.8},{"x":96,"y":388.18},{"x":98,"y":388.66}]},{"key":"IDNB","values":[{"x":1,"y":387.33},{"x":3,"y":388.5},{"x":5,"y":387.75},{"x":7,"y":387.98},{"x":9,"y":388.57},{"x":11,"y":388.23},{"x":13,"y":387.83},{"x":15,"y":388.31},{"x":17,"y":388.99},{"x":19,"y":388.7},{"x":21,"y":388.49},{"x":23,"y":388.21},{"x":25,"y":388.4},{"x":27,"y":389.05},{"x":29,"y":388.26},{"x":31,"y":387.88},{"x":33,"y":388.2},{"x":35,"y":388.3},{"x":37,"y":388.08},{"x":39,"y":388.29},{"x":41,"y":388.04},{"x":43,"y":387.91},{"x":45,"y":388.23},{"x":47,"y":388.47},{"x":49,"y":386.83},{"x":51,"y":387.55},{"x":53,"y":388.03},{"x":55,"y":388.98},{"x":57,"y":388.7},{"x":59,"y":388.94},{"x":61,"y":388.47},{"x":63,"y":388.5},{"x":65,"y":387.66},{"x":67,"y":388.17},{"x":69,"y":388.29},{"x":71,"y":387.73},{"x":73,"y":388},{"x":75,"y":388.36},{"x":77,"y":388.35},{"x":79,"y":388.75},{"x":81,"y":387.36},{"x":83,"y":389.32},{"x":85,"y":388.74},{"x":87,"y":388.86},{"x":89,"y":388.57},{"x":91,"y":388.21},{"x":93,"y":388.74},{"x":95,"y":387.84},{"x":97,"y":388.18},{"x":99,"y":388.7}]}]Here is the PHP im using to make the data from a query $lrs = CDB::ExecuteQuery($sql); if($lrs) { $jsonData = convert($lrs); } function convert($lrs) { $i = 0; $intermediate = array(); while ($vals = CDB::GetAssoc($lrs)) { $key = $vals['VARIABLE']; $x = $i; $y = $vals['VAR_MEASURE_1']; $intermediate[$key][] = array('x' => $x, 'y' => $y); $i++; } $output = array(); foreach($intermediate as $key => $values) { $output[] = array( "key" => $key, 'values' => $values ); } return json_encode($output, JSON_NUMERIC_CHECK); }can anyone point me in the right direction? Hi Is it possible to make a row(with number) increase every time the same value is added to the table? Example: I enter "test" into a table and it gets the following data: id=1 name=test count=1 And the next time I enter "test" into the table it becomes id=1 name=test count=2 instead of id=1 name=test count=1 id=2 name=test count=1 I want to create a form where users can suggest stuff and I want to see what is the most popular ect. Thanks in advance This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=307438.0 Jelly Bellys. So there are "recipes" of ones you can eat at the same time. The most well-known one is probably mixing a couple peanut butter jelly beans with a couple grapes. I have to say it's pretty good because they actually do taste like peanut butter and grapes, but I have one issue: the peanut butter flavor is too weak compared to the grape. Instead of a 1-1 ratio it takes more like 3-1. Weird thing, this has got to be the most famous recipe so why isn't it listed on their site? I see candy apple, tiramisu, and lemon meringue pie, but nothing about peanut butter and jelly sandwiches. Are they just not popular anymore? Personally I prefer peanut butter and chocolate (Nutella, specifically) but whatever. Which can't be that weird because Reese's is popular... Mind you peanut butter + Nutella sandwiches don't really taste like Reese's candies, but that could just be because of the type of chocolate. Like they use milk or dark chocolate while Nutella is based on hazelnut. Which reminds me, I have a jar of it in the cupboard, but it's been so long since I've used it that it might have turned into an oily mess by now. I know it's just the various oils and such separating but it looks like someone poured a teaspoon or two of water right into it and that just kinda puts me off the whole thing. Same for peanut butter for that matter except the "water" isn't clear. Dirty water. And mixing everything back together isn't so bad but it gets the knife dirty on the handle, which really bothers me because then my fingers get dirty and I have to stop what I'm doing and go wash my hands. I already do that enough each day, I don't want to make more reasons for me to do so. But beyond the oily mess there's also stuff getting stale. Stale Nutella is a pain because it's stiff and hard to deal with, and the kind of bread I like most is very soft and easily rips apart so spreading it on can be a real labor. Best method I've found is to spread a little bit on at a time but it takes so long to cover the whole face. Fine, it's a good sandwich, but in that same time I could have done something else. Maybe there's something in the freezer I could quickly heat up, or maybe there's some leftovers in the fridge I could eat. And if not there's pretty good odds that I need to go to the grocery store anyways. Ah, sorry. Forgot why I'm here. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=358112.0 Hi: I have a site hosted (shared) on 1and1.com hosting, and they seem to have a file upload limit of 2MB. Is there a way to overwrite this? I have been trying a .htaccess and php.ini file, but can't get it to work. The folder with the upload form is called "admin," in the ROOT of the site. Been trying (in both the ROOT and the "admin" folder): php.ini Code: [Select] ; Maximum size of POST data that PHP will accept. post_max_size = 8M ; Maximum allowed size for uploaded files. upload_max_filesize = 8M ini_set('memory_limit','128M'); .htaccess (in both the ROOT and the "admin" folder): Code: [Select] php_value memory_limit 24M That is all the code in each file - am I missing some code? Can this be done? Thank you. I'm trying to increase the variables $schedulemonth, $scheduledate, $scheduleyear in each loop so that they look like $schedulemonth1, $schedulemonth2, $schedulemonth3, etc... for each of them. I've tried several options and know I'm on the right track, but no go. The customer will choose how many payments and the script below will loop that many times - I have that part working - but the calendar I'm using with the variables above is the issue. Here's the code I'm using. while ($balance > 0){ if ($balance>$monthlypayment){ $myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear); //output the calendar $myCalendar->writeScript(); echo " "; echo "<input type=\"text\" name=\"payment" . $monthlypayment . "\" value=\"" . $monthlypayment . "\">\n"; $paymenttotal=($monthlypayment+$paymenttotal); $balance=round(($invoicetotal-$paymenttotal),2); echo " Balance: $balance\n"; $schedulemonth++; if ($schedulemonth==13){ $schedulemonth=1; $scheduleyear=($scheduleyear+1); } echo "<br>\n"; } if ($balance<$monthlypayment||$balance==$monthlypayment){ $myCalendar = new tc_calendar("date" . $paymentnumber, true);$myCalendar->setIcon("images/iconCalendar.gif");$myCalendar->setDate($scheduledate, $schedulemonth, $scheduleyear); //output the calendar $myCalendar->writeScript(); echo " "; echo "<input type=\"text\" name=\"payment" . $paymentnumber . "\" value=\"" . $balance . "\">\n"; $paymenttotal=($balance+$paymenttotal); $balance=round(($invoicetotal-$paymenttotal),2); echo " Balance: $balance\n"; $schedulemonth++; if ($schedulemonth==13){ $schedulemonth=1; $scheduleyear=($scheduleyear+1); } echo "<br>\n"; } } Additionally it needs to pick up each of these variables on the next page the variables are part of hidden fields in an form later in the page. So my question is actually 3 fold. 1. How do I increase the variable count in the loop above. 2. How do I put the <input type="hidden".......> in the form so that it loops through and catches the increasing variables 3. How do I loop through on the insertion page after the form is submitted to catch how many inserts to the database are needed. This one has me bent over. How do I echo the time in SECONDS? $tz = new DateTimeZone('America/Chicago'); $date = new DateTime('now', $tz); $mtime = $date->format('Y-m-d H:i:s'); echo ($mtime); E.g. 1296057739 I am trying to write a script that is going to access a database, grab the newest picture from it, find the height and width, analyze the height and width to find which command (which is assigned to a variable) is the one to run, run that command in the terminal, and then access the database again 6 seconds later (new pictures are uploaded every 6 seconds) and re-run and enter the command for this new picture. I have most of this already done, the problem I am having is figuring out how to get this to run every 6 seconds for forever. (Yes it has to be every 6 seconds.) Can anyone help me? Thanks in advance for the help! I need to get the +10 timezone. But 1. The output for +10 is incorrect. Please help to fix it. 2. Is this a good way to get it? <?php echo "time=" (.time() + 36000); ?> I'd like to make an sql request every x seconds with php. is it possible? Hi! I have got a problem with this function: Code: [Select] <?php function Sec2Time($time){ if(is_numeric($time)){ $value = array( "years" => 0, "days" => 0, "hours" => 0, "minutes" => 0, "seconds" => 0, ); if($time >= 31556926){ $value["years"] = floor($time/31556926); $time = ($time%31556926); } if($time >= 86400){ $value["days"] = floor($time/86400); $time = ($time%86400); } if($time >= 3600){ $value["hours"] = floor($time/3600); $time = ($time%3600); } if($time >= 60){ $value["minutes"] = floor($time/60); $time = ($time%60); } $value["seconds"] = floor($time); return (array) $value; }else{ return (bool) FALSE; } } ?> and my output for example: echo Sec2Time(604800); returns = "Array" ?? What I am wanting is to return a time from how many seconds. 604800 is 7 days so I want it to say 7 days. 2419200 is 1 month so I want it to say 1 month or 4 weeks. is (above) the right function for what I want ? thanks. Hi, I want to update a row when 30sec are passed on a page. If not nothing happens(not updating row). Example: You go to example.php>> 30sec pass, update row>> 30sec not over, no update. it does not necessarily have to be second it can be minutes or hours. Who can help me? Hope its clear enough, Thanks. Hi. I have a query that determines if user is online/offline. Works perfectly when page loads. I want to change to auto run query every X seconds. NOTES: - The query is on a .php page with multiple other queries. -IF it is possible to still run the query with-in this page? or make a separate file and include in an iframe? i would like to avoid the iframe and just $output the result of query every X seconds. Here is my $query code: $query = "SELECT `manager_id` FROM #__profiles_xref WHERE profileid = '$profid'"; $onofflineid=doSelectSql($query,1); foreach ($onofflineid as $isonoffline){ $profmanagerid=$isonoffline->manager_id; } $query = "SELECT `session_id` FROM table_session WHERE userid = '$propmanagerid'"; $onofflinestatus=doSelectSql($query,1); if (count($onofflinestatus)>0) { $output['PROPSTATUS']='Online'; } else { $output['PROPSTATUS']='Offline'; } |