PHP - Php Daily Counter
Hi,
I can't think how to make a counter which goes up during the day, and when a new day starts it gets reset to 0. How can I do this without relying on visitors to the site to run the script? Cheers, Tom. Similar TutorialsIm looking for some example code for countdowns. I need to be able to count down to the same time each day for example 9PM each day. and be displayed as 5hr 8m 15s. When the timer runs out, then run some code then start again for the next day. what would be the best route to take for this? Thanks in advance I have a weird issue. I'm working on something where people will submit hours for a business. Originally it was free form text, but then I figured it may get messy with people doing M-F 9-5 then Monday through Friday, 9AM to 5PM, Mon-Fri, etc. So I switched to a bunch of inputs. It has each day then a select for from and one for to. Data is passed to the script as a form submission. Vars are named HF# and HT# (hours from, hours to and a 0-6 digit for Mon-Sun). I want to take the input and output a string as such:
Mon-Tue, 8:00 AM to 5:00 PM
Thu-Fri, 8:00 AM to 5:00 PM
Sat, 9:00 AM to 1:00 PM
Sun, 12:00 PM to 3:00 PM
I did this:
$formdata = array(); $formdata["hf0"] = "8:00 AM"; $formdata["ht0"] = "4:30 PM"; $formdata["hf1"] = "8:00 AM"; $formdata["ht1"] = "4:30 PM"; $formdata["hf2"] = ""; $formdata["ht2"] = ""; $formdata["hf3"] = "8:00 AM"; $formdata["ht3"] = "4:30 PM"; $formdata["hf4"] = "8:00 AM"; $formdata["ht4"] = "4:30 PM"; $formdata["hf5"] = "9:00 AM"; $formdata["ht5"] = "1:00 PM"; $formdata["hf6"] = "12:00 PM"; $formdata["ht6"] = "3:00 PM"; $WeekDays = array("Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"); $hours = ""; $sd = "Mon"; $ld = ""; $fr = $formdata["hf0"]; $to = $formdata["ht0"]; for ($x=0; $x<=6; $x++) { if (empty($sd) && !empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } if ($fr != $formdata["hf$x"] || $to != $formdata["ht$x"]) { $hours .= "$sd" . (($sd==$ld)?", ":" - $ld, ") . " $fr to $to<br/>"; if (!empty($formdata["hf$x"])) { $sd = $WeekDays[$x]; $fr = $formdata["hf$x"]; $to = $formdata["ht$x"]; } else { $sd = ""; } } $ld = $WeekDays[$x]; }($formdata was because I was tired of hitting back, changing the data then resubmitting) This kinda works, but it skips Sunday. There has got to be a better way to do this.. any ideas? Hi, This is my first post so dont kill me if i did somthing wrong. Im trying to make a simple php/javascript page that will display the time remaining in each period every day (we have 4 periods per day). I found a nice javascript library from www.hashemian.com and am using the example that he linked to to do multiple countdown timers on one page. The problem i am having is that the only way i can think of to make it so that it counts down to a dynamic date is to specify that date as a variable and then combine it with the string that specifys the rest of the date/time combo for the target date/time. The current live version is at smd75jr.com/test/index2.php The first timer is just a test that im using to make sure i havent completely broken it. THe second timer is the one im trying to troubleshoot, it is currently set for 11:59 PM EST "today". (see code below) Any help would be greatly appreciated!! This is my code: Code: [Select] <html> <head> <title>Multiple Countdown Clocks</title> </head> <body> <div id="clock1">[clock1]</div> <div id="clock2">[clock2]</div> </body> <script language="JavaScript"> StartCountDown("clock1","06/27/2012 9:33 PM -0400") StartCountDown("clock2","periodTest") TodaysDate() //var today = new Date() //var todayMonth = today.getMonth() + 1 //var todayDay = today.getDate() //var todayYear = today.getFullYear() //var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) var periodTest = (todayDate + " 11:59 PM -0400") var periodA1 = (todayDate + " 8:53 AM -0400") var periodA2 = (todayDate + " 10:26 AM -0400") var periodA31 = (todayDate + " 12:32 PM -0400") var periodLunch1 = (todayDate + " 11:00 AM -0400") var periodLunch2 = (todayDate + " 12:32 PM -0400") var periodA32 = (todayDate + " 11:59 AM -0400") var periodA4 = (todayDate + " 2:05 PM -0400") //function Periods(todayDate, periodA1, periodA2, periodA31, periodA32, periodA4, periodB1, periodB2, periodB31, periodB32, periodB4, periodLunch1, periodLunch2, periodSchoolStart, periodSchoolEnd) // { // var today = new Date() // var todayMonth = today.getMonth() + 1 // var todayDay = today.getDate() // var todayYear = today.getFullYear() // var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) // // var periodA1 = (todayDate + " 21:25 PM -0400") // } function TodaysDate(todayDate) { var today = new Date() var todayMonth = today.getMonth() + 1 var todayDay = today.getDate() var todayYear = today.getFullYear() var todayDate = (todayMonth + "/" + todayDay + "/" + todayYear) } /* Author: Robert Hashemian (http://www.hashemian.com/) Modified by: Munsifali Rashid (http://www.munit.co.uk/) Modified by: Tilesh Khatri */ function StartCountDown(myDiv,myTargetDate) { var dthen = new Date(myTargetDate); var dnow = new Date(); ddiff = new Date(dthen-dnow); gsecs = Math.floor(ddiff.valueOf()/1000); CountBack(myDiv,gsecs); } function Calcage(secs, num1, num2) { s = ((Math.floor(secs/num1))%num2).toString(); if (s.length < 2) { s = "0" + s; } return (s); } function CountBack(myDiv, secs) { var DisplayStr; var DisplayFormat = "%%D%% Days %%H%%:%%M%%:%%S%%"; DisplayStr = DisplayFormat.replace(/%%D%%/g, Calcage(secs,86400,100000)); DisplayStr = DisplayStr.replace(/%%H%%/g, Calcage(secs,3600,24)); DisplayStr = DisplayStr.replace(/%%M%%/g, Calcage(secs,60,60)); DisplayStr = DisplayStr.replace(/%%S%%/g, Calcage(secs,1,60)); if(secs > 0) { document.getElementById(myDiv).innerHTML = DisplayStr; setTimeout("CountBack('" + myDiv + "'," + (secs-1) + ");", 990); } else { document.getElementById(myDiv).innerHTML = "Period Over"; } } </script> </html> Hi... I planned to create db table daily. When day begin button clicked (text box has date Value) master dB can be copied,with the name of text box value ($date). If already day begin then it show day begin done. How can I do that. Please guide me
hi i have daily data table it's contain ID, Date, and Rain i need to make a new table but tendays period ,,, any clues ,,, will be very greatfull thanks a lot ,,, Hey everyone. Currently I have a site set up where I manually edit the txt file and the site pulls it from the text file and displays via php. I wanted to automate it by creating one file which contains the sunset times for the whole year, and have php determine todays date and then display the corresponding sunset time. Can someone please point me in the right direction? maybe it can be set up in a way where each line in the txt file represents the day of the year. ex: Jan 1 would be line 0, Feb 1's sunset time would be on line 31 etc. Thanks Hey all, Im currently working on a site which I save a cookie on users computer for 1 month as well a row in a table with the 1 month expiring date plus cookie id. What I would like to know is if theres a way to make the server check the table every day at say 12pm to see if any corresponding user cookies in each row have expired on that day as to remove them from the table to match the expiring cookie on the users computer? I would like not to have to rely on a user/admin accessing in to make a script run instead have something thats timed to go off automatically instead? Is there anyway of doing this? Thanks! I have a counter that updates the database automatically with out refreshing the page. However i was wondering if someone can give me some pointers on how i can keep it updating the database even after someone exits the page. Currently it updates the database every 2 seconds by increasing the number by 1..however i want to be able to do this even if the page i not loaded is there any way i can do this? how do I make $counter add one evertime it runs through the loop: Code: [Select] <?php // Query member data from the database and ready it for display $sql4 = mysql_query("SELECT * FROM labels where item_id='".$pid."'"); $num_rows = mysql_num_rows($sql4); echo $num_rows; while($row = mysql_fetch_array($sql4)){ $label =$row["label"]; $lid=$row['id']; $counter = 0; $counter = $counter + 1; print $counter . "<BR>"; ?> <select name="name<?php echo $counter; ?>"> <?php echo $label; ?>currently, it says counter is 1 everytime How can I say, if more than one of these if's happens do this.... Code: [Select] if ((!isset($_POST['state'])) && (($_POST['country'] != $r['country']) || ($_POST['city'] != $r['city']))) { $details = $_POST['city'].', '.$_POST['country']; update_user_actions(1, $details); } else if ((isset($_POST['state'], $_POST['city'])) && (($_POST['state'] != $r['state']) || ($_POST['city'] != $r['city']))) { $details = $_POST['city'].', '.$_POST['state']; update_user_actions(1, $details); } if ((isset($_POST['credentials'])) && ($_POST['credentials'] != $r['credentials'])) { $details = ''; update_user_actions(2, $details); } if ((isset($_POST['specialties'])) && ($_POST['specialties'] != $r['specialties'])) { $details = ''; update_user_actions(3, $details); } if ((isset($_POST['personalweb'])) && ($_POST['personalweb'] != $r['personalweb'])) { $details = $_POST['personalweb']; update_user_actions(4, $details); } Hi, After looking at some Javascript, I think it can only be done in PHP. I'm trying to get my script to add a "1" to an external file. It's made in Javascript, but I hope I can put some PHP in it, even if it's at the end. I'm working on a Safari Extension, and would like to know how many people use it. It's all made in a .HTML file, so I should be able to add a PHP script at the end. I hope this is clear, and I hope it can be done in PHP, or something at least. Thanks, Joseph Duffy Hey all. Have a question, im still learning but what i am trying to do is make the number 1 add 1 to itself and repeat in the loop so, 1 2, 3, 4, 5, 6 ect...What am i doing wrong. $result = mysql_query("SELECT * FROM comments WHERE quoteid = ".$_REQUEST['quoteid'].""); while($row=mysql_fetch_array($result)){ $date = $row[date]; $name = $row[name]; $email = $row[email]; $quoteid = $row[quoteid]; $comment = stripslashes($row[comment]); $commentid = $row[commentid]; $counter = 1; $counted = $counter++; $resultb = mysql_query("SELECT * FROM quotes WHERE quoteid= '$quoteid'") or die(mysql_error()); while($link=mysql_fetch_array($resultb)){ $artist = $link[artist]; $song = $link[song]; } echo'<table border="0" cellpadding="0" cellspacing="0"><tr> <td rowspan="3" align="center"><span class="commentNumber">'.$counted.'</span></td> hi there i am looking to build a button counter. and i am wondering of you could help. i want the button to +1 every time someone clicks it and also store the value so it can be used as a voucher code. can anyone help thanks Hey everyone! My upcoming site will host, potentiallly thousands of photographs, and i was wondering how to go about having a unique ip hit counter for EACH image. Obviously i dont want people refreshing the page to gain hits, therefore the hit counter will need to be dependent on the IP address. I have used google and found a few hit counters however i need to know how to make this practical as it seems like it will require a lot of databases! Thanks in advanced, Jimmy. <?php $counter_name = 'Counter.txt'; if (!file_exists($counter_name)) { $f = fopen($counter_name, "w"); fwrite($f,"0"); fclose($f); } $f = fopen($counter_name,"r"); $counterVal = fread($f, filesize($counter_name)); fclose($f); $counterVal++; $f = fopen($counter_name, "w"); fwrite($f, $counterVal); fclose($f); echo $counterVal; ?> This is click counter... Counter.txt only number... How to add a date? Counter / Date 1. 2021-02-28 19:50:47 2. 2021-02-23 17:57:11 etc
I know this should be easy but I cannot find right query to do this online. I simple want a counter of each result of my query. What is the proper way to query this.
For example
1 | Result 1
2 | Result 2
3 | Result 3
The one I found online did a weird grouping counter.
Thanks
I am trying to keep track of how many times a page is loaded for debugging. Here is my code but it doesn't seem to work?! Code: [Select] <?php isset($counter) ? $counter++ : $counter=1; ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Page A</title> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> </head> <body> <h3>Add a Comment</h3> <form action="Processing.php" method="post"> <fieldset> <!-- Comment --> <label>Comment:</label><br /> <textarea cols="50" rows="15"><?php echo $counter; ?></textarea> <br /> <!-- Submit Form --> <input type="submit" name="addComment" id="addComment" value="Add a Comment"/> </fieldset> </form> </body> </html> What am I doing wrong? Debbie Hello, I am wondering how to create a counter that has 5 digits and counts the results from a db field (not just the returned results but the numeric SUM of the values in the field) for display. i.e. if the sum of the field = 347 the counter would read 00347 I have created images for the numbers 0-9 and named them 0.png, 1.png, 2.png etc Also, I may have to sum a value that is stored in the db as serialized data (part of an array). If so how can I do that?? Ok, I'm not sure if this is even possible but I will try and explain what I want to do and then maybe someone will be able to point me in the right direction. Say I have a link to an external site like google for example, when that link is clicked the target (google in this case) will open in a new window and the page on my site remains the same, is it possible to insert data into a table in my database at the same time when the link was clicked like an id value for the link, effectively creating a count, which can be displayed somewhere on the page? I really hope that makes sense, any help would be much appreciated! Need some help on my result counter. I am using a search box to return data from my database i can get the result returned fine but i am having problems getting the total number of result returned. It only returns the number of results per page as i am using a paginate. Can some one point me in the right direction. The number count im using is below. Code: [Select] $num_rows = mysql_num_rows($sql); echo "$num_rows Results Found\n"; |