PHP - Php Repeating Interval Function
Hey,
I'm not that familiar with PHP so maybe what I'm asking for is not even possible. I plan to establish a webserver that is connected to a RS232 device. I don't have any problems accessing the RS232 interface with a PHP-script, it's all working fine. Now I want the incoming data from the device being display on the servers webpage almost in realtime. When I say almost I mean that the client who is logged on to the website should be able to define the update rate of the incoming data. So here comes the problem, I need something like the java script setinterval() function that is working on the server-side and repeats the data request to the device in an infinite loop with the given time interval. I don't want to refresh the whole page as I will have to update about 20 sets of data within seconds! I found this code: http://phpclasses.chimit.nl/package/5544-PHP-Call-a-function-after-a-period-of-time.html it looks pretty promissing but I just can't make it working... As I said I'm a PHP-noob so I just put the code below on the start of my own code and provided the Timer.class.php file in my project folder. Could anyone explain how I could make the test function repeating endlessly on a 1sec basis using this code so I would get a screen full of "called"? So far I only get two "called" :-) Thanks! declare(ticks=100); function test () { print "<br>called"; } require_once 'Timers.class.php'; setTimeout('test', 110000000); setInterval('test', 10000000); Similar TutorialsHi guys i am a complete novice learning. I want to automatically load a form page without using the submit button. i can get the page to load no problems but the url keeps refreshing in the browser window ? here is the code i am using.
<h3>View Mileage.</h3> <form method="post" action="testmileage.php" name="mileage" id = "mileage"> <input type="hidden" name="start-date" value="2020-04-06"> <input type="hidden" name="end-date" value="2021-04-05"> </form> <script>window.onload = function(){ document.mileage.submit(); };</script>
I am coding a browser game in php/mysql. the economy code needs to run at a regular interval. How can I get my code to run say, every 6/12/24 minutes? I heard of something called a cron job, but im not sure if it is going to be what I need. So I have a php script in public_html on my apache server, and it runs a global economy code for my browser game. If I open firefox and go to: http://localhost/Economy.php it runs the code, and it changes all the values in the database properly. How do I get that to run automatically, say every 6 minutes? I have windows so no cron jobs. I went to task scheduler and created a task which I thought would work, and it lists the task as running. But it gives me an error. Event Views: Code: [Select] Log Name: Microsoft-Windows-TaskScheduler/Operational Source: Microsoft-Windows-TaskScheduler Date: 9/28/2011 5:02:37 PM Event ID: 101 Task Category: Task Start Failed Level: Error Keywords: (1) User: SYSTEM Computer: Matt-PC Description: Task Scheduler failed to start "\Economy" task for user "Matt-PC\Matt". Additional Data: Error Value: 2147750687.Event Xml: Code: [Select] <Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event"> <System> <Provider Name="Microsoft-Windows-TaskScheduler" Guid="{DE7B24EA-73C8-4A09-985D-5BDADCFA9017}" /> <EventID>101</EventID> <Version>0</Version> <Level>2</Level> <Task>101</Task> <Opcode>101</Opcode> <Keywords>0x8000000000000001</Keywords> <TimeCreated SystemTime="2011-09-28T22:02:37.967669800Z" /> <EventRecordID>18</EventRecordID> <Correlation /> <Execution ProcessID="1012" ThreadID="1484" /> <Channel>Microsoft-Windows-TaskScheduler/Operational</Channel> <Computer>Matt-PC</Computer> <Security UserID="S-1-5-18" /> </System> <EventData Name="TaskStartFailedEvent"> <Data Name="TaskName">\Economy</Data> <Data Name="UserContext">Matt-PC\Matt</Data> <Data Name="ResultCode">2147750687</Data> </EventData> </Event> EDITed for code tags Hi all. In my database, i have a column recurring which is derived from a multiple option form field with values: Weekly, Bi-Monthly, Monthly, Quarterly, Half Yearly and Yearly. I want to have as next due the current date plus the recurring value. eg current date = 2014-11-24 recurring = monthly next due = current date + recurring (in the next due will be 2014-12-24) so i did: $stmt = $pdo->query("SELECT recurring, due_date FROM $table"); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $recur = $row['recurring']; $date_due = $row['due_date']; } $weekly = "Weekly"; $bi_monthly = "Bi-Monthly"; $monthly = "Monthly"; $quarterly = "Quarterly"; $half_yearly = "Half Yearly"; $yearly = "Yearly"; if(strcmp($recur, $weekly) == 0){ $recurs = "7 DAY"; }elseif(strcmp($recur, $bi_monthly) == 0){ $recurs = "14 DAY"; }elseif(strcmp($recur, $monthly) == 0){ $recurs = "1 MONTH"; }elseif(strcmp($recur, $quarterly) == 0){ $recurs = "3 MONTH"; }elseif(strcmp($recur, $half_yearly) == 0){ $recurs = "6 MONTH"; }elseif(strcmp($recur, $yearly) == 0){ $recurs = "1 YEAR"; } $stmt = $pdo->query("SELECT ADDDATE('$date_due', INTERVAL $recurs) as nex_due FROM $table"); $row = $stmt->fetch(PDO::FETCH_ASSOC); $nex_due = $row['nex_due']; $stmt = $pdo->prepare("SELECT * FROM $table ORDER BY trans_id DESC"); $stmt->execute(); $num_rows = $stmt->rowCount(); while($row = $stmt->fetch(PDO::FETCH_ASSOC)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['trans_ref']; echo "</td><td>"; echo $row['acct_num']; echo "</td><td>"; echo ucwords($row['payee']); echo "</td><td>"; echo ucwords($row['company']); echo "</td><td>"; echo $row['acct_no']; echo "</td><td>"; echo number_format($row['amt'],2); echo "</td><td>"; echo $row['purpose']; echo "</td><td>"; echo $row['recurring']; echo "</td><td>"; echo $row['due_date']; echo "</td><td>"; echo $nex_due; echo "</td><td>"; echo "<strong>".$row['status']."</strong>"; echo "</td><td>"; echo "<strong>".$row['pay_status']."</strong>"; echo "</td><td>"; } The problem is that it's giving me as next due the value of the first row even when the recurring is different! Does any one know how to run PHP script automatically at specific time interval in my local machine. I am using Windows 7. What about using the Task scheduler ? Please write to me in details how to give the path of the php page in Task Scheduler. HI,
I was trying do add a function to my script to stop each 10 seconds, using max_execution_time. Apparently is not working and most probably from the php.ini file, that I can t change because I want for the others script to run normally.
How can I write a function inside a php file to stop everything after 10 seconds. Or how can I make a script to stop after 100 processed items and start again after 30 seconds. I need to stop this file somehow. $processedItems++; guys, please help i have table with datas like speed of vehicle, position e.t.c from morning 8 a.m. to 8 p.m. I need to get these details, but after every 15 minutes i.e. after selecting datas at 8 a.m. it shd select datas @ 8.15 a.m. then 8.30 a.m. hw can i write a mysql query for this ? or a PHP approach is appreciated This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=331688.0 I've been researching online resources and seen a lot of code and functions for calculating an interval or difference between two date/time figures. What I'm trying to do is somewhat in reverse... I want to establish an interval to determine a past date/time to be used in a MySQL Query but just can't figure the critical part.
// STEP #1 = DEFINE THE DESIRED DATE/TIME DIFFERENCE INTERVAL DESIRED FOR QUERIES $timeinterval = '60'; // Interval is in MINUTES and can be changed as desired // STEP #2 = GET THE CURRENT LOCAL SERVER DATE/TIME // as YYYY-MM-DD HH:MN:SE $serverdatetime = date('Y-m-d H:i:s'); // My local Server Date & time // STEP #3 = CALCULATE THE ***PAST** (OLDER) DATE/TIME LIMIT BASED ON $timeinterval (Minutes) // as YYY-MM-DD HH:MN:SE $pastdatetime = [stuckinarut here] <- 60 MINUTES prior to current Server Date/Time // STEP #4 = MySQL QUERY (`submitted` column is auto-timestampped on record insertions) $sql="[columnsblahblah] FROM mydb WHERE `submitted` >= $pastdatetime";In a Perfect World, the MySQL Query would yield ONLY records with a `submitted` DATE/TIME equal to 60 Minutes (or less) PRIOR TO from the Current Server Time. Any assistance is appreciated! Thanks. -FreakingOUT When I log in to my website I am getting something like this in the URL... Code: [Select] http://local.debbie///////////articles/article.php?slug=postage-meters-can-save-you-money If I then navigate to other pages everything seems fine and I get a normal URL like this... Code: [Select] http://local.debbie/articles/consider-becoming-an-s-corporation What is going on?! Debbie Code: [Select] $getrest = mysql_query("SELECT * FROM block WHERE sid='$id' ORDER BY `id` DESC",$this->connect); while($row1 = mysql_fetch_assoc($getrest)) { $idz = $row1['id']; $getmore = mysql_query("SELECT * FROM block WHERE sid='$idz' ORDER BY `id` DESC",$this->connect); while ($row2 = mysql_fetch_assoc($getmore)) { } } you see i'm using the result from the first query in the where clause of the second query. This isn't good practice as what i'm trying to accomplish could lead me doing this up to ten times. what would be a better way to do this than while loops inside of while loops? example? can someone help to add new products and increase the quantity of the product when pressing the + button, but it works for [-] Code: [Select] <?php include "./php/connection.php"; function products () { $query = "SELECT * FROM product"; if (@mysql_num_rows($query)==0) { echo "There are no products to display!"; } else { while ($query_row = mysql_fetch_array($query)) { "<div class='product'>" . "<img class='img' src=". $row["Image"]." alt='phone' width='100' height='150' />" . "<p class='name'>".$row["Name"]."</p>". "<p class='price'>£". $row["Price"] ."</p>". "<p><a href='./cart.php?ProductID=". $row["ProductID"]."' class='myButton'>More Info</a></p>". "</div>"; } } } if (isset($_GET['ProductID'])) { $quantity = mysql_query('SELECT * FROM product WHERE ProductID = ' .$_GET["ProductID"]); while ($quantity_row = mysql_fetch_array($quantity)) { if ($quantity_row["Quantity"]!=@$_SESSION["cart_".$_GET["ProductID"]]) { @$_SESSION["cart_".$_GET["ProductID"]]+="1"; } } } if (isset($_GET["remove"])) { $_SESSION["cart_".$_GET["remove"]]--; header("Location: ./cart.php"); # Go back to the login pages } if (isset($_GET["delete"])) { $_SESSION["cart_".$_GET["delete"]]="0"; header("Location: ./cart.php"); # Go back to the login pages } function paypal_items() { $num = 0; foreach($_SESSION as $name => $value) { if ($value!=0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT ProductID, Manufacturer, model, Price FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $num++; echo '<input type="hidden" name="item_number_'.$num.'" value="'.$productid.'">'; echo '<input type="hidden" name="item_name_'.$num.'" value="'.$query_row['Name'].'">'; echo '<input type="hidden" name="amount_'.$num.'" value="'.$query_row['Price'].'">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="shpping_'.$num.'" value="0">'; echo '<input type="hidden" name="quantity_'.$num.'" value="'.$value.'">'; } } } } } function cart () { "<table id='producttable' border='1'>". "<tr>". "<td class='td top'>Delete</td>". "<td class='td top'>Product Name</td>". "<td class='td top'>Quantity</td>". "<td class='td top'>Price</td>". "<td class='td top'>Sub Total</td>". "</tr>"; foreach($_SESSION as $name => $value) { if ($value>0) { if (substr($name, 0, 5) == "cart_") { $productid = substr($name, 5, (strlen($name)-5)); $query = mysql_query('SELECT * FROM product WHERE ProductID =' .$productid); while ($query_row = @mysql_fetch_array($query)) { $sub = $query_row["Price"] * $value; "<tr>". "<td class='td'><a href='./cart.php?delete=".$productid."'> [Delete] </a></td>". "<td class='td'>".$query_row["Manufacturer"]."</td>". "<td class='td'>".$value."</td>". "<td class='td'><a href='./cart.php?ProductID=".$productid."'> [+] </a>£".$query_row["Price"]."<a href='./cart.php?remove=".$productid."'> [-] </a></td>". "<td class='td'>£".$sub."</td>". "</tr>"; } } @$total += $sub; } } if (@$total==0) { echo "<p>Your basket is empty</p>"; } else { echo @" Total: £" .$total; ?> <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_cart"> <input type="hidden" name="upload" value="1"> <input type="hidden" name="business" value="kamran193@hotmail.co.uk"> <?php paypal_items(); ?> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $total; ?>"> <input type="image" src="http://www.paypal.com/en_US/i/btn/x-click-but03.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!"> </form> <?php } echo "</table>"; } echo cart(); echo products(); ?> The code works but the title is repeated with each new set of data. I want the titles set up at the top and never repeating... No idea what is causing it.
$conn = new mysqli($servername, $username, $password, $dbname); $sql = "SELECT deadchar, level, class, killforumid, realm, date FROM pkdata ORDER BY deadchar DESC"; $result = $conn->query($sql); while($row = $result->fetch_assoc()) { $deadchar = $row['deadchar']; $level = $row['level']; $class = $row['class']; $killforumid = $row['killforumid']; $realm = $row['realm']; $date = $row['date']; $conn->close(); echo "<table><center><tr> <th> <font size=3 color=#070719>Victim</font> </th> <th> <font size=3 color=#070719>Level</font> </th> <th> <font size=3 color=#070719>Class</font> </th> <th> <font size=3 color=#070719>Killer</font> </th> <th> <font size=3 color=#070719>Realm</font> </th> <th> <font size=3 color=#070719>Date</font> </th> </tr></center>"; echo "<tr><center> <td><center>$deadchar</center></td> <td><center>$level</center></td> <td><center>$class</center></td> <td><center>$killforumid</center></td> <td><center>$realm</center></td> <td><center>$date</center></td> </tr>"; echo "</table>"; } ?> I'm trying to make it so that if the $row data is more than just "" (empty) then echo if not then run the scan on the next number. It just keeps repeating the values all the way through? Help? Thanks. function scan($random) { if ($random == 1) { $query = "SELECT * FROM users WHERE clicks > 20 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } else { scan(2); } } if ($random == 2) { $query = "SELECT * FROM users WHERE clicks > 10 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); if (isset($row['id'])) { echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } else { scan(3); } } if ($random == 3 OR 4 OR 5) { $query = "SELECT * FROM users WHERE clicks > 0 AND status='1' ORDER BY RAND() LIMIT 1"; $result = mysql_query($query); $row = mysql_fetch_assoc($result); echo '<html><body style="margin: 0px;"><a href="http://www.ryansocratous.com/banner/DELETE/click.php?u=' . $row['activation'] . '"><img src="http://www.ryansocratous.com/banner/DELETE/image.php?id=' . $row['id'] . '"></img></a></body></html>'; } } $random = rand(1, 5); scan($random); I don't even really know how to title it. I have this piece of code, i wrote. it works with wordpress api but honestly i don't think that matters much. what it does, is pick $ci number of categories, and then picks 2 posts from each category. it then assigns the image in/attached to that post to an array, to be used later. this all works fine, the problem is when it picks a post that doesn't have an image. right now, it can't tell that. writing in a bit to be able to tell whether there is an image or not should be easy. i'm thinking it can be as basic as file_exists or as complicated as parsing the post. the part i have the problem with - is how do i make it go back and pick another post/category when it comes up short? more than once? i want it to keep going back until it comes up with an image. i'd rather not expand the search any farther than necessary Code: [Select] <?php if ( false === ( $scroller = get_transient( $stransient ) ) ) { if (!is_array($scroller) || count($scroller)==0) { $args = array( 'type' => 'post', 'parent' => 18, 'exclude' => 63, 149, 278, 62 ); $companies = get_categories( $args ); while (count($companies) > $ci){unset($companies[array_rand($companies)]);} shuffle($companies);$truckco= array(); foreach ($companies as $company){ $argus = array('numberposts' => 2, 'orderby' => 'rand', 'post_type' => 'post', 'category' => $company->cat_ID ); $listings = get_posts($argus); foreach($listings as $tn=>$post) { $truckco[$company->slug]['truck_'. $tn]['image'] = get_the_image( array( 'image_scan' => true, 'format' => 'array', 'width' => '172', 'height' => '129' ) ); $truckco[$company->slug]['truck_'. $tn]['pid'] = $post->ID; } } ?> thank you Hi Folks, I am looping through a recordset ($result) containing different languages which I convert to values of html checkboxes, I want to compare the recordset values to array values ($arr_languages_spoken) and check the checkboxes that match. I think I am close, the code I have checks the right boxes but duplicates every value from the recordset so I have 2 of each checkbox, any help would be appreciated, thanks. MY CODE while($row = mysql_fetch_array($result)) { foreach ($arr_languages_spoken as $value) { if ($value == $row['language']) { echo "<input type=checkbox name=languages_spoken_1 value=".$row['language']." CHECKED/>".$row['language']." "; } else if ($value != $row['language']) { echo "<input type=checkbox name=languages_spoken_1 value=".$row['language']." />".$row['language']." "; } } } sorry if i have posted this in the wrong place, wasnt sure wether to post here or mysql. I have made a php calendar, and i am now wanting it to show if there is an event on that day and if so show it in a tool tip. the tool tip is populated by what is in the title="" of the link so i need my events to be shown in there. I have figured out how to show the event but now i am stuck on how to show all events if there is more than one one that day, how i have set it seems to only the second event, probably as the second variable overwrote the first variable. this is the code i have at the minute .............. $result = mysql_query("SELECT * FROM events WHERE day='$day_num' AND month='$fullmonth' AND year='$year'") or die(mysql_error()); $rows= mysql_num_rows($result); if ($rows !="false"){ while($rowout = mysql_fetch_array($result)) { $todayis = $rowout['day'] ."-". $rowout['month'] ."-". $rowout['year'] ."<br>"; $title= $rowout['event'] ."<br><br>";} $firstl = "<a href='' title='". $todayis . $title ."'>"; $lastl = "</a>";} else {$firstl = ""; $lastl = "";} then to display the day and links ................. Code: [Select] <td><? echo $firstl; ?><? print $day_num; ?><? echo $lastl; ?></td> could some one be so kind and help me write it so that it displays all events? here is a link to the calendar, incase its needed. http://www.scripttesting.htmlstig.com/calendar/index.php Many thanks Carl I have a simple problem but seem to be hitting a roadblock with fixing it. I am in the process of upgrading a site from PHP 5.6 to 7.0 (eventually to 7.2) I am seeing error notices like PHP Notice: Undefined index: productpage in ….. I know this it because the $_REQUEST can sometimes be empty depending on what data is passed back and when certain pages are loaded $productpage = mysqli_real_escape_string($con, $_REQUEST['productpage']); I also know that I could turn the error notice off or use isset to check $_REQUEST but I would prefer to use the ?? '' option to fix this issue. The problem is that when I add the ?? '' option to the above code the problem resolved itself but then moments later the same error on the same line reappeared in the error logs and I cant understand why. Can someone give me the correct example of where to place ?? '' in the above code so that I can rule out my potentially dodgy code as being the reason the error keeps reappearing.
I know I am probably complicating this but I am looking for a way to code a header and footer to the exterme top and extreme bottom of my pages. I have seen it before but I have no idea how to do it from scratch. But I ore or less want to be able to edit my header or footer one time and it work every where. Thanks in advance. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=310594.0 |