PHP - I'd Like My Insert/update To Show Real Time Results On A Page...
I'm not looking for code, mostly just some direction, but I'm sure I'll be back as I try to shape the code. Also, I know very little about coding jQuery, Ajax, etc. Here is what I'm looking for:
Basketball coach enters a Page that only he (or admin) can see. (I have that part figured out.) Once there, he has a form to fill out with a player's name and other information. I'd rather there not be 12 rows of empty cells. (Coaches will view that as work) I'd rather not have the Page reload on each "Add", but that would be the lesser of two evils. Is there a way to keep a persistent connection so when a coach hits Add, the player gets added to the database, a new empty form shows up, and the player's information shows up below on a roster? Similar TutorialsI'm working on a chat using basic textarea input, post, but the problem that I'm facing is, if a person doesn't send something, then the output is not updated eg. other messages from other users updating in real time.
How is that achieved when you see new database entries pop up live, milliseconds after they are entered?
Do I set a constant refresh rate of some sort?
How do you update a section of a webpage without "refreshing" the entire page like the POST method?
Hi i need to count the number items in an album now on the album i have create a field called count which counts the number items in that album but now i dnt knw how to update those as soon insert a item in the table item so i thought woul be possible to create a script that when insert data into item tables also update album table row count by adding one like update count with A now A equal row count ++1 any help on start of it if possible???/ I have a form right now that Updates a table on my database. I was wondering if I could possibly still have that working but also Insert the same information into another table on the database when the submit button is pressed? I have a script that runs a MySQL query and loops through a bunch of results.
For each person's name, I have a short bio that I want to show/hide by clicking on the person's name. I have a basic start, but I can't figure out how to show/hide them individually. When I click on someone's name, it shows/hides all of the bio's. I do have an individual ID for each person, and could use that somehow, but I'm scratching my head trying to figure out how to accomplish that. Any ideas?
http://jsfiddle.net/APA2S/3644/
I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
Code: [Select] The form below is meant to retrieve the named attribute of a form input called "limitedtextfield" , along side the current date and store those values in a database. The form contains some javascript which can be disregarded for this particular problem. [code] <form name="mymind" style= "position:relative;left:40px;" action="insert_status.php" method="post"> <input name="limitedtextfield" type="text" onKeyDown="limitText(this.form.limitedtextfield,this.form.countdown,55);" onKeyUp="limitText(this.form.limitedtextfield,this.form.countdown,55);" maxlength="55"><br> <font size="1">(Maximum characters: 55)<br> You have <input readonly type="text" name="countdown" size="3" value="55"> characters left.</font> <input type="hidden" name="submitted" value="TRUE"/> <input style="position:relative;left:0px;bottom:0px;" type="submit" name="submit" value="Submit!" /> </form> Here is the php script that processes the form. What it is meant to do is search the database and if no record is found for the authenticated member, input the relevant values into the database. If a record is found, it should update the record. Well every time I hit the submit button, all I get is a blank page. Any clue as to what is going wrong? PS: I checked the database and no values got inserted. Code: [Select] <?php //address error handling ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); //authenticate user require('auth.php'); //Connect to database require ('config.php'); if (isset($_POST['submitted'])) { $query = "SELECT* FROM publications WHERE member_id ='".$_SESSION['id']."' AND cartegory='status'"; $result = @mysql_query($query); $num = @mysql_num_rows($result); if ($num> 0) { $update = mysql_query("UPDATE publications SET publication = '{$_POST['limitedtextfield']}' WHERE member_id = '".$_SESSION['id']."' AND cartegory = 'status'"); header("Location: member.php"); } else { $query = "INSERT INTO publications ( member_id, publication, cartegory, pub_date) VALUES ( '{$_SESSION['id']}','{$_POST['limitedtextfield']}', 'status', NOW() )"; header("Location: member.php"); } } ?> I know the php is basic and not completed yet, but I am working on that. My next step I want the result to show on index.php when a form is submitted to calculator2.php. I just cant seem to get it. Please help! index.php Code: [Select] <div class="post"> <h2 class="title">Calculator</h2> <hr /> <form method="post" action="calculator2.php"> Fireplace Front Width: <input type="text" name="fw"> <br /> Fireplace Back Width: <input type="text" name="bw"> <br /> Fireplace Depth: <input type="text" name="fd"> <br /> <input type="submit" name="Submit" value="Submit"> </form> Pounds Of Glass Needed: <?php echo $res1; ?> </div> calculator2.php Code: [Select] <?php $frontwidth = $_POST['fw']; $backwidth = $_POST['bw']; $firedepth = $_POST['fd']; $x = $frontwidth + $backwidth+ $firedepth; $y = ($x / 3) * .6667; $res1 = $y *2; echo $res1; ?> Hi again PhpFreaks, yet again I got a problem regarding coding. hiii all, i want to show the database field (alise name) as the url after index.php when page or site loads first time. how i can achieve it? please help.... thanks in advance Ok so I have a question. is it possible to make a form submit to a DB in real time without the need for a submit button ? if so could you drop a hint to what it would be caled or a tut / reference to it ? Hi guys, got some questions about the Instagram real-time api. first let me tell you what I want to do. I'd like to run a daemon process with a socket connection or something of the like to the Instagram API to get a constant feed of photos with a certain tag. We estimate it to be a large amount of data at a particular time (thus why we want to go Real-time). This process will parse the feed and store it into a mongodb database. Secondly, for the front end, I'd like to display all new, live photos in real-time, possible with ajax or some form of checking on a set interval. Problem being, I can't find anyone doing this with php. All of the resources I have seen use Node.js and Tornado. Has anyone done this with PHP or know of a good Real-time API demonstration/tutorial to get me started? Here's the documentation... http://instagr.am/developer/realtime/ any help would be greatly appreciated! thanks! Hi, i am thinking of creating a text based game mmorpg using php/mysql etc... I know that a lot of these types of games use a tick based system, but i want it to be realtime, the only game i cna find that uses this is Torn, does anyone know how they make it realtime? I know that ticks can be controlled by cronjobs, but how about realtime? The problem is that the game might involve the player building a house, in a tick based system it could be easy to manage by saying the house will take 3 ticks to complete, but i want the house to be like in 10 minutes of 32 minutes, how can i do this. Someone said to check whenever the player next logs in to check if the house has finished and then say it has been built, but seeing as it is an mmorpg it could affect everyones gameplay, not just the person building it, so this will not work. Thanks and sorry if this is a bit confusing. I wrote a short script that takes a list of keywords and does a Google search to find how often they are used in the title of a page. However, I cannot get it to echo the results in real time. On one server I use it works fine. On the other it runs the entire list and then outputs everything in the end. The problem is sometimes this takes several minutes and therefore it times out after not receiving a response. Any suggestions? Thanks in advance. <?php $file = file('words.txt'); $results = ''; foreach ($file as $line) { $data = file_get_contents("http://www.google.com/search?hl=en&q=allintitle%3A%22" . urlencode($line) . "%22&btnG=Google+Search"); preg_match('/of about <b>([0-9,]*)?<\/b>/si', $data, $number); $results .= $line . ";" . $number[1]; echo $results . "</br>"; $results = ""; sleep(2); } ?> Hi. How to implement twitter like real-time sharing system? So that is like, if my friend(following person) write a message, it also appear on my wall(page). 1. Is it hard? 2. What language used for it? PHP? 3. Is there any source about it? Thanks. This topic has been moved to Editor Help (Dreamweaver, Zend, etc). http://www.phpfreaks.com/forums/index.php?topic=322054.0 Hello, I am building an online game(users make a character and move on a map and so on...)
All user data is stored in a mySQL database and I want the users to interact in real-time, but there can be a 1-3 second delay between the communication, but not exceed 3 seconds even if 500 players are playing at the same time.
But for the purpose of the question let's say the users can only chat between one another, if I'll have a solution for that then I can use the same method for more parts of the game.
I can't use websockets because my webhost doesn't support it( I don't want to use pusher.com).
I know I can make real-time apps with ajax long polling, but I think that with 500 players playing at the same time it's not the best solution.
So, finally:
How can I make user interaction as close as possible to a real-time game?
(Without too much load on the hosting server)
(I am sorry if some of my terms are not correct - I am just getting back to coding after a long time...)
Edited by Mythion, 17 August 2014 - 02:34 AM. Hey there! So, I am working trying to get a page to edit and update field to insert back into the DB. But for some odd reason, the page just shows up vlank. I've added it to show errors, but still nothing is coming back, so I have no idea what the issue is. Not too sure if there is a config issue with PHP on my server or what. Here's my code: Code: [Select] <?php ini_set('display_errors', 1); //open DB connection include '../dbconn.php'; if ($_POST) { $msg=""; //build an update query $update = "update testspaces set status='$_POST[status]',spacenumber='$_POST[spacenumber]' where id='$_POST[id]'"; //execute query and check to see if it went through if (!mysql_query($update)) { $msg = "Error Updating User"; print $update; } else { $msg = "Record Updated Successfully"; echo "<br>"; echo "<br>"; echo "<br>"; echo "<div class='header2'><a href='adminindex.php'>Go Back To Edit</a></div>"; //print $update; //write a table row confirming the data $table_row = <<<EOR <TR> <td>$status</td> <td>$spacenumber</td> </TR> EOR; } //if not posted, check that an ID has been //passes VIA the URL } else { if (!IsSet($_GET['id'])) { $msg = "No User Selected!"; } else { $id = $_GET['id']; //build and execute da query $select = "select * from testspaces where id=$id"; $result = mysql_query($select); //check to see if the record is there if (mysql_num_rows($result) < 1) { $msg = "No User with that ID is found"; } else { //set the variables for the form code $form_start = "<FORM METHOD=\"post\"ACTION= \"" . $_SERVER['PHP_SELF'] . "\">"; $form_end = ' <TR> <TD COLSPAN="2"><input type="submit" value="Submit Changes" /> <input type="reset" value="Cancel Changes" /></td> </tr> </form> '; //assign the results to an array while ($row = mysql_fetch_array($result)){ $status = $row['status']; $space = $row['spacenumber']; //write out into table row with form fields $table_row = ' <table border="1" align="center" cellpadding="5" cellspacing="0"> <th>Space Number</th> <th>Status</th> </tr> <tr> <td><input type="text" name ="spacenumber" value ="' . $space . '" size="20"/></td> <td><input type="text" name ="status" value ="' . $status . '" size="20"/></td> </tr> <br /> <a href="editemployees.php">Back to Employees</a> '; } // end of while } // end of else num rows } // end of else isset get id } // end of else mysql update //print message echo (IsSet($msg)) ? "<div class=\"error\">$msg</div>" : ""; ?> <? echo (IsSet($form_start)) ? $form_start : ""; ?> <input type ="hidden" name="id" value="<? echo $id ?>" /> <? echo (IsSet($table_row)) ? $table_row : ""; ?> <? echo (IsSet($form_end)) ? $form_end : ""; ?> Not too sure what could be causing to become blank. I've developed a file upload service of sorts. Think TwitPic, TwitVid and Twaud combined and it's not that far off. I need to determine which content pages are most viewed. Right now I just count each and every page request, so... The problem I run into (of course) is that also agent/bot requests are counted, and for some reason search engines (or other services) are very keen on accessing pages with many pictures on them, so such accesses can easily "overload" and make the access counting quite skewed. Is there a black list of search engine user agents I could deploy, or is there a more generic way of knowing whether I get a request from a search engine rather than a user? I still want the content pages indexed by search engines, so they shouldn't become "invisible" to them, yet I need to be able to determine what accesses are from primarily real users. There's no need to log in to see the content, so I can't use that as a differentiator. I suspect there are also image grabbing agents accessing my pages, and honestly they could be shut out completely. Thanks in advance, Anders Hi, I have about 40 select boxes and I've allocated each of them an individual id because the amount of select boxes will never change. I've put each value in a JS array and then receive it in PHP through AJAX. The problem I am having is to do with inserting/updating data in the db. The problem is currently I have the following logic set when the user presses the save button: Code: [Select] [center] $sql = "SELECT * FROM tbl_supervision WHERE workload_id = '".$_SESSION['active_workload']."' AND semester = '1';"; $result = mysql_query($sql) or die ("Error in query: $sql. " . mysql_error()); $rows = mysql_num_rows($result); $supervision_data = array(); while($row = mysql_fetch_array($result)) { $supervision_data[] = $row; } if(!empty($supervision_data)) { for($i = 0; $i < count($supervision_data); $i++) { $sql4 = "UPDATE tbl_supervision SET workload_id = '".$_SESSION['active_workload']."', degree = '".$degree1array[$i]."', student_name = '".$student1array[$i]."', student_eft = '".$eft1array[$i]."', supervision_role = '".$role1array[$i]."' WHERE supervision_id = '".$supervision_data[$i]['supervision_id']."' AND semester = '1';"; $result4 = mysql_query($sql4) or die ("Error in query: $sql4. " . mysql_error()); if (!$result4) { die('Error: ' . mysql_error()); } else { $success = 1; } } } else { for($i = 0; $i < count($degree1array); $i++) { if($degree1array[$i] != "None" || $student1array[$i] != "" || !empty($eft1array[$i]) || $role1array[$i] != "") { if($degree1array[$i] != "None") { $sql7 = "INSERT into tbl_supervision (workload_id, degree, student_name, student_eft, supervision_role, semester) VALUES ('".$_SESSION['active_workload']."', '".$degree1array[$i]."', '".$student1array[$i]."', '".$eft1array[$i]."', '".$role1array[$i]."', '1');"; $result7= mysql_query($sql7) or die ("Error in query: $sql7. " . mysql_error()); if (!$result7) { die('Error: ' . mysql_error()); } else { $success = 1; } } } else { $success = 0; } } }[/center] What I want to achieve is: 1. If there are the same number of inputs in the db compared to the number of inputs received from the select boxes, the update query will simply kick in. 2. If there there are less number of inputs in the db compared to the number of inputs received from the select boxes, the insert query will only insert those values that aren't already in the db. Currently, with the code I have posted above, I can only insert values from scratch and only update those values that are already there in the db but I can't add in new values after the initial data has been inserted. I've tried using count() and sizeof() functions but I can't seem to work out how could I manipulate the code to achieve what should be straight forward functionality. Could anybody please help me out? The degree1array, student1array, eft1array & role1array are the arrays that contain the select box values.. Code: [Select] var degree1 = new Array (document.getElementById('degreetype1').value, document.getElementById('degreetype2').value, document.getElementById('degreetype3').value, document.getElementById('degreetype4').value, document.getElementById('degreetype5').value, document.getElementById('degreetype6').value, document.getElementById('degreetype7').value, document.getElementById('degreetype8').value, document.getElementById('degreetype9').value, document.getElementById('degreetype10').value); var student1 = new Array (escape(document.getElementById('studentname1').value), escape(document.getElementById('studentname2').value), escape(document.getElementById('studentname3').value), escape(document.getElementById('studentname4').value), escape(document.getElementById('studentname5').value), escape(document.getElementById('studentname6').value), escape(document.getElementById('studentname7').value), escape(document.getElementById('studentname8').value), escape(document.getElementById('studentname9').value), escape(document.getElementById('studentname10').value)); var eft1 = new Array (document.getElementById('eft1').value, document.getElementById('eft2').value, document.getElementById('eft3').value, document.getElementById('eft4').value, document.getElementById('eft5').value, document.getElementById('eft6').value, document.getElementById('eft7').value, document.getElementById('eft8').value, document.getElementById('eft9').value, document.getElementById('eft10').value); var role1 = new Array (document.getElementById('suprole1').value, document.getElementById('suprole2').value, document.getElementById('suprole3').value, document.getElementById('suprole4').value, document.getElementById('suprole5').value, document.getElementById('suprole6').value, document.getElementById('suprole7').value, document.getElementById('suprole8').value, document.getElementById('suprole9').value, document.getElementById('suprole10').value); Thanks I am logging occasions someone's profile is viewed. I will use a Cron to report the amount of views. Do I? (1) INSERT a record every time and count up at end. Remember, I'm using a Cron to report amount of views so won't be counting up on every page request!! (2) UPDATE a table (but won't I need to SELECT previous value first)? Unless, "UPDATE field1 and add 1 to it's value" is possible. Which is best? |