Jump to content

dishadcruze

Members
  • Content Count

    44
  • Joined

  • Last visited

Community Reputation

0 Neutral

About dishadcruze

  • Rank
    Member
  1. dishadcruze

    Keeping the user active even when the screen is locked

    @ kicken Can i PM my code to you? i have replaced header( "refresh:25...." ); instead of javascript. Still the problem is same. even in mobile also it happens the same.
  2. dishadcruze

    Keeping the user active even when the screen is locked

    Yeah, i am using javascript to submit form to set flag in leader's end like this <script type="text/javascript"> $(function(){ // document.ready function... setTimeout(function(){ $('#FrmID').submit(); },3000); }); </script> And in result page header( "refresh:25;url=play_game.php?id=".$grp_id."" );
  3. dishadcruze

    Keeping the user active even when the screen is locked

    i am using php and mysql. 1. Leader starts the game, a flag is set to 1 in database and players will see the questions (Only this needs Leader's click) 2. After 40 seconds, result will open in leader's side and the result flag will set to 1 and players will see the result. 3. After 40 seconds, it will go back to questions and same thing happens Leader will just starts the game and his work is done. Till he exists the game, it should be running. Here if the leader is inactive , the flag won't set and player have to wait till leader is active. I don't know how to overcome this
  4. I have a small online question and answer game. In which once a leader starts games, on particular time duration it goes on till he exits from the game. But when the leader's screen is inactive (both in mobile and laptop as well) / locked, the game stops, it doesn't work. How can i overcome this problem? i have not used cookies so far. is the cookies solve my problem? or any other way please suggest
  5. Yup!. Even i tried the same and this the only possible way to get the nearby result as i wanted. Thanks Barand
  6. Now i can't change the method of storing data. how should i solve it then?
  7. @Barand: i tried like this select jm.po_no, jm.vendor, jm.post_date, ji.ref_id, sum(case when ji.type = 'poo' then qty else 0 end) as ordered, sum(case when ji.type = 'por' then qty else 0 end) as received, sum(case when ji.type = 'poo' then qty else - qty end) as total FROM journal_main jm INNER JOIN journal_item ji ON jm.id=ji.ref_id WHERE ji.type IN('poo', 'por') group by jm.id but it returns ordered and received in separate row
  8. I have 2 tbles journal_main and journal_item. in journal main i have fields like id | po_no | period | post_date | vendor 1 | PO123 | 12 | 2018-02-12 | XYZ 2 | PO234 | 12 | 2018-02-13 | ABC in journal_item id | ref_id | type | sku | qty 1 | 1 | poo | A123 | 12 2 | 1 | poo | B234 | 20 3 | 2 | por | A123 | 2 4 | 2 | por | A123 | 3 5 | 2 | por | B234 | 6 i want to get the output as po_no | date | vendor | sku | ordered_qty | received_qty | balance po123 | 2018-02-12 | XYZ | A123 | 12 | 5 | 7 po123 | 2018-02-12 | ABC | B234 | 20 | 6 | 14 i am not getting how to combine 2 queries in a single query. Here i have 2 queries which gives me ordered_qty and received_qty separately for ordered_qty select journal_main.id, journal_main.po_no, journal_main.post_date, journal_main.vendor, journal_item. sku, SUM(journal_item.qty) AS Oqty FROM journal_main INNER JOIN journal_item ON journal_main.id=journal_item.ref_id WHERE journal_item.type='poo' GROUP BY journal_item.sku, journal_main.id for received_qty select journal_main.id, journal_main.po_no, journal_main.post_date, journal_main.vendor, journal_item. sku, SUM(journal_item.qty) AS Rqty FROM journal_main INNER JOIN journal_item ON journal_main.id=journal_item.ref_id WHERE journal_item.type='por' GROUP BY journal_item.sku, journal_main.id
  9. dishadcruze

    implementing php long polling

    Can somebody help me out with this?
  10. dishadcruze

    implementing php long polling

    I got the solutions for that. But in my server.php i am displaying a form which will be having few input fields. This should display in #response area. Now i am able to display the same on instant basis. As it loads on seconds basis, i am not able to enter anything on any input boxes. Here is my display page. <?php ob_start(); include('includes/sessions.php'); include('includes/config.php'); include('includes/functions.php'); $grp_id = $_GET['id']; ?> <!DOCTYPE html> <head> <!-- head section --> <script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script> <script type="text/javascript"> function getContent(timestamp) { var queryString = {'timestamp' : timestamp, 'id' : <?php echo $grp_id; ?>}; $.ajax( { type: 'GET', url: 'http://localhost/folder/server.php', data: queryString, success: function(data){ // put result data into "obj" var obj = JSON.parse(data); // put the data_from_file into #response $('#response').html(obj.data_from_file); // call the function again, this time with the timestamp we just got from server.php getContent(obj.timestamp); } } ); } // initialize jQuery $(function() { getContent(); }); </script> </head> <body<?php if ($body_classes) { echo ' class="' . $body_classes . '"'; } ?>> <div id="page-content" class="block"> <div class="row gutter30"> <div class="col-xs-12"> <div id="response"></div> <!--Contents in server.php will display according to the condition changes in database--> </div> </div> </div> server.php <?php set_time_limit(0); $data_source_file = 'data.txt'; include('includes/sessions.php'); include('includes/config.php'); include('includes/functions.php'); // main loop while (true) { // if ajax request has send a timestamp, then $last_ajax_call = timestamp, else $last_ajax_call = null $last_ajax_call = isset($_GET['timestamp']) ? (int)$_GET['timestamp'] : null; // PHP caches file data, like requesting the size of a file, by default. clearstatcache() clears that cache // clearstatcache(); // get timestamp of when file has been changed the last time // $last_change_in_data_file = filemtime($data_source_file); // Create database $sql = "SELECT max(gid) FROM base_grp WHERE gid=".$_GET['id'].""; $result = mysqli_query($conn, $sql); $last_change_in_data_file = mysqli_fetch_array($result, MYSQLI_NUM)[0]; // if no timestamp delivered via ajax or data.txt has been changed SINCE last ajax timestamp if ($last_ajax_call == null || $last_change_in_data_file > $last_ajax_call) { $sql = "SELECT is_set FROM base_grp WHERE gid =".$_GET['id'].""; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { if($row['is_set'] == 0) { $data .= '<form name="frm" method="post" action="show_data.php"> <div class="row gutter30" style="margin-top:20px;"> <div class="form-group"> <img src="img/img1.png" class="image" /> <input type="text" name="img1" class="form-control" /> <input type="hidden" name="img1_id" value="3" /> </div> <div class="form-group"> <img src="img/img2.png" class="image" /> <input type="text" name="img2" class="form-control" /> <input type="hidden" name="img2_id" value="4" /> </div> <div class="form-group"> <img src="img/img3.png" class="image" /> <input type="text" name="img3" class="form-control" /> <input type="hidden" name="img3_id" value="2" /> </div> <div class="form-group"> <img src="img/img4.png" class="image" /> <input type="text" name="img4" class="form-control" /> <input type="hidden" name="img4_1" value="1" /> </div> <button type="submit" name="lock" class="btn btn-sm btn-success">SUBMIT</button> </div> </form> '; $last_change_in_data_file = $row["gid"]; } else if($row['is_set'] = 1) { $data .= "<div class='row gutter30' style='margin-top:20px;'> <div class='col-xs-3'> <img src='img/img1.png' class='image' /> </div> <div class='col-xs-3'> <img src='img/img2.png' class='image' /> </div> <div class='col-xs-3'> <img src='img/img3.png' class='image' /> </div> <div class='col-xs-3'> <img src='img/img4.png' class='image' /> </div> </div> "; $last_change_in_data_file = $row["gid"]; } $last_change_in_data_file = $row["gid"]; } } // mysqli_close($conn); // put data.txt's content and timestamp of last data.txt change into array $result = array( 'data_from_file' => $data, 'timestamp' => $last_change_in_data_file ); mysqli_close($conn); // encode to JSON, render the result (for AJAX) $json = json_encode($result); echo $json; // leave this loop step break; } else { // wait for 1 sec (not very sexy as this blocks the PHP/Apache process, but that's how it goes) sleep( 1 ); continue; } } I tried adding delay of 20 seconds in function like this $(function() { setTimeout("getContent();",20000); }); But for 1st time also it takes 20 secs to display data. Can somebody suggest me where i am going wrong?
  11. dishadcruze

    implementing php long polling

    @ mac_gyver My exact scenario is: There is a group A formed by a user User1 and in that group there will be minimum 4 members. When minimum 4 members are online, group owner (User1) will updates some queries on db and he will hit a button 'OK'. When he hits the button , a filed in database sets 1. When this sets to 1, all the online users of this group gets the notification about this. And for them approve button will be activated. Once they approve its immediately visible to admin that who all approved. I am doing it with php-long-polling. But here i am not getting how exactly i can use this to my requirement. I just need some hints and direction. Can you please guide me how can i go with this along with php long polling. I am not comfortable in java-scripts so i am using this.
  12. dishadcruze

    implementing php long polling

    Yes even i want to display the record according to 'last_id' but i can query in sql and php , but my only problem is to display as and when it updated. Here i stuck
  13. dishadcruze

    implementing php long polling

    basically i want to pass a variable to this page along with timestamp. Timestamp is getting passed like this in client.js timestamp is getting passed like this function getContent(timestamp) { var queryString = {'timestamp' : timestamp}; $.ajax( { type: 'GET', url: 'http://localhost/php-long-polling/server/server.php', data: queryString, success: function(data){ // put result data into "obj" var obj = jQuery.parseJSON(data); // put the data_from_file into #response $('#response').html(obj.data_from_file); // call the function again, this time with the timestamp we just got from server.php getContent(obj.timestamp); } } ); } // initialize jQuery $(function() { getContent(); }); so here i am not getting how to do it
  14. dishadcruze

    implementing php long polling

    No, what i meant was, how to send that 'id' through url or post to this page??
  15. dishadcruze

    implementing php long polling

    After many attempts i could do it like this in server.php, i did like this <?php /** * Server-side file. * This file is an infinitive loop. Seriously. * It gets the file data.txt's last-changed timestamp, checks if this is larger than the timestamp of the * AJAX-submitted timestamp (time of last ajax request), and if so, it sends back a JSON with the data from * data.txt (and a timestamp). If not, it waits for one seconds and then start the next while step. * * Note: This returns a JSON, containing the content of data.txt and the timestamp of the last data.txt change. * This timestamp is used by the client's JavaScript for the next request, so THIS server-side script here only * serves new content after the last file change. Sounds weird, but try it out, you'll get into it really fast! */ // set php runtime to unlimited set_time_limit(0); // where does the data come from ? In real world this would be a SQL query or something $data_source_file = 'data.txt'; $servername = "localhost"; $username = "*****"; $password = "******"; $dbname = "mydb"; // Create connection $conn = mysqli_connect($servername, $username, $password , $dbname); // Check connection if (!$conn) { die("Connection failed: " . mysqli_connect_error()); } // main loop while (true) { // if ajax request has send a timestamp, then $last_ajax_call = timestamp, else $last_ajax_call = null $last_ajax_call = isset($_GET['timestamp']) ? (int)$_GET['timestamp'] : null; // PHP caches file data, like requesting the size of a file, by default. clearstatcache() clears that cache // clearstatcache(); // get timestamp of when file has been changed the last time // $last_change_in_data_file = filemtime($data_source_file); // Create database $sql = "SELECT max(tax_id) FROM taxes"; $result = mysqli_query($conn, $sql); $last_change_in_data_file = mysqli_fetch_array($result, MYSQLI_NUM)[0]; // if no timestamp delivered via ajax or data.txt has been changed SINCE last ajax timestamp if ($last_ajax_call == null || $last_change_in_data_file > $last_ajax_call) { // get content of data.txt // $data = file_get_contents($data_source_file); // Create database $sql = "SELECT tax_id, name FROM taxes"; $result = mysqli_query($conn, $sql); if (mysqli_num_rows($result) > 0) { // output data of each row while($row = mysqli_fetch_assoc($result)) { $data .= "id: " . $row["tax_id"]. " - Name: " . $row["name"]. "<br>"; $last_change_in_data_file = $row["id"]; } } // mysqli_close($conn); // put data.txt's content and timestamp of last data.txt change into array $result = array( 'data_from_file' => $data, 'timestamp' => $last_change_in_data_file ); mysqli_close($conn); // encode to JSON, render the result (for AJAX) $json = json_encode($result); echo $json; // leave this loop step break; } else { // wait for 1 sec (not very sexy as this blocks the PHP/Apache process, but that's how it goes) sleep( 1 ); continue; } } But i want to get the data according to particular id. my sql statement has to be something like this $sql = "SELECT tax_id, name FROM taxes WHERE grp_id=".$id.""; So i am not getting from where i should pass the id to this page Can somebody help me in this??
×

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.