example of event to fetch the data from a table on every 5

  • kaif
  • Born
  • Born
  • kaif
  • Posts: 4

Post 3+ Months Ago

The events are working on insert and delete,but it is not working on select command. this is my code,


SQL Code: [ Select ]
CREATE EVENT `kaif`
  ON SCHEDULE EVERY 5 SECOND
do
     SELECT * FROM test.temp2;
  1. CREATE EVENT `kaif`
  2.   ON SCHEDULE EVERY 5 SECOND
  3. do
  4.      SELECT * FROM test.temp2;


this event is not working why


I want to execute the query on every 1 hour,how to write this
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • Satwant
  • Graduate
  • Graduate
  • User avatar
  • Posts: 127
  • Loc: Bangalore

Post 3+ Months Ago

kaif wrote:
The events are working on insert and delete,but it is not working on select command. this is my code,
SQL Code: [ Select ]
CREATE EVENT `kaif`
  ON SCHEDULE EVERY 5 SECOND
do
     SELECT * FROM test.temp2;
  1. CREATE EVENT `kaif`
  2.   ON SCHEDULE EVERY 5 SECOND
  3. do
  4.      SELECT * FROM test.temp2;

This Code is Fine

kaif wrote:
this event is not working why


The Event is working But you are not able to see it because it has no effect on db. This code just select Rows and Discard Them.
kaif wrote:
I want to execute the query on every 1 hour,how to write this


I think You want to show records in Browser Window, Online. You can use a Small Ajax code With Set Interval Functionality which Call It self after 1 hour and Update View. :)
  • kaif
  • Born
  • Born
  • kaif
  • Posts: 4

Post 3+ Months Ago

satwant,Thanks to ur response,

I don't know the ajax programming

please give me the code how to run on the windows.

Instead writing ajax,can we use php ?

if yes please give me the code,its urgent

Please help me friend

Kaif
  • Satwant
  • Graduate
  • Graduate
  • User avatar
  • Posts: 127
  • Loc: Bangalore

Post 3+ Months Ago

kaif wrote:
satwant,Thanks to ur response,

I don't know the ajax programming

please give me the code how to run on the windows.


First: whenever U encounter New Development Words always try to Google them and learn them. Because U will Learn them only once and they will help you lifetime :)

kaif wrote:
Instead writing ajax,can we use php ?

Not directly with php but with html ,u can do this By Setting Meta Page refresh in Head section of your html page
Following code will make a page to refresh after 5 seconds
Code: [ Select ]
<html>
<head>
<meta http-equiv="refresh" content="5" /> </head></html>
  1. <html>
  2. <head>
  3. <meta http-equiv="refresh" content="5" /> </head></html>


kaif wrote:
if yes please give me the code,its urgent


I make a very simple example to Show this simple concept. Before u implement This please Try to understand usage of functions

Here is Javascript And Html Code
Code: [ Select ]
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Random Country Select By Satwant Hundal</title>
<script type="text/javascript">
    /* By: Satwant Hundal
      Script : Usage of Set Interval For Ajax Calls
    */
    //This is Function to call Over Certain Interval
    var i_am_Function=function()
    {
        // following code is used to initiate Ajax call Object Called XMLHTTPOBJECT
        xmlhttp="";
        if (window.XMLHttpRequest)
        {// code for IE7+, Firefox, Chrome, Opera, Safari
            xmlhttp=new XMLHttpRequest();
        }
        else
        {// code for IE6, IE5
            xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
        }
        //Function to Handle Data Send By Php Code from Server
        xmlhttp.onreadystatechange=function()
        {
            if (xmlhttp.readyState==4 && xmlhttp.status==200)
              {
                //code to update Your Html Page
                var x=document.getElementById('country_name');
                x.innerHTML='Ramdom Country:'+xmlhttp.responseText;
            }
                
        };
        xmlhttp.open("GET",'data.php',true);
        xmlhttp.send();
    }
    window.onload=function(e)
    {
        // Seeting Up Set Interval Function to 5000 millisecond which means 5 seconds
        //for Hour you need to put 3600000
        i_am_Function();
        var TimeOutId=setInterval(i_am_Function, 5000);
        // Time Out ID is Used to Identify Particular Set Interval. Use this to Clear it when u dont
        //need it.
        //clearInterval(TimeOutId);
    }
</script>
<style type="text/css">
    #country_name
    {
        width: 100%; height: 100%; font-size: 80px;
    }
</style>
</head>
<body>
    <!-- This is Place which is Updated By Above Code -->
    <div id="country_name"></div>
</body>
</html>
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
  2. <html>
  3. <head>
  4. <title>Random Country Select By Satwant Hundal</title>
  5. <script type="text/javascript">
  6.     /* By: Satwant Hundal
  7.       Script : Usage of Set Interval For Ajax Calls
  8.     */
  9.     //This is Function to call Over Certain Interval
  10.     var i_am_Function=function()
  11.     {
  12.         // following code is used to initiate Ajax call Object Called XMLHTTPOBJECT
  13.         xmlhttp="";
  14.         if (window.XMLHttpRequest)
  15.         {// code for IE7+, Firefox, Chrome, Opera, Safari
  16.             xmlhttp=new XMLHttpRequest();
  17.         }
  18.         else
  19.         {// code for IE6, IE5
  20.             xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  21.         }
  22.         //Function to Handle Data Send By Php Code from Server
  23.         xmlhttp.onreadystatechange=function()
  24.         {
  25.             if (xmlhttp.readyState==4 && xmlhttp.status==200)
  26.               {
  27.                 //code to update Your Html Page
  28.                 var x=document.getElementById('country_name');
  29.                 x.innerHTML='Ramdom Country:'+xmlhttp.responseText;
  30.             }
  31.                 
  32.         };
  33.         xmlhttp.open("GET",'data.php',true);
  34.         xmlhttp.send();
  35.     }
  36.     window.onload=function(e)
  37.     {
  38.         // Seeting Up Set Interval Function to 5000 millisecond which means 5 seconds
  39.         //for Hour you need to put 3600000
  40.         i_am_Function();
  41.         var TimeOutId=setInterval(i_am_Function, 5000);
  42.         // Time Out ID is Used to Identify Particular Set Interval. Use this to Clear it when u dont
  43.         //need it.
  44.         //clearInterval(TimeOutId);
  45.     }
  46. </script>
  47. <style type="text/css">
  48.     #country_name
  49.     {
  50.         width: 100%; height: 100%; font-size: 80px;
  51.     }
  52. </style>
  53. </head>
  54. <body>
  55.     <!-- This is Place which is Updated By Above Code -->
  56.     <div id="country_name"></div>
  57. </body>
  58. </html>


This Code is Stored in server in a Php File
Code: [ Select ]
// Your Connection String Replace UserName and Password
    $con = mysql_connect("localhost","YOUR USER NAME","YOUR PASSWORD") or die("Error: ".mysql_error());
    //Your DATABASE NAME where country table is stored
    mysql_select_db('ssb',$con) or die("Error: ".mysql_error());
    $sql="SELECT * FROM `country` ORDER BY RAND() LIMIT 0,1";
    $record=mysql_query($sql,$con) or die("Error: ".mysql_error());
    $row=mysql_fetch_row($record);
    print_r($row[1]);
    mysql_close($con) or die("Error: ".mysql_error());
  1. // Your Connection String Replace UserName and Password
  2.     $con = mysql_connect("localhost","YOUR USER NAME","YOUR PASSWORD") or die("Error: ".mysql_error());
  3.     //Your DATABASE NAME where country table is stored
  4.     mysql_select_db('ssb',$con) or die("Error: ".mysql_error());
  5.     $sql="SELECT * FROM `country` ORDER BY RAND() LIMIT 0,1";
  6.     $record=mysql_query($sql,$con) or die("Error: ".mysql_error());
  7.     $row=mysql_fetch_row($record);
  8.     print_r($row[1]);
  9.     mysql_close($con) or die("Error: ".mysql_error());


You can download Full example from My Site http://satwant(.)tk/publicDownload/CountryExample.zip

Post Information

  • Total Posts in this topic: 4 posts
  • Users browsing this forum: No registered users and 79 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.