john010117 Posted January 6, 2007 Share Posted January 6, 2007 I have read the stickies/announcements, and they [i]did[/i] say how to do this. But they didn't explain it further, and the link they've posted for further reading doesn't work. So, here's my problem.On my index page, I have a news section. No php needed for that. But I want the website to automatically archive old news when the next day comes. So, if I type in index.php, it should automatically get the news for today (but I'm typing up the news). Sorry if this doesn't make sense. I want to have something [url=http://halo.bungie.org]like this[/url] (see the date at the top and the arrows?). How do you do that? Quote Link to comment Share on other sites More sharing options...
Mutley Posted January 6, 2007 Share Posted January 6, 2007 You will need to have a database field for the date.Then, you simple SELECT only the news items in the database on that day. In the URL you have something like www.mysite.com/index.php?newsdate=123[code=php:0]$date = $_GET['newsdate'];// This looks at the URL for the value "?newsdate=" $sql = "SELECT * "; $sql .= "FROM mynews "; $sql .= "WHERE datecreated = '$date' ";// Select information out of database for that day $result = mysql_query($sql) or die (mysql_error()); if(mysql_num_rows($result) == 1) {// ...........go on to display it[/code]etc, hope that helps you understand it better. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 6, 2007 Author Share Posted January 6, 2007 I'm a n00b at PHP and MySQL... so that's what you use to get the information out of the database and display it, correct? Then, for the MySQL thing, do you create a table named "newsdate"? If so, then what do you do? Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 I don't get this... ??? :( Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 In your table which has the news, add a field for DATE. Not a new table, just a field to your existing table.Post your database structure and we can explain more if need be.If you don't have a database yet, do more research and start actually making something ;) Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Yes, I have a database. But how do I post the structure? Do I take a screenshot of it? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted January 7, 2007 Share Posted January 7, 2007 [quote author=john010117 link=topic=121305.msg498534#msg498534 date=1168129693]Yes, I have a database. But how do I post the structure? Do I take a screenshot of it?[/quote]you can tell us table name and all it's column names...."News"- User- Date- News- Ratingsomething like that... just the structure Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 If you have PHP My Admin, you can do an export and copy the SQL statement generated. Or do what generic said :) Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 I just made 2 fields, one with "DATE" and the other one with "TEXT". Here it is...[code]CREATE TABLE `news` (`What do you do?` TEXT NOT NULL ) ENGINE = MYISAM ;[/code] Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 What you just posted doesn't make any sense. You have a table news with a field called "What do you do?".If your table has two fields, and one is of the DATE type, use the SQL posted above. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Ok. I've renamed the field to "news". So then, I just put the MySQL code posted by Mutley into phpMyAdmin (that's what I'm using)? Quote Link to comment Share on other sites More sharing options...
Mutley Posted January 7, 2007 Share Posted January 7, 2007 Renamed which field?My code needs to be entered in PHP not phpmyadmin, the code was an example by the way, just copying it won't work. Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 7, 2007 Share Posted January 7, 2007 I'm guessing that you do have some knowledge of PHP basics, and MySQL is your new point here...Now you need a form to easily post all this, if you've made it to PHP basics you know about HTML, just an assumption but you really should.This form should have, well from what your structure suggests just 1 field for all your news post content.Using the information posted from the form we want to insert it into your database. this function is called 'INSERT'.[code=php:0]<?$date = date("m.d.Y")." at ".date("h:i:s a");mysql_query("INSERT INTO news (text, date) VALUES ('{$_POST['text']}', $date)");?>[/code]Now what this code does is first create a date, and assigns it to $date to be used later. (This date will be MM/DD/YYYY at HH:MM:SS am/pm) It then takes the information posted from the form and inserts it.This is a basic basic basic version, you will need to add to it, and create the other bits to make it function to the best of its ability.Another suggestion would be to add fields to your table such as Title and Poster. Quote Link to comment Share on other sites More sharing options...
Jessica Posted January 7, 2007 Share Posted January 7, 2007 You might want to go through some more tutorials on MySQL.Or use a pre-existing CMS. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 [b]To Mutley[/b]: I've renamed "What do you do?" field to "News".[b]To DarkendSoul[/b]: So you post that code in the form?PS: I know HTMLPSS: I'm new at PHP and MySQL. Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 7, 2007 Share Posted January 7, 2007 You have the form's target posting website as the site with that code. Once again this code is basic, it wont tell you if it did it right. It also may not display errors if your server does not have this option enabled. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Even though it didn't say if it worked or not, it didn't show any errors, either (using your code).Here's my form code:[code]<form action="test10.php"><input name="news" size="30"><input type="submit" value="submit"></form>[/code]...and here's my test10.php code:[code]<?php$db_host = "&*<?php$db_host = "****"; $db_user = "****"; $db_pass = "****"; $db_name = "****"; $dbac = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $date = date("m.d.Y")." at ".date("h:i:s a");mysql_query("INSERT INTO news (text, date) VALUES ('{$_POST['text']}', $date)");?><?php$db_host = "****"; $db_user = "****"; $db_pass = "****"; $db_name = "****"; $dbac = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $date = date("m.d.Y")." at ".date("h:i:s a");mysql_query("INSERT INTO news (text, date) VALUES ('{$_POST['text']}', $date)");?>"; $db_user = "allaoorg_admin1"; $db_pass = "9055084308"; $db_name = "****"; $dbac = mysql_connect($db_host,$db_user,$db_pass); mysql_select_db ($db_name) or die ("Cannot connect to database"); $date = date("m.d.Y")." at ".date("h:i:s a");mysql_query("INSERT INTO news (text, date) VALUES ('{$_POST['text']}', $date)");?>[/code]Am I doing it right so far? Quote Link to comment Share on other sites More sharing options...
fert Posted January 7, 2007 Share Posted January 7, 2007 [code]$db_host = "&*<?php[/code]you forgot a " and a ; Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Ok, I've fixed that. Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 7, 2007 Share Posted January 7, 2007 Your post will not yield any information, the $_POST and name of the field do not match.Either change the name of your form input or "{$_POST['text']}" ('text' is the name the field it gets information from. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 I changed both to "news". Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 7, 2007 Share Posted January 7, 2007 Well test it out and let us know if it adds stuff.Note that this is insecure and anyone can post.And clean up your code! Heres a cleaned version that can go into test10.php[code]<?php// Connection information$db_host = "***"; $db_user = "***"; $db_pass = "***"; $db_name = "***"; // Connect to server$dbac = mysql_connect($db_host,$db_user,$db_pass); // Select databasemysql_select_db ($db_name) or die ("Cannot connect to database"); // Check if news has been posted.if ($_POST['news']) { // *Start* // Get current date. $date = date("m.d.Y")." at ".date("h:i:s a"); // Insert information to table mysql_query("INSERT INTO news (text, date) VALUES ('{$_POST['news']}', $date)");/*END*/ }?><form action="test10.php"><input name="news" size="30"><input type="submit" value="submit"></form>[/code] Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Sorry for being such a noob, but how do you know if it added to the db or not? I'm confused. ??? Quote Link to comment Share on other sites More sharing options...
DarkendSoul Posted January 7, 2007 Share Posted January 7, 2007 * Edited last post with a helpful hint for you.You said you had phpMyAdmin i believe? Go in there and look at your table, then chose browse. Quote Link to comment Share on other sites More sharing options...
john010117 Posted January 7, 2007 Author Share Posted January 7, 2007 Oh, shoot! Did I just give my user/pass away? :o [b]DarkendSoul[/b], can you please censor my info in your code?Oh, and I can't seem to press "browse" for some reason. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.