PHP - Php - Live Timer To Show Completion - Strategy Based
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) Code: [Select] $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 Similar TutorialsWhen it comes to php im still no expert, and when it comes to date/time within PHP my brain melts... what i want is a countdown timer in php that echos how long left is on a timer. i will set the timer for 60 minutes. and i want it to countdown in minutes (no need to display hours, seconds etc...) everytime the user refreshes the page the coundown will obivously refresh. how can i code this or anyone have any handy links to point me in the right direction. Thanks Hi, i dont know how to explain this so ill start with what i want to do. Id like to create a simple text based game in php for learning purposes but im stuck on 1 thing, making a page refresh based on a server timer. Basically every 2 minutes is a server tick and at such time your character gets +gold based on resources etc. im just not sure what such a thing would be called so i havnt been able to google it, obviously the ticks need to be server controlled so a user cant just refresh a page to get a new tick. i would also need the page to display how long left till next tick. the only way i can see it possible is to have a server side application controlling timers, and the php page requests time remaining or something. Any help would be muchly appreciated, thanks. I'm trying to make a simple website where people register to my website. When the user doesn't fill anything inside the boxes they get a message "Please fill all required fields" on the register.php page On my local host require_once works good. It shows up.
But when i upload the files to my sever the require_once does not show up on the register.php It just refreshes and i dont get the message "Please fill all required fields"
This is the code that works in local host but not in a live server <?php require_once 'messages.php'; ?>
Here is my full code
Register page: <html> <?php require_once 'messages.php'; ?> <br><br> <form action="register-clicked.php" method="POST"> Username:<br> <input type="text" name="usernamebox" placeholder="Enter Username Here"> <br><br> Email:<br> <input type="text" name="emailbox" placeholder="Enter email here"> <br><br> Password:<br> <input type="password" name="passwordbox" placeholder="Enter password here"> <br><br> Confirm Password:<br> <input type="password" name="passwordconfirmbox" placeholder="Re-enter password here"> <br><br> <input type="submit" name="submitbox" value="Press to submit"> <br><br> </form> </html>
Register clicked <?php session_start(); $data = $_POST; if( empty($data['usernamebox']) || empty($data['emailbox']) || empty($data['passwordbox']) || empty($data['passwordconfirmbox'])) { $_SESSION['messages'][] = 'Please fill all required fields'; header('Location: register.php'); exit; } if ($data['passwordbox'] !== $data['passwordconfirmbox']) { $_SESSION['messages'][] = 'Passwords do not match'; header('Location: register.php'); exit; } $dsn = 'mysql:dbname=mydatabase;host=localhost'; $dbUser='myuser'; $dbPassword= 'password'; try{ $connection = new PDO($dsn, $dbUser, $dbPassword); } catch (PDOException $exception){ $_SESSION['messages'][] = 'Connection failed: ' . $exception->getMessage(); header('Location: register.php'); exit; }
messages.php <?php session_start(); if (empty($_SESSION['messages'])){ return; } $messages = $_SESSION['messages']; unset($_SESSION['messages']); ?> <ul> <?php foreach ($messages as $message): ?> <li><?php echo $message; ?></li> <?php endforeach; ?> </ul> Edited Wednesday at 12:49 AM by bee65 hi, Instead giving its default on "Choose Process", I would like to display its process based on the value in database. How can I do it? Code: [Select] <?php require_once '../../connectDB.php'; require_once '../include/functions.php'; $sql = " SELECT * FROM tb_item ORDER BY itm_id asc"; $result = mysql_query($sql) or die(mysql_error()); ?> <form> <h1>Items</h1> <table width="75%" border="1" align="left" cellpadding="5" cellspacing="1"> <tr> <th width="100" align="left">Item ID</th> <th width="100" align="left">Parts</th> <th width="100" align="left">Sub-Process</th> <th width="100" align="left">Confirmation</th> </tr> <tr> <?php while ($row = mysql_fetch_array($result)) { extract($row); ?> <td><?php echo $itm_id; ?></td> <td><?php echo $itm_parts; ?></td> <td> <select name='cboSub' id='cbosub'> <option value='' selected>---- Choose Process ----</option> <?php createComboBox(); ?> </select> </td> <td> <a href='processItem.php?itm_id=<?php echo $itm_id; ?>'> <img src='../images/modify.png' width='20' height='20' alt='confirm'/> </a> </td> </tr> <?php }; ?> </table> </form> <?php /** * Create combo box for sub-process */ function createComboBox() { $sql = " SELECT * FROM tb_sub_process ORDER BY sub_id asc"; $result = mysql_query($sql) or die(mysql_error()); while ($row = mysql_fetch_array($result)) { extract($row); echo "<option value='$sub_id' $select>$sub_name</option>"; } } ?> I've attached an example of what basically the output will looks like. Any help are appreciated. Thanks in advance. Regards, Juz [attachment deleted by admin] Code: [Select] $query = "INSERT INTO contactv3(name,email,msg) VALUES ('$name','$email','$msg')"; $result = mysql_query( $query ); if( !$result ) { die( mysql_error() ); } I have this current php snippet inserting the $name and $msg into a mysql db. $name and $msg come from here (a form that the user fills out). Code: [Select] <input type="text" size=28 name="name"> <input type="password" size=28 name="msg" > but is it possible to also enter the URL or perhaps a parameter that is appended to the end of the URL into the mysql db into separate column? hi, at the moment, my page only works with the County: Angus (2nd in the list) List of Counties County List Angus County List The code for my Pubs page is below..., I think I need to change the hard coded bit that reads: Code: [Select] echo "<ul title=\"Pubs in Angus\" id=\"Angu\">"; and the SQL string: Code: [Select] $query = "SELECT * FROM pubs WHERE rsCounty = 'Angus' LIMIT $offset, $rowsPerPage"; pubs page Code: [Select] <?php include_once("config.php"); include_once("functions.php"); // Check user logged in already: checkLoggedIn("no"); //doCSS(); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>My Pub Space</title> <link rel="stylesheet" type="text/css" href="stylesheets/style1.css" title="default" /> <meta name="viewport" content="width=device-width; initial-scale=1.0; minimum-scale=1.0; maximum-scale=1.0; user-scalable=0;"/> <link rel="apple-touch-icon" href="../iui/iui/mps-icon.png" /> <style type="text/css" media="screen">@import "../iui/iui/iui.css";</style> <script type="application/x-javascript" src="../iui/iui/iui.js"></script> <meta name="apple-touch-fullscreen" content="YES" /> <script type="text/javascript" src="js/jva.js"></script> </head> <body> <? $offset = (isset($_GET['start'])) ? (int)$_GET["start"] : 0; $rowsPerPage = (isset($_GET['count'])) ? (int)$_GET["count"] : 10; $query = "SELECT * FROM pubs WHERE rsCounty = 'Angus' LIMIT $offset, $rowsPerPage"; $result = mysql_query($query) or die(mysql_error().'<br>SQL: ' . $query); //looping counties $query1 = "SELECT rsCounty, COUNT(PUBID) AS County_Count FROM pubs GROUP BY rsCounty"; $result1 = mysql_query($query1) or die(mysql_error().'<br>SQL: ' . $query1); $County1 = $result1['rsCounty']; $CountyCount = $result1['County_Count']; ?> <div class="toolbar"> <h1 id="pageTitle">Select County</h1> <a id="backButton" class="button" href="#"></a> <a class="button" href="logout.php" target="_self">Logout</a> </div> <ul title="Select County" id="county" selected="true"> <?php while ($row = mysql_fetch_assoc($result1)){ $RSCOUNTY1 = $row['rsCounty']; $RSCOUNTY1short = substr($row['rsCounty'],0,4); $CountyCount = $row['County_Count']; echo <<<EOF <li><a href="#$RSCOUNTY1" class="digg-count">$CountyCount</a> <a href="#$RSCOUNTY1short">$RSCOUNTY1</a></li> EOF; } echo "</ul>"; // start East Sussex echo "<ul title=\"Pubs in Angus\" id=\"Angu\">"; while($row = mysql_fetch_array($result)){ $PUBID = $row['PUBID']; $rsPubName = $row['rsPubName']; $rsAddress = $row['rsAddress']; $rsPostCode = $row['rsPostCode']; $rsTel = $row['rsTel']; $rsTown = $row['rsTown']; $rsCounty = $row['rsCounty']; // how many rows we have in database // print the link to access each page $self = $_SERVER['PHP_SELF']; $next = "<li><a href=\"all.php?start=" . ($offset + $rowsPerPage) . "&count={$rowsPerPage}\" target=\"_replace\">View More</a></li>"; //div container of header and information echo <<<EOF <li><a href="viewpub.php?PUBID=$PUBID">$rsPubName</a></li> EOF; if ($_SESSION["RSUSER"] == "admin") { echo "<a href=\"edit.php?PUBID=$PUBID\" class=\"small\">edit this pub</a>"; } } echo $next; echo "</ul>"; // End East Sussex ?> </body> </html> Please help?! Hello, i have a form with a dropdown selection with the values 1 to 8, on the submit page i have another form which has 8 divs, now i want to show only a number of those divs based on the selection of the dropdown from the previous page. example: 1st page dropdown value is 4, form gets submitted, on the next page show div 1 & 2 & 3 & 4, and so on. Is this possible? /Edit: i just thought about it again and i think i could use Code: [Select] <?php $dropdown=$_POST['dropdown']; if($dropdown=="1") { ?> around the div tags, but then i would have to make 8 forms and take out 1 div one by one based on the dropdown selection, or is my thinking wrong? hey guys, I am having a small problem and I can't wrap my head around it. I want users to be able to upload up 10 photos in the database and what I want to do is check the database to see how many pics they have already and if they have 10, just show the photo with action items but if they have 7 for example, show the 7 pictures and three upload fields, if they have 4, show the pics and 6 fields and so on... let me know what you guys think and some help. Thanks in advance guys, you always come through... Hello,
I want to show checkbox is checked when there is entry of that id in a table in my database.
I have 2 tables page and access_level. I am getting data from page table and displays it in <ul><li> tag with checkbox to select all or only few. After selecting the checkbox, i will store only selected checkbox value in access_level table along with table id. Page link and page name details will be stored in page table.
Now if i want to edit , i should display all the pages which is there in page table and i should also mark checked to those which are already stored in access_level table.
I am using LEFT OUT JOIN, It displays all the pages. But it is not displaying the check mark to those which are already selected.
Here is my code
<?php $s1 = mysql_query("SELECT pages.page_id, pages.code, pages.page, pages.href, access_level.aid, access_level.page_id as pgid, access_level.department, access_level.position, access_level.active FROM pages LEFT OUTER JOIN access_level ON pages.page_id=access_level.page_id WHERE access_level.department=".$department." AND access_level.position=".$position." AND pages.code='sn'") or die(mysql_error()); while($s2 = mysql_fetch_array($s1)) { ?> <tr><td><li><?php echo $s2['page']; ?> </td><td><input type="checkbox" name="sn[]" value="<?php echo $s2['page_id']; ?>" <?php if($row['pgid'] === $s2['page_id']) echo 'checked="checked"';?> />here is my pages table pages.JPG 26.55KB 0 downloads access_level access_level.JPG 19.09KB 0 downloads In access_level table i do not have page ids 8 and 9. But i want to display that also from pages table and for 1 to 7 and 10 i should display check mark. How i can achieve this? Please Help Hello,
I'm starting using class and have a question for you guys :
Let's consider a class "customer". I want to code a search tool. Where should I put my search function ? Within the customer class ? In another "search" class ? Other solution ?
Thanks for help !
am currently building the cart system of a product, now there is this part wherein, the non-logged-in OR logged-in user should also be able to see the items that he/she viewed, how to do that?., am not asking for code snippets , just give me some ideas/hints/strategies/tips that may help me get the big picture on how to do this thing and proceed coding. This topic has been moved to Application Design. http://www.phpfreaks.com/forums/index.php?topic=350418.0 Hi, I was asked to create an app, wherein, the user may enter the email addresses of people manually, and it auto generates a random key. now this key will be used access such pages e.g proposal.test.com/ppc proposal.test.com/seo proposal.test.com/design so using the key for example => Sa22asdf it should appear like this proposal.test.com/ppc/Sa22asdf proposal.test.com/seo/Sa22asdf proposal.test.com/design/Sa22asdf without the unique key generated during the input of email address, the URL mentioned shouldn't be accessed by anyone.. now my question is, how to approach this thing in PHP ? I have done the input for email address and generation of random keys., but i don't know yet what to do or how to do the securing of pages using those keys ? Hi guys, What techniques do you use to process, validate, and then show errors on your forms. Do you set an "action" to the same form and then handle errors somewhere? Do you use a separate script to process validation? What standards do you apply for the position of the error messages? Do you alter the "look" of any fields in errors (make them red for example)? Do you have a good standard strategy that can be applied for all forms in a re-usable fashion? Perhaps using functions? I am looking for a robust, user friendly (and coder friendly come to that) solution to this frequently encountered situation. Many thanks for any help. S I am wondering if there is an easier / better way to keep my development and test databases in synch.
When I develop, I may add tables or fields to existing tables. When I upload from the development server to the test server I can check and make sure that I include all of the programs that I have edited by using the filesystems last modified date. However, I keep track of new and changed tables in MYSQL manually. Is there an easy way, that I am just missing, to see last modified dates for tables within a db? Is there some other strategy I should be using. I hate missing a table and having the test server give errors on code I debugged once on the development server.
I am refactoring entire collective scattered SQL from my legacy codebase, and into separate classes, and looking for some structure to put it into. Right now I have folders effectively called `DataFromDB` - contains classes that accepts whatever parameters are given, and returns pure data back to the user `DAO` - Data Access Object, which takes that raw data from DB and makes sense out of it and prepares it for consumption by the model/business logic layer objects. That is: - src (folder) |- DAO (folder) | - ProductADAO (classes - take data in, return consumable objects out) | - ProductBDAO | - ... | - ProductZDAO |- DataFromDB (folder) | - ProductAData (classes - contain methods to query pure result sets from DB) | - ProductBData | - ... | - ProductZDataWhenever I need to make a new SQL or refactor an old one I do this: What is this SQL doing? Is it operating on `SomeObjectX`? If yes, find/create class called `ObjectX`, and add a method to it, extracting pure data from DB, put it into `DataFromDB` folder. Write the `DAO` object if needed to transform data into a consumable object. Use the object as is in my code. Does this look like a good strategy? Is there a better one? My problem with this one is that before (now) all the SQL is tightly coupled and is included into the multiple business classes. Using the above strategy will mean I am to be creating many many classes, a lot of classes, most likely one for every few SQL statements. The pros is that it seems like I will achieve a level of code modularity that I wanted. I bought script for live chat support but i want something more. Now you can login with admin role and operator role, but what i want is to add user role so when user login in app he can see online operators and chat with them. It is open source so there is no legal issue..
So if anyone wants to help me i will send script on your email and try to solve this..
Thanks,Ivan
I'm trying to get live search set up for one of my pages and have been successful for the most part. I basically used the code provided by w3schools (http://www.w3schools.com/php/php_ajax_livesearch.asp) but need to make a modification. Their code is set up to read the link titles and urls from an xml file and search through the xml file but I would like to just search through a variable. So in the w3schools code there is this... $xmlDoc=new DOMDocument(); $xmlDoc->load("links.xml"); $x=$xmlDoc->getElementsByTagName('link'); And I have this variable that I want it to search instead of "links.xml"... $searchTest = "<pages><link><title>Search this text</title><url>www.gohere.com</url></link></pages>"; How do I get that into the $xmlDoc variable? If I simply replace "links.xml" with $searchTest like this $xmlDoc=new DOMDocument(); $xmlDoc->load($searchTest); $x=$xmlDoc->getElementsByTagName('link'); I get nothing when I try to search. But if I create a file in the php code and write the contents of $searchTest to that file then put that file in the $xmlDoc->load("newfile.xml"); line it searches and works fine. Any ideas? Hello sir, I request an help for the live search.. Here are the 2 pages Code: [Select] <html> <form action='?p=search'> <font face='sans-serif' size='5'> <center> Search By the CID.<br> <input type='text' size='50' name='search'> <input type='submit' name'submit' value='Search'> </center> </font> </html> Code: [Select] <?php //get data $button = $_GET['submit']; $search = $_GET['search']; if (!$button) echo "You Have to insert a Valid CID."; else [ if (strlen($search)<=2) echo "Search term too short.The CID contain 6 number"; else [ echo"You searcher for <b>&search</b><hr size='1'>" } } ?> Now i want the live search by the name of the profile... Can someone help me? Well I usually run my scripts in CLI.. I have it do something then sleep for x amounr of settings, is there anyway to make it show me the seconds counting down instead of just a blinkin cursor? |