PHP - Show Content In The Future?
Hello!
I've managed to solve that the content is shown AFTER 6 hours when added to the SQL. But I want to add many things on the same (current time) but I don't want everything to pop up after 6 hours. I want a 6 hour delay on EACH content I add. How do I solve this? Here is my code: $six_hours_ago = time() - 21600; $sql = "SELECT * FROM Trailers WHERE Genre LIKE '%".$_GET['show']."%' AND time < '".$six_hours_ago."' ORDER BY `Trailers`.`sort` DESC"; insert.php $sql="INSERT INTO Trailers (Poster, Title, Year, Genre, IMDB, Actors, Plot, Youtube, time) VALUES ('".mysql_real_escape_string($_POST['Poster'])."','".mysql_real_escape_string($_POST['Title'])."','".$_POST['Year']."','".mysql_real_escape_string($_POST['Genre'])."','".$_POST['IMDB']."','".mysql_real_escape_string($_POST['Actors'])."','".mysql_real_escape_string($_POST['Plot'])."','".$_POST['Youtube']."', '".time()."')"; Thanks! Similar TutorialsThis topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321426.0 I'm having trouble getting this to work. Basically I'm trying to get everything in the red boxes in the below picture to not show. http://content.screencast.com/users/rockstarvisible/folders/Jing/media/4a50bc73-f3b9-4fbd-824b-e63413e85c06/2012-04-01_1540.png Here's a screen shot of the mysql table it's pulling from: http://content.screencast.com/users/rockstarvisible/folders/Jing/media/7ec2c110-25c3-45a5-a2e6-e6c3e029b41c/2012-04-01_1842.png Only the new dosage (on row 2 of the mysql table) should start showing from march 15th and on. However, currently both dosages are showing on March 15th and on. How do I change this? Here's my code: Code: [Select] //---------------------------------------------------drug dosage information //query database and grab dosages for different days of the week $query_drug_dosage = "SELECT * FROM `users_drug_dosage` WHERE users_drug_dosage.user_id =". $_SESSION['user_id']. " ORDER BY users_drug_dosage.id"; $query_run_drug_dosage = mysql_query($query_drug_dosage) or die(mysql_error()); //create id array $id_array = array(); while ($row_drug_dosage = mysql_fetch_assoc($query_run_drug_dosage)){ $id = $row_drug_dosage['id']; $sdd_day = $row_drug_dosage['calendar_day']; $sdd_month = $row_drug_dosage['calendar_month']; $sdd_year = $row_drug_dosage['calendar_year']; $mon_dd = $row_drug_dosage['mon_dd']; $tue_dd = $row_drug_dosage['tue_dd']; $wed_dd = $row_drug_dosage['wed_dd']; $thur_dd = $row_drug_dosage['thur_dd']; $fri_dd = $row_drug_dosage['fri_dd']; $sat_dd = $row_drug_dosage['sat_dd']; $sun_dd = $row_drug_dosage['sun_dd']; //if current date >= start date of dosage if (mktime(0, 0, 0, $month, $list_day, $year) >= mktime(0, 0, 0, $sdd_month, $sdd_day, $sdd_year) ) { //switch to find out what day of the week //the current date is and then pull the drug dosage //for that specific date switch (date("D", mktime(0, 0, 0, $month, $list_day, $year))) { case 'Mon': $drug_dosage = $mon_dd; break; case 'Tue': $drug_dosage = $tue_dd; break; case 'Wed': $drug_dosage = $wed_dd; break; case 'Thu': $drug_dosage = $thur_dd; break; case 'Fri': $drug_dosage = $fri_dd; break; case 'Sat': $drug_dosage = $sat_dd; break; case 'Sun': $drug_dosage = $sun_dd; break; } //store current id in the id array $id_array[] = $id; //find current id in id array //$key1 = array_search($id, $id_array); //echo 'key 1: ' . $key1; foreach ($id_array as $value){ if ($value == $row_drug_dosage['id']){ $calendar.= str_repeat('<div class="drugdosages">Dosage: '.$drug_dosage.' Mg</div>',1); } } //echo '<br/><br/>'; //print_r($id_array); //echo '<br/><br/>'; } } //---------------------------------------------------drug dosage information this is how I think I should do it, but i'm not sure at all: pull in all the dates for all the rows in the drug dosage table join them together by a / and join function and put into an array then do a for each loop for each value in the array explode the value and seperate by / and then use that for the $sdd_month, $sdd_day, $sdd_year Hi,
I want to set two expiration dates in a form. Prior to the fall deadline, options A, B, C are displayed. After the fall date has passed, only A and B will be displayed. This works beautifully:
<?php //SET THE TIME ZONE date_default_timezone_set('America/New_York'); //CREATE TIMESTAMP VARIABLES $current_ts = time(); $fall_deadline_ts = mktime(0,0,0,9,1,2014); $winter_deadline_ts = mktime(0,0,0,12,1,2014); //IF THE FALL DEADLINE HAS PASSED if($current_ts > $fall_deadline_ts) { echo "a, b"; } else { echo "a, b ,c"; } ?>How can I tweak this so that after the Winter deadline has ALSO passed, it will only display A, rather than A, B? Thanks! I want to show different content to different users from different states. So, if a visitor is visiting the website from California, I want to show California content. Likewise, if a user is visiting from any other State (say NY, Chicago, or anywhere), I want to show content relating to that State. Any suggestions? Thanks. I've been working on developing a CMS blog and now I'm trying to create a slideshow wit Bootstrap Carousel on the homepage to present the dynamic content (images + text) using the data from table 'posts'. I tested this code, and it only presents one post. I mean, It's not possible to go to the next slide. I want to show all the posts on the slides. *The DB connection is already on the includes. The connection was written on a small file called DB.php Home.php <header> <div id="carouselExampleIndicators" class="carousel slide" data-ride="carousel"> <ol class="carousel-indicators"> <li data-target="#carouselExampleIndicators" data-slide-to="0" class="active"></li> <li data-target="#carouselExampleIndicators" data-slide-to="1"></li> <li data-target="#carouselExampleIndicators" data-slide-to="2"></li> </ol> <div class="carousel-inner" role="listbox"> <?php // The default SQL query $sql = "SELECT * FROM posts ORDER BY id desc"; $stmt = $ConnectingDB->query($sql); while ($DataRows = $stmt->fetch()) { $Id = $DataRows["id"]; $PostTitle = $DataRows["title"]; $Image = $DataRows["image"]; $PostText = $DataRows["post"]; ?> <!-- Slide --> <div class="carousel-item active" style="background-image: url('uploads/<?php echo $Image; ?>')"> <div class="carousel-caption"> <div class="card-body black"> <h3 class="large-mistral-white"><?php echo $PostTitle; ?></h3> <p class="small-times-white"><?php echo $PostText; ?></p> </div> </div> </div> <?php } ?> </div> <a class="carousel-control-prev" href="#carouselExampleIndicators" role="button" data-slide="prev"> <span class="carousel-control-prev-icon" aria-hidden="true"></span> <span class="sr-only">Previous</span> </a> <a class="carousel-control-next" href="#carouselExampleIndicators" role="button" data-slide="next"> <span class="carousel-control-next-icon" aria-hidden="true"></span> <span class="sr-only">Next</span> </a> </div> </header> DB.php <?php $DSN='mysql:host = localhost; dbname=everybody_blog'; $ConnectingDB = new PDO($DSN,'root',''); ?>
Evening All, How would I go about selecting a future date based on a date? What I want to achieve is to take todays date, add ten days to it and then store it as the month end following that date. For example 19th Nov + 10days = 29th November = 31st Dec Many thanks for any pointers! Hello. I wanted to make a table where the dates are listed going forward at least one year. So, at least 365 records, but each date should be unique and should start from today until one year from now. I tried to make a date column and make it a primary key.
However, an error comes up when I try to insert more than one record. This is for a calendar that I'm building so I need the dates listed one year in advance and it would be great if new dates could be added without my having to manually go in there and insert new records to stick to my 1 year in advance rule.
For that aspect I might have to create a php script where the date records are added every time a user logs in, to make sure they are up to date, but anyways what I don't understand is why I can't make a table with 1 year of date records in advance, where each row has a unique date starting from today.
Hi everyone, I'm writing a science fiction wordpress blog set 10 years into the future. I basically need all posts to display as if they are 10 years from now. Eg. posts needs to display as: February 7, 2021 instead of February 7, 2011 This will be for every post that I write. How can I automatically add 10 years to every post date? (And where would I put that code?) Currently, the wordpress php is calling the date with `<?php the_time(__('M j, Y')) ?>` I realise it's a bit of an odd request, but it's necessary for this particular project. I know it's possible - but I'm brand new to php and am not sure how. =) I hope someone out there can help. It would be very much appreciated. many thanks in advance Luke Hi, I want to calculate the future month, i have used following code to calculate the date $date = date('Y-m-d',strtotime(date("Y-m-d", strtotime('2010-01-31')) . " +3 month")); It gives me 2010-03-03 But i need to get 2010-02-28 OR just month is enough like 2010-02 Thank you Nikhil What are your feelings regarding Linux desktop distros, and their ability to break through to mainstream usage? I started using Ubuntu about 6 or 7 years ago, and have fooled around with some other distros, but at least for me Ubuntu always seemed the best. I've got my 65 year old mom using it, and my 11 year old son playing with Kubuntu (and learning python!). I don't really consider us normal though; normal being almost too dumb to do more than check email and get on the internet.
I've managed to fully switch over to Ubuntu on all of my computers, with the exception of running Windows in a VM for Photoshop and Illustrator. Since I don't use those programs every day, there are a lot of days where I don't see Windows. I never really had a problem with Windows, except for Windows 3.1 was kind of a drag. Getting on the internet on a 56K modem on Windows 95 wasn't any fun either, but that wasn't Windows' fault. I never had the crashes and bad experiences people like to claim makes Windows suck. My main reason for abandoning Windows is just to be more involved with Linux, and hopefully reach Linux guru status someday.
I really never liked Macs. I bought one 3 or 4 years ago, and it just felt like I was paying a lot of money for a glorified (and over-hyped) linux distro. I really never liked the feel of the Finder. At the time there was no awesome text editor, and I bought a couple just to test out what I could find. Unlike Windows and Linux, it seemed like nothing is free in the Mac world. I eventually gave the Mac away. We couldn't be friends.
I'd really like to see Linux become the dominant OS. It's exciting to see how far Ubuntu has come in the years that I've used it, and I evangelize for Linux/Ubuntu quite a bit. Even still, it can sometimes seem that I am a stranger in a strange world. Do you think we can count on Linux being a bigger part of mainstream computing? One of the problems I see is that there are so many distros that a person investigating Linux may be a little overwhelmed. What do you think is keeping the masses from using Linux desktops?
Hi, I am using this function to output a list of dates for every friday over the next 12months. This is working fine. Code: [Select] [php] //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 1; $i <= $nbrweek; $i++) { // 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin=strtotime('this Friday'); $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Insert //$date1=date('Y-m-d', $date_begin); for($i = 1; $i <= $nbrweek; $i++) { //$date=$result[$i]; echo $result[$i]."<br/>"; } [/php] My problem is that when I alter the code to try and get the date for every second Friday for the next year the script freezes. Code: [Select] [php] //function function nextWeeksDay($date_begin,$nbrweek) { $nextweek=array(); for($i = 2; $i <= $nbrweek; $i+2) { // 52 week in one year of course $nextweek[$i]=date('Y-m-d', strtotime('+'.$i.' week',$date_begin)); } return $nextweek; } /// end function /// example of a select date // var $date_begin=strtotime('this Friday'); $nbrweek=52; // call function $result=nextWeeksDay($date_begin,$nbrweek); // Insert //$date1=date('Y-m-d', $date_begin); for($i = 2; $i <= $nbrweek; $i+2) { //$date=$result[$i]; echo $result[$i]."<br/>"; } [/php] I really don't understand why?? Does anyone know why? Thanks I was wondering if there was a way to have the MAX function NOT return a Date that is more than 2 days into the future (from the current day)? If there is a Date that is more than 2 days into the future I would like to return the one closest to the current day. Here is the code I have: Code: [Select] <?php mysql_connect("local", "xxx", "xxx") or die(mysql_error()); mysql_select_db("pricelink") or die(mysql_error()); // Get a specific result from the "ft9_fuel_tax_price_lines" table $query ="SELECT ItemNumber,TableCode,Cost, MAX(`Date`) as `max_date`, MAX(`Time`) as 'max_time' FROM `ft9_fuel_tax_price_lines` GROUP BY `ItemNumber`,`TableCode`"; $result = mysql_query($query) or die(mysql_error()); echo "<table border='1'>"; echo "<tr> <th>ItemNumber</th> <th>TableCode</th> <th>Date</th> <th>Time</th> <th>Cost</th> </tr>"; // keeps getting the next row until there are no more to get while($row=mysql_fetch_array($result)) { // Print out the contents of each row into a table echo "<tr><td>"; echo $row['ItemNumber']; echo "</td><td>"; echo $row['TableCode']; echo "</td><td>"; echo $row['max_date']; echo "</td><td>"; echo $row['max_time']; echo "</td><td>"; echo $row['Cost']; echo "</td></tr>"; } echo "</table>"; ?> Any help would be appreciated. Thanks! Hello, I am having trouble setting a cookie with a future expiration. I am using PHP Version 5.1.6. Here is my code: $expire = time() + 60*60*24*30; // 30 days setcookie("TestCookie",$value, $expire); The cookie gets set, however, the cookie is not persistent and expires when I close my browser. This should not be the case but should expire in 30 days. The time() is correct on the server. Here is the raw http headers: Status: HTTP/1.1 200 OK Date: Sat, 26 Mar 2011 15:12:27 GMT Server: Apache/2.2.3 (CentOS) X-Powered-By: PHP/5.1.6 Set-Cookie: TestCookie=my+cookie+value; expires=Mon, 25-Apr-2011 15:12:27 GMT Content-Length: 126 Connection: close Content-Type: text/html; charset=UTF-8 However, when I open Firefox or Chrome they both say that the cookie will expire when I close the browser. I know that my browser is accepting cookies properly because I see other cookies from other websites in the cookie list that expire with future dates. I've tried setting a cookie in the future with javascript and it works fine, like the following: $jsExpire = date("D, j M Y H:i:s e", $expire); echo " <script> <!--// document.cookie = 'jscookie=testcookie; expires=$jsExpire; path=/' //--></script> "; However, when still trying to set the cookie (before headers are sent which is how php operates), php fails to set the cookie properly. Is there any kind of setting in php ini that could effect cookie expiration dates? Obviously it's not a browser problem since I can set cookies correctly with javascript but not php. I even tried sending cookie with header() like this and it doesn't set in the futu header("Set-Cookie: TestCookie=my+cookie+value; expires=Mon, 25-Apr-2011 17:26:45 GMT; path=/; domain=.mydomain.com"); Any help appreciated. Hi,
I have made a database linked with php that I use a html form for. The HTML form requests a particular date to retrieve, and the php form it is linked to then retrieves data from the MySQL database from that date.
My question is: I want there to be a restriction so that the retrieval can only be for dates before the present date (and certainly not any date in the future).
e.g. if it is 6th July 2020, then the database can only retrieve from the 5th July 2020 and before. (7th July 2020 onwards also is not allowed.) Is there a way I can do it? Anyone who can guide me to a particular code function or something of that sort - I would be deeply grateful as my searches have not come up fruitful. Edited July 10, 2020 by samanjclarity Hello guys,
I require a suggestion about how shall I proceed as when I am about to set a goal for my future in programming world, Just so that you could suggest me better, I urge you to please read about a little background history of mine. And please stay neutral in regards of language, dont say PHP because you are a PHP developer and dont say Java because you are a Java developer.
Thanks.
I stepped into programming when I was in school (below A-levels at 14, now I am 29) and I started to bunk school and went to internet cafe and would sit there reading sources of HTML pages in year 2000. I would observe their programming styles, I would learn about the tags they used and then search internet (it was IE6 then and Yahoo searching at its peak) so I could learn about it.
Years passed, and having my family related to medical professions, I took admission in Pharmacy in University and quit after 2 years and entered working class. My development slowed down but passion always stayed the same.
Now I am in Spain and working as a technician of mobile repairing with a company, but I still have this passion of programming and when I learn that etc etc friend of mine now is working with CISCO in Germany, now is working as a game developer in America, I become really sad. I could have been one of those. But the fact is that I am not. So I restarted again with development and started learning PHP on my work desk using online resources and tutorials and asking silly questions.
Nothing I could become but an obsolete language programmer with a mess.
Now when I havent been able to become someone, till now, I still have passion and I want to be somewhere.
-----------------------------
I am confused for some days now, shall I continue with PHP (apart from the fact that i am a MYSQL learner, haven't learned PDO or MYSQLi till now) or shall I step into Java learning, using the online resources ofCourse, but if I step into Java, It will be a fresh start and I will be able to organize it better on my way with guidance of professionals like you.
The Things confusing me: (as I am imagining in my mind)
PHP:
A great web development language being used on billions of website, have an extraodinary support, well documented, World is moving online, so future is e-commerce in these terms.
JAVA:
Feels a giant to me, and impresses me at times, a myth to me, I am speaking illogical I know, and after android, I see a great potential in this language.
Edited by Digitizer, 28 August 2014 - 06:03 PM. Hi, I am trying to get the number of days between the current date and a date in the future specified by column 'end_date'. The code I have seems to be working but it displays the number of days as a negative number, how do I change this to be a positive number? I have tried simply changing $days = $now - $end_date; to $days = $end_date - $now; but that doesn't work as I thought it would! Thanks in advance.. Code: [Select] $now = time(); $end_date = strtotime($row['end_date']); $days = $now - $end_date; echo floor($days/(60*60*24)); I was trying to prevent bottlenecks when sending emails, and the below post was the solution. Similar predicament now, but I also need to generate some images first so they may be attached to the emails and the images are generated by a fairly slow command line program that emulates a browser. Multiple emails might or might need the same image so I plan on creating all the images before queuing the emails. I believe the futureTick approach executes each tick in series as blocking, but doesn't attempt to execute all of them at once so it doesn't impact the rest of the application. Promises, however, appear to be more about a structured process for managing callback functions. As such, the futureTick approach would likely be best for tasks requiring much PHP processing, and promises are more suitable for tasks which PHP is just waiting for a response from some other service. True? Would one ever want to attempt to use both approaches? Seems like it might make sense if the code within a promise was PHP intensive to break it down into multiple futureTick tasks, but not not feed promises into the futureTick as promises are "kind of" non-blocking, true? To execute the CLI image program, considering https://github.com/clue/reactphp-shell. Or do you think plan old exec() would be applicable? For using promises, would it just look something like the following? $deferred = new React\Promise\Deferred(); $deferred->promise() ->then(function ($rs) { // create the first image })->then(function ($rs) { // create the second image })->then(function ($rs) { // create the last image })->then(function ($rs) { // send the first email })->then(function ($rs) { // send the second email })->then(function ($rs) { // send the last email }); $deferred->resolve($nothing?); Or maybe something like the following? I would be amazed if it works as is, but hopefully is on the right track. $deferred = new React\Promise\Deferred(); $deferred->promise() ->then(function ($rs) { // Create images // See https://github.com/clue/reactphp-shell $launcher = new ProcessLauncher($loop); $shell = $launcher->createDeferredShell('bash'); $shell ->execute('create the first image') ->execute('create the second image') ->execute('create the lst image') ->then(function ($rs) use($loop) { // Send emails // Just showing this way but will actually use kicken's EmailQueue solution $loop->futureTick(function () { // send the first email }); $loop->futureTick(function () { // send the second email }); $loop->futureTick(function () { // send the last email }); }); }); $deferred->resolve($someQueueOfImages?);
I want to set a never expire date, so I figured I would set the date 99 years into the future. No dice. After trial and error, it appears you can only make it 25 years into futu date("Y-m-d",strtotime("+25 years")); I wonder if it is the absolute date, or the number 25. If it is the maximum date (i.e. nothing after 2035) then I will have a problem with this code next year! My query is a fixtures list for my local sports team- There seems little point including fixtures from the past as they are in a results query anyway. I'm ordering by date (see below) but how can I remove the ones already past? $query = "SELECT * FROM fix10 ORDER BY Date"; TIA Nick I want to show a cookie of a referral's username on a sign up page. The link is like this, www.mysite.com/signup?ref=johnsmith. The cookie doesn't show if I go to that url page. But it does show up once I reload the page. So I'm wondering if it's possible to show the cookie the first time around, instead of reloading the page? Here is my code. // This is in the header $url_ref_name = (!empty($_GET['ref']) ? $_GET['ref'] : null); if(!empty($url_ref_name)) { $number_of_days = 365; $date_of_expiry = time() + 60 * 60 * 24 * $number_of_days; setcookie( "ref", $url_ref_name, $date_of_expiry,"/"); } else if(empty($url_ref_name)) { if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; } } else {} // This is for the sign up form if(isset($_COOKIE['ref'])) { $user_cookie = $_COOKIE['ref']; ?> <fieldset> <label>Referred By</label> <div id="ref-one"><span><?php if(!empty($user_cookie)){echo $user_cookie;} ?></span></div> <input type="hidden" name="ref" value="<?php if(!empty($user_cookie)){echo $user_cookie;} ?>" maxlength="20" placeholder="Referrer's username" readonly onfocus="this.removeAttribute('readonly');" /> </fieldset> <?php }
|