PHP - Php/jquery Auto-refresh: Only Fade-in New Rows In Database Since Last Refresh
Hi all,
Thanks for reading. I'm running a script using jQuery that auto-refreshes a <div> on the index page from an external PHP script to get all the rows in a database and display them on the index page. The script works great - here it is as follows: Code: [Select] <script type="text/javascript"> $(document).ready(function() { $("#responsecontainer").fadeOut("fast").load("getrows.php").fadeIn("slow"); var refreshId = setInterval(function() { $("#responsecontainer").fadeOut("fast").load('getrows.php').fadeIn("slow"); }, 5000); $.ajaxSetup({ cache: false }); }); </script> The getrows.php script I'm working with looks like this: Code: [Select] <?php $rowsQuery = mysql_query("SELECT * FROM Happenings WHERE HappeningDate='$today'"); if (mysql_num_rows($rowsQuery) == 0) { $happeningsToday = "There are no happenings today."; } else { $allHappeningsToday = 1; while ($getHappeningsToday = mysql_fetch_array($rowsQuery)) { $happeningName = stripslashes($getHappeningsToday['HappeningName']); $happeningDate = $getHappeningsToday['HappeningDate']; $happeningDescription = $getHappeningsToday['HappeningDescription']; if ($allHappeningsToday == 1) { $happeningsToday .= " <div class=\"box\"> <p>".$happeningName." | ".$happeningDate." | ".$happeningDescription." </div>"; $allHappeningsToday = 2; } else { $happeningsToday .= " <div class=\"box\"> <p>".$happeningName." | ".$happeningDate." | ".$happeningDescription." </div>"; $allHappeningsToday = 1; } } } echo $happeningsToday; ?> This script works great as well. Currently, the auto-refresh jQuery script as you can see if getting and fading in/out all of the rows. Off of the above getrows.php script, is there a way after I could get only the newly created rows since the last refresh and only fade those in and out while leaving the others already loaded by the auto-refresh script to not fade in/out? Any ideas, thoughts or suggestions would be unbelievably helpful. Thank you very much. Similar Tutorialsis there a way to auto refresh the same page youre on after a script runs? Hi all, I am having some trouble with a part of code. Basically the code is set for a Factory to produce 750 items every 30 minutes. It does this fine IF AND ONLY IF someone clicks the Factory page. For example, it produces 750 bullets, then I leave the page alone for say 20 minutes, but when I click back, it doesn't have 10 minutes left before the next produce. Instead, It has 30 minutes. So it only produces when someone on the game clicks the page. I have tried the basic html refresh but that doesn't work. Any idea's? Thanks in advance please this code is not working,i want when users comment on a page it should refresh this is my code: Code: [Select] <h3>Comments:</h3> <table> <tr class="row-a"> <td class="first"></td> <td><?php include"header.php"; $sql="SELECT post_content,post_by FROM post ORDER BY topicsID"; $result=mysql_query($sql)or die(mysql_error()); while($row=mysql_fetch_array($result)) { echo"<strong>{$row['post_by']}</strong>: {$row['post_content']}"."</br>"; } if(mysql_affected_rows()>0) { header("location:".$_SERVER['PHP_SELF']); } ?></td> </tr> </table> <h3>Post your comments here</h3> <form action='reply.php'method='post'> <textarea name="comment" id="content" style="width:400px;height:50px;background-color:#D0F18F;color:#000000;font:15px/20px cursive;scrollbar-base-color:#638E0D;"></textarea> <br /> Name:<input type="text"name="name"/> <input class="button" type="submit"name="submit"value="submit" /> </p> </form> <br /> [code] I think I'm seriously missing some small thing to get this code to just auto refresh after (x) seconds or after video completes fully. This is for users to watch from a database of other users that submitted url's - right now all I could put a skip button to auto-refresh. If anyone can help or at least point me into the right direction on some snippets I can kind-of work off of. here is the snippet (kind-of a big snippet) Code: [Select] <? include('header.php'); foreach($_GET as $key => $value) { $secure[$key] = filter($value); } if($_GET['a'] == "skip"){ $sit1 = mysql_query("SELECT * FROM `youtube` WHERE `id`='{$secure['id']}'"); $sit = mysql_num_rows($sit1); if($sit > 0){ mysql_query("INSERT INTO `viewed` (user_id, site_id) VALUES('{$data->id}','{$secure['id']}')"); }} ?> <div class="block medium right"> <div class="top"><?if(isset($data->login)) {?> <h1>Earn Coins - Youtube</h1> </div> <div class="content"> <? // fetches all "unplayed" youtube videos for this user // $site2 = mysql_query("SELECT * FROM `youtube` WHERE (`active` = '0' AND `points` >= `cpc`) AND `id` NOT IN (SELECT `site_id` FROM `viewed` WHERE `user_id`='{$data->id}') ORDER BY `cpc` DESC LIMIT 0, 1"); $site = mysql_fetch_object($site2); $ext = mysql_num_rows($site2); if($ext > 0){ ?> <script src="js/swfobject.js"></script> <script type="text/javascript"> var playing = false; var fullyPlayed = false; var interval = ''; var played = 0; var length = 30; function YouTubePlaying(){ played += 0.1; roundedPlayed = Math.ceil(played); document.getElementById("played").innerHTML = Math.min(roundedPlayed,length); if (roundedPlayed == length){ if (fullyPlayed == false){ YouTubePlayed(); fullyPlayed = true; } } } function YouTubePlayed(){ var response = '<? echo $site->youtube;?>'; var username = "<? echo $data->id;?>"; $.post("ytreceive.php", { data: response + "---" + username}, function(result){ if(!isNaN(result)) { var curr_val = $('#points').text(); var new_val = parseInt(curr_val)+parseInt(result); $('#points').text(new_val); } } ); document.getElementById(response).style.visibility = "visible"; } function onYouTubePlayerReady(playerId){ ytplayer = document.getElementById("myytplayer"); ytplayer.addEventListener("onStateChange", "onYouTubePlayerStateChange"); } function onYouTubePlayerStateChange(newState){ if (newState == 1){ playing = true; interval = window.setInterval('YouTubePlaying()',100); }else{ if (playing) window.clearInterval(interval); playing = false; } } function refreshpage() { window.location.reload(); } </script> <center> <div style="width: 520px; padding: 10px;"> <h3>"<? echo $site->title;?>"</h3> View this video for 30 seconds and after that you will receive <? echo $site->cpc;?> coins<br/><br/> <div id="ytPlayer">You need Flash player 8+ and JavaScript enabled to view this video.</div> <script type="text/javascript"> var params = { allowScriptAccess: "always" }; var atts = { id: "myytplayer" }; swfobject.embedSWF("http://www.youtube.com/v/<? echo $site->youtube;?>?enablejsapi=1&playerapiid=ytplayer&autoplay=1", "ytPlayer", "425", "356", "8", null, null, params, atts); </script> <br/> <br />Must play for <span id="played">0</span>/10 seconds (<a href="youtube.php?a=skip&id=<? echo $site->id;?>" style="color:blue">Skip</a>) <div id="<? echo $site->youtube;?>" style="visibility:hidden"><a href="javascript:refreshpage()">View Next Video</a></div> </div></center> <?}else{?> <div class="msg"> <div class="error">Sorry, there are no more coins to be earned at the moment. Please try again later.</div> <div class="info"><a href="buy.php"><b>Feel like you need more coins? You can purchase them now!</b></a></div></div> <?}}else{?><script>document.location.href='index.php'</script><?}?> </div> </div> <?include('footer.php');?> Hi. I am trying to get a PHP Query to refresh every 10 seconds. I have scoured the internet for days and could not find anything of much use. Plenty of Ajax going on (whatever that is) but the scripts were immense. I only want to refresh 7 lines of PHP Query Code. Can you please tell me if this is possible? Thanks in Advance. Help me...
My objective is to reload the marker inside google map every 30s...
But the scripts below seem not running properly...
<?php define('INCLUDE_CHECK',1); include "dbconnect.php"; ?> <!DOCTYPE html> <html lang="en"> <head> <title></title> <meta charset="UTF-8" /> <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name ="audience" CONTENT="all"> <meta name ="revisit-after" CONTENT="4 days"> <meta name ="content-Language" CONTENT="English"> <meta name ="distribution" CONTENT="global"> <link rel="shortcut icon" href="favicon.png"/> <link rel="stylesheet" type="text/css" href="host_entry/css/demo.css" /> <link href="host_entry/css/bootstrap.min.css" rel="stylesheet" media="screen"> <script type="text/javascript" src="host_entry/js/jquery-1.7.1.min.js"></script> <script src="host_entry/js/bootstrap.min.js"></script> <!-- Google Map JS --> <script src="http://maps.google.com/maps/api/js?key=AIzaSyDY0kkJiTPVd2U7aTOAwhc9ySH6oHxOIYM&sensor=false" type="text/javascript"></script> <script> //SCRIPTS TO RESFRESH THE MARKER...I THINK THIS IS INCORRECT...HELP!!! $(document).ready(function() { $.ajaxSetup({ cache: false }); // This part addresses an IE bug. without it, IE will only load the first number and will never refresh setInterval(function() { $('#result').load('index.php'); }, 10000); // the "3000" here refers to the time to refresh the div. it is in milliseconds. }); // ]]> </script> </head> //to dislay the map <div id="map_canvas" style="top:55px;left:13px;"> <!-- Map will display --> <div id="map"> <!-- Fullscreen Loading & Fullscreen Buttons area --> <span style="color:Gray;">Loading map...</span> </div> <!-- Fullscreen Loading & Fullscreen Buttons area Ends --> </div><!-- Map Ends display --> <script type="text/javascript"> var locations = [ <?php $query="SELECT * from host_entry"; $result=mysql_query($query)or die(mysql_error()); { if ($num=mysql_numrows($result)) { $i=0; while ($i < $num) { $id=mysql_result($result,$i,"id"); //$host_type=mysql_result($result,$i,"host_type"); $host_name=mysql_result($result,$i,"host_name"); $host_status=mysql_result($result,$i,"host_status"); $host_lapt=mysql_result($result,$i,"host_lapt"); $host_long=mysql_result($result,$i,"host_long"); if($host_status==0) echo "[ '<div id=result><div class=info style=text-align:center;><h4>$host_name</h4></div></div>', $host_lapt, $host_long],"; $i++; } }else { echo "<h3 align='center'><font color='#ff0000'>No Content Found</font></h3>"; } } ?> ]; //FROM HERE TO SET THE MARKER IMAGE // Setup the different icons and shadows var iconURLPrefix = 'host_entry/img/'; var icons = [ iconURLPrefix + 'p_red_alert.png' ] var icons_length = icons.length; var map = new google.maps.Map(document.getElementById('map'), { zoom: -5, center: new google.maps.LatLng(3.1215681, 101.71180140000001), mapTypeId: google.maps.MapTypeId.ROADMAP, mapTypeControl: false, streetViewControl: false, disableDefaultUI: true, panControl: false, zoomControlOptions: { position: google.maps.ControlPosition.LEFT_BOTTOM } }); var infowindow = new google.maps.InfoWindow({ maxWidth: 400, maxHeight: 350, }); var marker; var markers = new Array(); var iconCounter = 0; //I THINK THE PROBLEM START HERE...:( // Add the markers and infowindows to the map for (var i = 0; i < locations.length; i++) { marker = new google.maps.Marker({ position: new google.maps.LatLng(locations[i][1], locations[i][2], locations[i][3], locations[i][4], locations[i][5]), map: map, animation: google.maps.Animation.BOUNCE, icon : icons[iconCounter], }); markers.push(marker); google.maps.event.addListener(marker, 'click', (function(marker, i) { return function() { infowindow.setContent(locations[i][0]); infowindow.open(map, marker); } })(marker, i)); iconCounter++; // We only have a limited number of possible icon colors, so we may have to restart the counter if(iconCounter >= icons_length){ iconCounter = 0; } } function AutoCenter() { // Create a new viewpoint bound var bounds = new google.maps.LatLngBounds(); // Go through each... $.each(markers, function (index, marker) { bounds.extend(marker.position); }); // Fit these bounds to the map map.fitBounds(bounds); } AutoCenter(); google.maps.event.addDomListener(window, 'load', initialize); </script> <?php //include "includes/footer.php"; ?> </body> </html>Is there a way to reload the marker with the ability of ajax towards the markers Help me for the solution... Thanks.... i got a submit button... if user click the submit button iwant to page will auto referesh... can someone teach me After I've successfully inputted something in my script and then click refresh in Chrome with "Right Click -> Reload", the same thing that I've inputted before gets re-inserted AGAIN into the database, thus resulting in multiple versions of the same thing in the MySQL database. How can I prevent that? p.s. Chrome is warning with a pop up of repeated action, and when I then click continue the repeated insertion of the data occurs, and I'd like to prevent the repeated insertion. Hi Is it necessary to hash stored access and refresh tokens that are stored in a database. Both these tokens have limited lifespan (access token - 20 minutes but refresh token is 14 days). The reason I ask is I have hashed the tokens using the password_hash function but a user can have multiple active sessions if they want (so there is a sessions table with user id (not username), access token, token expiry date/time, refresh token and refresh token expiry date/time. So in order to refresh the access token I have to do a look up to see which session it relates to, what I have found is that I must retrieve all rows where the refresh token hasn't expired and then run password_verify against the tokens stored with the tokens provided to check each session to see if they match. What I have found is that it takes a while to run the password_verify function (by design I think) for each row (could be many if the users has been silly and logged in lots of time) which would cause an unacceptable delay when calling an API with an access token that needs refreshing (my tests resulted in times upwards of 30 seconds for a user who has around 10 active sessions). If both tokens were not hashed the same action to refresh a token for a user who has 10 active sessions takes less than a second which is much more acceptable. Edited December 15, 2018 by mds1256hi all i am having a big problem that i have been trying to find out what is going on for weeks. i have a echo script that echos data that is in my database, and if i have to refresh the page it will add blank data in my database and the top echo info is blank as well. how can i fix this, and i was wanting to know how do i echo out my info in a textarea. i added a jepg to show you what i mean. here is my code echoforms.php <?php error_reporting(0); require_once('demo.php'); /*Open the connection to our database use the info from the config file.*/ $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD); $sql = "SELECT company_name, contact_name, address, street_number, postcode, contact_number, contact_email, budget, description FROM 3dartactforms"; $results = mysql_query($sql); if (!$results) { die('Invalid query: ' . mysql_error()); } while($result = mysql_fetch_array( $results )){ echo '<div style="border: 1px solid #e4e4e4; padding: 15px; margin-bottom: 10px;">'; echo date("d/m/y"); echo '<p>Company Name: ' . $_POST['company_name'] . '</p>'; echo '<p>Contact Name: ' . $_POST['contact_name'] . '</p>'; echo '<p>Address: ' . $_POST['address'] . '</p>'; echo '<p>Street Number: ' . $_POST['street_number'] . '</p>'; echo '<p>Postcode: ' . $_POST['postcode'] . '</p>'; echo '<p>Contact Number: ' . $_POST['contact_number'] . '</p>'; echo '<p>Contact Email: ' . $_POST['contact_email'] . '</p>'; echo '<p>Budget: ' . $_POST['budget'] . '</p>'; echo '<p>Description: ' . $_POST['description'] . '</p>'; echo '</div>'; } ?> I have been working on my local machine and haven't had any errors. I just deployed my site live and I'm getting a database error in my auto-complete text box. Any help would be much appreciated! I'm thinking there may be an error in my the way I'm naming the mysql connect names, but the fact that database data is being populated is confusing me. Wondering if something is wrong with the code? Thanks for the help in advance! These are the errors: Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: A link to the server could not be established in /home/content/99/7862599/html/gadgetabulous/Database/filename.php on line 3 Warning: mysql_real_escape_string() [function.mysql-real-escape-string]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/content/99/7862599/html/gadgetabulous/Database/filename.php on line 3 (here is a link if you want to see the error: http://gadgetabulous.com/cellphoneform.php(just type "iphone" in the search box and the error will appear)) Here is my db file: Code: [Select] <?php $q=$_GET['q']; $my_data=mysql_real_escape_string($q); $mysqli=mysqli_connect('host','root','password','dbname') or die("Database Error"); $sql="SELECT name FROM cell_brands WHERE name LIKE '%$my_data%' ORDER BY name"; $result = mysqli_query($mysqli,$sql) or die(mysqli_error()); if($result) { while($row=mysqli_fetch_array($result)) { echo $row['name']."\n"; } } mysql_close($mysqli); ?> Thank you in advance for the help! "BACK" or REFRESH: Preventing database interaction / code execution how to prevent database interaction / code execution when user presses back or refresh button? can i detect? can i disable back/refresh? I forgot my password for my old account so had to create a new one. New laptop.
Anyway, I've searched and searched but can't find a jQuery, javascript or anything else to do what I want to do. I want to fade out all the different paragraphs of a div one letter at a time starting with the first.
Here is something CLOSE though the string has to be input. I'm pulling data in from a database with PHP. So not sure if I can target individual letters in different paragraphs.
$(function () { var string = " David"; var q = jQuery.map(string.split(''), function (letter) { return $('<span>' + letter + '</span>'); }); var dest = $('#fadeIn'); var c = 0; var i = setInterval(function () { q[c].appendTo(dest).hide().fadeIn(1000); c += 1; if (c >= q.length) clearInterval(i); }, 1000); });I know I can get my target from a div then split it into characters with something like this: function arrayMe(string) { // For all matching elements $(string).each(function() { var myStr = $(this).html(); myStr = myStr.split(""); var myContents = ""; for (var i = 0, len = myStr.length; i < len; i++) { myContents += '' + myStr[i] + ''; } $(this).html(myContents); }); }Then call the function: $('document').ready(function() { var myStringType = $('.sample-text'); arrayMe(myStringType); });Where my div as a class of sample-text. (These are just code snippets I have pulled from the net in my search for an answer). But using the fade in which nice in jsfiddle, How can I put all these together to fade out my text a single letter at a time? I'm not sure if different paragraphs will work or not or if I'm going to have to have one long paragraph (bad for my application). Thanks for the help here guys. You've always come through for me before. It's just been awhile since I've been stumped. will refresh a page every second will cause some crash or error ?? cause when i try this, it sometimes display this error "Warning: mysql_connect() [function.mysql-connect]: Can't connect to MySQL " this is occur when i run it in my local server. I am so worried if this might also happen when i run it online. thanks So basically, My Bulletfactory page is playing up. Every 30 minutes the bulletfactory should produce bullets, it is producing the bullets fine, but only when someone views the page (after 30 minutes is up). If there any kind of PHP refresh for this? Or do i just use normal refresh? Thanks I have a php page that is maid up of three pieces. header.php main.php footer.php I can't figure out how to refresh the header.php and footer.php without refreshing the main.php. Anyone have an example of how I can do this. Thanks hits i have already echoed title and included that file in my php script, a header file.... but now i want to refresh my php script if the comment has been successfully added else remain in the same page....it remains in the same page now with just a msg that the comment is added....but i cant see the comment unless i refresh the page... i get he headers already sent error when i put a header() there as i have included another php file which already echoes title to screen....so what do i do now? i want the comment to be displayed to the user once he clicks on save and not make it tedious for him to refresh....any suggestions?any way around? After I submit form data how can I force the page to refresh so I can see the changes take effect? I know this is probably a very basic question. hello, i have a page that parses a string from espn and i have a style sheet that makes it refresh every 2 minutes. the thing that is buggin me is that when i load the page it loades with the last cached data so i have to wait 2 minutes for the info to update. is there any way to force the current content on load, and keep my refresh every 2 minutes still? thanks |