PHP - Date Since Article Was Posted Ie. Yesterday, Or 14 Hours Ago
hi there,
basically in my database i have DATETIME for when an article was posted, using this, I'd like to make it possible for viewers of the article to see when it was posted in a "Posted Today", "Posted Yesterday" or Posted 23 hours ago" format. If it was posted longer ago than yesterday, then I would like it to just be the normal date. I know how to work out if it was posted today, just through: $date = date('j F', strtotime($rows['date'])); $today=date('j F'); but not sure how to do the hours. thanks! Similar TutorialsI'm building an article system, what im trying to do is when a user choose the article to be published tomorrow to able to. Write today the article but the system will show it from tomorrow Code: [Select] $gettoday = date("Y:m:d"); $query = "SELECT * FROM tblnews WHERE MainArticle = 1 AND NewsDate = '".$gettoday."' ORDER BY `Id` DESC LIMIT 1"; $result = mysql_query($query); This is my code, but when i use this and the article is not posted for today is not showing anything.. any suggestions please? Thank you Im using $time = date('Y-m-d H:i:s'); How can I make a new variable that adds 4 hours on the $time output. Hi, I have a database where I store times with the Now(); function. What I want is: When the viewer looks at the post, instead of it saying: Posted: 2010-11-14 19:08:14, I want it to say posted: x hours ago, Posted: x days ago, etc. Any help with this would be appreciated! I have the below code wish I wish to add 12 hours to: Code: [Select] $today = date('D', mktime(0,0,0,date('m'),date('d')+0,date('Y'))); anyone to show how I add 12 hours? I want to users can setup time difference in hours, but I dont know how to solve this. Here is script for localtime: $date_format = 'd.m.Y H:i'; $timezone = new DateTimeZone("Europe/Berlin"); $date = new DateTime(); $date->setTimezone($timezone); echo "<div align='right'> Today is " . $date->format("$date_format") . "</div>"; Now I have $user_time in config and users can change this value (example: +1 hours, -3 hours etc...). Users time settings ($user_time) are saved in database. How to display time based on user_time (ex. $date->format("$date_format") ) to display message like this: Today is 16.09.2010 18 (+$user_time) : 40 Hi All, I have a 'Newspaper' in a game I'm coding. My plan was to have an edition every week and on average 15 articles a week. I would set this out like so. . Code: [Select] <? $select_paper=mysql_query("SELECT * FROM paper WHERE id=1"); while($the=mysql_fetch_object($select_paper)){ ?> <table width=100% class=table> <tr> <td> <td width=50% style=border: none; background-color: transparent; valign=top> <table border=1 cellpadding=0 cellspacing=0 bordercolor=#000000 class='main' align=center> <tr> <td width=500 class='tableheading'><?php echo "$the->title"; ?><center> </center></td> </tr> <tr > <td class="profilerow" align=left><center><?php echo "$the->news"; ?> </td> </tr> <tr > <td class="subtableheader" align=left><center><?php echo "Article By $the->by - $the->date"; ?> </td> </tr> </table> <br> </td> <? } ?> With that repeated for 15 articles per edition. BUT! To save time, space and complication, I would rather do it using something like this. . Code: [Select] $select = mysql_query("SELECT * FROM paper WHERE edition=1 ORDER by id ASC"); $num = mysql_num_rows($select); Could someone tell me how to intergrate this with the layout tables as show in code #1? Thanks! I have manage to create my own script that add news article, however, I would like to add a comment form below the news article. How can I relate the news and the comments? also, when I delete the articles, it should also delete the comments in mysql. Your help is highly appreciated! I have a database in which i store articles that contain all type of special characters including slashes, single quotes, double quote etc. Previously it was working fine, but now after the updating the xampp, things are not going as usual. I insert are articles using following code $query = "INSERT INTO `articles` (`source`, `heading`, `description`, `catagory`, `detail`, `date`, `timestamp`) values ('$source', '$heading', '$desc', '$catagory', '$detail', '$date', '$timestamp')"; Error I am getting is Error Running query 1You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's economy and emphasized that international community should provide its complet' at line 2 Can anybody tell me whats wrong with my script? Hello, can you help me on my news article? I would like to be able to add photo on the article. Below is my codes Quote ======= html ======= <?php include_once ('post_news.php'); ?> <form Action="add_news.php" Method="post"> <input name="postdate" type="text" id="postdate"> <input name="title" type="text" id="title"> <textarea name="newstext" cols="60" rows="15" id="newstext"></textarea> <input type="submit" name="submit" value="Submit"> <input type="reset" name="reset" value="Reset"> </form> ============== php - post_news.php ============== <?php ini_set ('display_errors', 1); error_reporting (E_ALL & ~E_NOTICE); if (isset ($_POST['submit'])) { require_once ('inc/dbConfig.php'); // Define the query. $query = "INSERT INTO news (id, postdate, title, newstext) VALUES (0,'{$_POST['postdate']}', '{$_POST['title']}','{$_POST['newstext']}')"; // Execute the query. if (@mysql_query ($query)) { print "<p>Data has been added.</p>"; } else { print "<p>Could add the entry because: <b>" . mysql_error() . "</b>. The query was $query.</p>"; } mysql_close(); } ?> ===== db structure ====== id int(10) unsigned NOT NULL auto_increment, postdate timestamp(14), title varchar(50) NOT NULL, newstext text NOT NULL, PRIMARY KEY (id), KEY postdate (postdate) Hope you guys can help me. Thanks! I am developing a CMS with articles and categories. I am making a feature for the admin panel that shows all the categories. In the table, I would like to include each category's latest article. My traditional method is to select just the categories in one query, loop through the results, and then inside the category loop have a query that gets the information on the latest article... So something like...
$query = " SELECT category_id, title, description FROM categories ORDER BY title ASC"; if($query = mysql_query($query)){ while($cat=mysql_fetch_assoc($query)){ $query_article = " SELECT article_id, category_id, title FROM articles WHERE category_id = ".$cat['category_id']." ORDER BY article_id DESC LIMIT 1"; $last = mysql_fetch_assoc($query_article); } }How could I use joins and/or subqueries to achieve my goal of combining these two queries into one? I have come up with a query which is below: SELECT c.category_id, c.title, c.description, a.article_id, a.category_id, a.title, COUNT(a.article_id) AS total_articles FROM article_categories AS c LEFT JOIN articles AS l ON ( SELECT article_id AS article_id, category_id, title AS article_title FROM articles AS l WHERE l.category_id = c.category_id ORDER BY l.article_id DESC LIMIT 1) LEFT JOIN articles AS a ON (c.category_id = a.category_id) GROUP BY c.category_id ORDER BY c.title ASCWhen I use the above query, I get an error saying "Operand should contain 1 column(s)" I would also like to add something that counts the total number of articles in the category. Thanks for your time! I'm feeling a little overwhelmed/burned-out/confused... I have a page "article_index.php" that contains a summary of each article plus a link to it, e.g. Code: [Select] <a href="<?php echo WEB_ROOT; ?>articles/postage-meters-save-you-money"> When you click on a link, it goes to "article.php" and uses a mod_rewrite to transform the "pretty URL" to regular URL that "article.php" can use to query the correct article from my database. ----- Here is what I need help with... When a user is on a given article page, I want to sto - ReturnToPath - ArticleID in the SESSION. I am drawing a blank on how to get the "ArticleID" when a user is on a give page?! Hope you guys follow me?! Debbie Hello, I am trying to create article directory for learning PHP MySql and i want to write a script for recording number of views for an article and store it in Database. Can anyone please direct me to a nice simple tutorial or help me with the steps or algorithm? Suppose the link for an article is http://www.domain.com/article.php?id=123 Do i need to put extra variables and create a tracking PHP file for it? This topic has been moved to Apache HTTP Server. http://www.phpfreaks.com/forums/index.php?topic=322454.0 I have a status system, built with ajax, and I need to get the unique id that the database assigns to the post and return it in the results that are appended to the page via javascript, however I'm not sure how the bessst way would be to do this? I have been doing this: ///variables that are sent to the database $session = $_COOKIE['id']; $uid = $_POST['id']; $post = $_POST['post']; $date = mktime(); //way I have got the unique id of this post $query = mysql_fetch_assoc(mysql_query("SELECT * FROM posts WHERE from_id='$session' AND to_id='$uid' AND post='$post' AND date='$date'")); $id = $query['id']; Although that does work, It feels like it might not always be accurate. When I submit my form the variables are sent to the url in my address bar and not to the php post page (resersend.php). Here is the pertinent html page code (index.html)... Code: [Select] <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> function showMonth(str) { if (str=="") { document.getElementById("txtHint").innerHTML=""; return; } if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari xmlhttp=new XMLHttpRequest(); } else {// code for IE6, IE5 xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); } xmlhttp.onreadystatechange=function() { if (xmlhttp.readyState==4 && xmlhttp.status==200) { document.getElementById("txtHint").innerHTML=xmlhttp.responseText; } } xmlhttp.open("GET","reserv.php?q="+str,true); xmlhttp.send(); } </script> </head> <body> <form> <p><font face="arial" size="2" color="#336600">Reservation month:</font> <select name="months" onchange="showMonth(this.value)"> <option value="" selected="selected">Choose One</option> <option value="May 2011">May 2011</option> <option value="June 2011">June 2011</option> <option value="July 2011">July 2011</option> <option value="August 2011">August 2011</option> <option value="September 2011">September 2011</option> <option value="October 2011">October 2011</option> <option value="November 2011">November 2011</option> <option value="December 2011">December 2011</option> <option value="January 2012">January 2012</option> <option value="February 2012">February 2012</option> <option value="March 2012">March 2012</option> <option value="April 2012">April 2012</option> </select> </form></p> </body> </html> And here is the php code from the page (reserv.php) that works with the above html page... Code: [Select] <?php $q=$_GET["q"]; $con = mysql_connect('My_host', 'my_user', 'my_password'); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("my_db", $con); $sql="SELECT * FROM daterange WHERE DEND > DATE(NOW()) AND STATUS='A' AND MONTH = '".$q."' ORDER BY RID, DATE, SITE"; $result = mysql_query($sql); // Determine the number of reservation dates $number = mysql_numrows($result); // Create drop-down menu of reservation dates print "<font size=\"3\" face=\"Arial\"><b>Select Your Reservation:</b><br> <form action=\"resersend.php\" method=\"post\"> <select name=\"RID\"> <option value=\"\">Choose One</option>"; for ($i=0; $i<$number; $i++) { $RID = mysql_result($result,$i,"RID"); $DATE = mysql_result($result,$i,"DATE"); $SITE = mysql_result($result,$i, "SITE"); $PRICE = mysql_result($result,$i, "PRICE"); print "<option value=\"$RID\">$DATE, $SITE, $PRICE</option>"; } print "</select><p align=left><label><font size=\"3\" face=\"Arial\">First Name: <input type=\"text\" name=\"FNAME\" size=\"50\" maxlength=\"50\" tabindex=\"1\"<br>"; print "<p align=left><label>Last Name: <input type=\"text\" name=\"LNAME\" size=\"50\" maxlength=\"50\" tabindex=\"2\"<br>"; print "<p align=left><label>Address Line 1: <input type=\"text\" name=\"ADDR1\" size=\"50\" maxlength=\"50\" tabindex=\"3\"<br>"; print "<p align=left><label>Address Line 2: <input type=\"text\" name=\"ADDR2\" size=\"50\" maxlength=\"50\" tabindex=\"4\"<br>"; print "<p align=left><label>City: <input type=\"text\" name=\"CITY\" size=\"50\" maxlength=\"50\" tabindex=\"5\"<br>"; print "<p align=left><label>State (abbrev.): <input type=\"text\" name=\"STATE\" size=\"2\" maxlength=\"2\" tabindex=\"6\"<br>"; print "<p align=left><label>Zip Code: <input type=\"text\" name=\"ZIP\" size=\"5\" maxlength=\"5\" tabindex=\"7\"<br>"; print "<p align=left><label>Contact Phone Number: (<input type=\"text\" name=\"PHONE1\" size=\"3\" maxlength=\"3\" tabindex=\"8\""; print "<label>)<input type=\"text\" name=\"PHONE2\" size=\"3\" maxlength=\"3\" tabindex=\"9\""; print "<label>-<input type=\"text\" name=\"PHONE3\" size=\"4\" maxlength=\"4\" tabindex=\"10\"<br>"; print "<p align=left><label>Email: <input type=\"text\" name=\"EMAIL\" size=\"50\" maxlength=\"50\" tabindex=\"11\"<br>"; print "<p align=left><input type=\"submit\" value=\"Book Now!\" name=\"submit\">"; print "<input type=\"reset\" value=\"reset\" name=\"reset\"></form>"; // Close the database connection mysql_close($con); ?> I am sure this is easy, but any help would be greatly appreciated. Thanks. Hi Friends, I have form in that i am sending some values using POST method. But i cant able to get values using $_POST['var'] or $_REQEUST['var'] Data is not coming in IE6, But it is coming in firefox and other browsers even in IE8. What may be problem? any settings i have to make for IE6. ? Any suggestions I need to echo back the users drop down selection. How can I do this without storing the value? Code: [Select] $isset = $_POST['industry']; foreach ($industries as $industry) { if (isset($isset) && $industry['industry_id'] == $isset) { echo "<option value=\"{$industry['industry_id'] }\" selected=\"selected\">${industry['industry']}</option>\n"; } else { echo "<option value=\"{$industry['industry_id'] }\">${industry['industry']}</option>\n"; } } i need to submit 1 article (3 input fields: title, category, description), to multiple sites. it must be done with 1 click. one more thing... each site to which i have to submit has different input names, but are the same 3, also 1 is for title 1 for category and 1 for description. |