DexterTheCat Posted June 5, 2014 Share Posted June 5, 2014 (edited) I got an idea with my homepage in progress. It's a blog and I want to sort my post in a navigation bar. Is it possible to do a script with $date function to create a new file the 1th of every month. Then use file_get_content on the current month. To clarify in this stage I haven't started connecting my database. Edited June 5, 2014 by DexterTheCat Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/ Share on other sites More sharing options...
ginerjm Posted June 5, 2014 Share Posted June 5, 2014 Yes of course it's possible - not likely tho. If I were doing this, I would do it this way: 1 - store each day's post(s) in a db table with the date as the key field. Or perhaps, the date and a sequence number if you wanted to have multiple posts per day ie, multiple records per day. 2 - use php to build a dynamic dropdown to select the available month/year posts 3 - use a second dropdown built with ajax to show the available days for the month/year selected in #2 4 - use ajax again to then show the post(s) for the specific day selected in #3. No nav bar cause it's not really (imho) navigation, but merely selection. I don't think you want to put any references to individual posts in a nav bar or immediately in a dropdown. You're probably going to have way too many posts to be able to present them to the user that way. Let the user drill down to the item he wants to see. Of course when the page is first displayed, I'd actually show the user the current day's post and then he/she can use the dropdowns to move to a different one. Maybe even a button to automatically go back one day and another button to go forward one day. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481943 Share on other sites More sharing options...
Psycho Posted June 5, 2014 Share Posted June 5, 2014 To clarify in this stage I haven't started connecting my database. Create a database and do it the right way. You are only creating more work and problems by trying to do this through flat files. Yes, there is a learning curve to get started with databases. But, the benefits are huge. For a simple blog it would not be a lot of work once you grasp the basics. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481944 Share on other sites More sharing options...
DexterTheCat Posted June 5, 2014 Author Share Posted June 5, 2014 Sounds awesome ginerjm! I will try that out. When I put my post to file now with a+ does it fill the file from the last post. Is there a way ro reverse so the most present post comes first? Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481945 Share on other sites More sharing options...
DexterTheCat Posted June 5, 2014 Author Share Posted June 5, 2014 Create a database and do it the right way. You are only creating more work and problems by trying to do this through flat files. Yes, there is a learning curve to get started with databases. But, the benefits are huge. For a simple blog it would not be a lot of work once you grasp the basics. Yeah! I agree but I must make this one without... Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481946 Share on other sites More sharing options...
Psycho Posted June 5, 2014 Share Posted June 5, 2014 Yeah! I agree but I must make this one without... Odd, you originally stated To clarify in this stage I haven't started connecting my database Which indicates you intend to use one at some point. But, now you say you must implement this w/o one. Then use a flat-file database. Once you set up a real database later it would be a simple process to transition the data and update the code and add/change the connection settings. You would already have the queries and logic set up for accessing/modifying the data. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481947 Share on other sites More sharing options...
cyberRobot Posted June 5, 2014 Share Posted June 5, 2014 Sounds awesome ginerjm! I will try that out. When I put my post to file now with a+ does it fill the file from the last post. Is there a way ro reverse so the most present post comes first? You could read the file into an array with file(): http://www.php.net/manual/en/function.file.php You can then loop through the array backwards...or reverse the array with array_reverse(): http://www.php.net/manual/en/function.array-reverse.php Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481948 Share on other sites More sharing options...
ginerjm Posted June 5, 2014 Share Posted June 5, 2014 My final saying on this post. You are choosing to IGNORE what Psycho told you - a guy with over 10k posts! - and proceeding to waste your time developing for a flat file system that will NOT be able to be used in the fashion I described for you, which YOU YOURSELF thought was awesome. Really? Tell me you aren't going to be silly about this. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481950 Share on other sites More sharing options...
davidannis Posted June 5, 2014 Share Posted June 5, 2014 Yeah! I agree but I must make this one without... Why would you need to make it without? Easy to install versions of MySQL are available for Windows, Mac, Linux, and even Android. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1481955 Share on other sites More sharing options...
DexterTheCat Posted June 6, 2014 Author Share Posted June 6, 2014 My final saying on this post. You are choosing to IGNORE what Psycho told you - a guy with over 10k posts! - and proceeding to waste your time developing for a flat file system that will NOT be able to be used in the fashion I described for you, which YOU YOURSELF thought was awesome. Really? Tell me you aren't going to be silly about this. I am not silly but I was told to do it this way! I don't really get how a university course can teach php but not let the student use MySQL... Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1482014 Share on other sites More sharing options...
Ch0cu3r Posted June 6, 2014 Share Posted June 6, 2014 If you are to store the blog entries in a flat file format. You'd probably want to also include the year and month in the filename, so not to overwrite blog entries entered from a previous year. You could then do something like this // define the path to the blogs $blog_entries_path = 'path/to/blog_files/' . date('Y-m') . '.txt'; // example file path produced path/to/blog_files/2014-06.txt // check to see if the path does not exists. if(!file_exists($blog_entries_path)) { // create a new empty blog file for current year and month. file_put_contents($blog_entries_path, ''); } // read the contents of the current months blog entries $current_entries = file_get_contents($blog_entries_path); // or use file() - docs http://php.net/file don't really get how a university course can teach php but not let the student use MySQL... Maybe they first want you to create an application using PHP's file functions, so you can develop a good understanding of the PHP language. Then maybe later on in your course they will start to introduce you to databases. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1482019 Share on other sites More sharing options...
DexterTheCat Posted June 7, 2014 Author Share Posted June 7, 2014 If you are to store the blog entries in a flat file format. You'd probably want to also include the year and month in the filename, so not to overwrite blog entries entered from a previous year. You could then do something like this // define the path to the blogs $blog_entries_path = 'path/to/blog_files/' . date('Y-m') . '.txt'; // example file path produced path/to/blog_files/2014-06.txt // check to see if the path does not exists. if(!file_exists($blog_entries_path)) { // create a new empty blog file for current year and month. file_put_contents($blog_entries_path, ''); } // read the contents of the current months blog entries $current_entries = file_get_contents($blog_entries_path); // or use file() - docs http://php.net/file Maybe they first want you to create an application using PHP's file functions, so you can develop a good understanding of the PHP language. Then maybe later on in your course they will start to introduce you to databases. MySQL is my own summer project when the university don't have any courses in MySQL or databases. Thank for your helpfull adivce and tips. Quote Link to comment https://forums.phpfreaks.com/topic/288994-create-new-text-file-monthly/#findComment-1482135 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.