ClanKiller.com http://forums.clankiller.com/ |
|
another php question http://forums.clankiller.com/viewtopic.php?f=8&t=543 |
Page 1 of 1 |
Author: | Satis [ Thu Oct 30, 2003 1:29 pm ] |
Post subject: | another php question |
This is what I'd like to do... if someone could point me toward a tutorial I would be appreciative... On my news page, I'd like to have all my individual news entries be separate text files in a directory (a directory of their own). I then want the actual news page to pull the 10 most recent text files into the page. I know this is possible with php, but I don't know where to begin to look for an answer. Additionally, I'd like to make an old news page that pulls all the rest of the entries in (but not the first 10). Can someone point me in the right direction? I'd like to do this with flat text files rather than a mysql table, since the entries don't need to be searchable or anything. Plus I want to learn how to do stuff like this. *edit* One more quick question... is it a bad idea to have a large number of php include statements? Like, including a file which then includes 3 files which in turn include several more? I'm doing a site redesign and I'm trying to make it as modular as possible. If it's a bad idea, I need to know before I get too far into it. |
Author: | RB [ Sat Nov 01, 2003 2:34 am ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Post subject: | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Okay, Satis. It appears to be question I can answer because I've done many similar things in CGI before. Also I now work on one Pollpage in pure PHP and I also do not know damny nothing of mysql so, we face with the same problems. (I think) You didn't ask for making whole thing for you so, I'll be limited to giving some advices only. If you search for some manual to learn howto this, I doubt you'll find something exact so easy. If you insist, I recommend you to do some textprocessing works in C/PHP (rather PHP directly). This is not thing for placing on web. This is just model how it can look.
Satis, I must digress a bit to say you what are your BASE options. 0. I know php-mysql chain is more elegant way to do what you want. Well: 1. You can manage php to put all texts into one single txt file and then do update/edit/observation with PHP/HTML interface.(harder to make, easier to use) 2. You can make only your (old)news page php generators and add texts by simply adding new *.txt file into some directory.(easier to make, barely harder to use) 3. (After you make something) You should think about partial showing news (10 by 10 or n by n or all by all) on history page. 4. (After you make something) You should think about making manager for searching that thing. Like google. 5. (While you make something) You should think about following abstraction: Why 10 news on the top page? You should allow $n numbers on news on the first page. Others are in history. Simple. Just set $n to 5 and you have 5 news on the top page. In data abstraction and working comfort, you can go far away from just this. If you open *.tpl files in your XFile directory, you'll see they are pure HTML pieces of HTML pages. If you look better, you'll see they have some markers (like "{POST_MESSAGE}") in there on keyplaces (like date, topic title, post contain etc. etc.) So, purpose of templates are to divine forum pages to many easy-observing pieces. Marking keyplaces just make it many-purpose-thing. You can do the same: 1. Make main page tamplate. It, simplied, could looks like:
2. Make news piece template. It, simplied, could look like:
Notice I used symbol "#" for keyplaces marking. It is enough long for start. Also, I didn't marked "what is what" (date, time, contain, ...). Instead, I will assume any thing must have exact order in datafile. You have many ways to mark "what is what", but I'll give freedom to your imagination rather. 3. So, then you have to manage php to use these templates to present heap of files or database in one file you make. Here, you'll have one loop in the global domain (later, it can become function). It should send main page template BUT it also should replace symbol "#" with last 10 news. That can be done with one function. Let see:
That while is a bit ugly. I'm not sure if this equivalent will work in php (it works in C)
4. So, when we talks about sendnews(), that it more complicated thing. First, there you have to open dbase and find 10 last entires (easy if all files are in one file) OR to find last 10 made files. You have much ways to do both of these things:
Second: So, you'll also have 1 template and 10 news. You have two-three-four ways.
Third: With recent algorithm, one news file (1.txt for ex.) should look:
You should think about overall standardization first. That's all for start. You can go mooore deeper into abstraction and comfort doings. When you finish it, moderating your site should be easy as in this forums. (either you manage database by yourself or let that to mysql) As for the including, I think you should feel free to make how much levels (or line includes) you need. Let me know if I can help you more. |
Author: | Satis [ Sat Nov 01, 2003 2:12 pm ] | |||||||||
Post subject: | ||||||||||
thanks gfreeman, I wasn't expecting help from you. Indeed, what you laid out were basically my options. The C is gibberish to me, but hey, that's fine. In fact, I just solved my problem yesterday. I didn't have a chance to post about it, but I got it working. What I did was make a directory /news with a bunch of text files. Each file is named [date].txt, like 20030823.txt, that way the date is part of the filename and I can easily sort it. The code is here:
|
Author: | Pig [ Sat Nov 01, 2003 2:32 pm ] |
Post subject: | |
Don't do .txt files. Don't be a pussy. This is a very easy project to start learning MySQL. Plus, there are tons of things you can do with a database other than search it for a text string. 1. If you store your news in a database then you all you have to do is store the date it was entered as one of the fields in the entries row. Then you can just selectively get the 10 most recent news post, or whatever. 2. There would be no manual movement of files. Archiving, etc would be automatic. 3. files are much harder to work with properly than a database. 4. A database would be much more effecient. Why use programming if you are going to castrate the concept. That's like buying car so you can store your gas in it. If you want to store your gas, get a gas can. If you are using a car, then fucking drive it. This is a great tutorial to get started with PHP/MySQL: http://www.sitepoint.com/article/228 So that you have a framework of what you need to do, I will diagram the process below. When you hit a question, ask. BTW, I'm not going to help you do this with txt files. That's just a waste of both of our time. Use phpmyadmin or other db utility to create a table in your database. The table should have a prefix to distinguish it from any other projects in the same database (such as you found with phpbb). I would use ck_, but it is your choice. You will need a field for the text, id, and date. The table might look like this: ck_news ========= ck_news_id (int) ck_news_post (text) ck_news_date (varchar) everything should be obvious, but make sure that when you are populating the ck_news_date field, that you use a unix timestamp Put a bunch of crap in there to test it as well. When you build the page that you want to have the news, it would be easiest to just create a news.php file and include it on your main page, rather than do the programming on the main page itself (btw, includes, and mulitple includes are no problem - include 100's if you want). On news.php, connect to the database (see the tutorial above). Then you need to create a simple query like: $result = mysql_query("SELECT * FROM ck_news ORDER BY ck_news_date DESC LIMIT 0,10"); maybe that should be 1,10... don't recall off the top of my head. You'll figure it out. The result is nothing more than a mathematical place holder of the results found in your query. There is no data directly accessible from it. You need to create a loop to manually extract the rows from it. Then you need to get the data from the query: while( $row = mysql_fetch_array($result) ) { echo("posted on: " . date("Y.m.d H:i", $row[ck_news_date]) . "<br><br>$row[post]"); } Boom! done. If you want to see all of them, just don't specify a limit. I gotta go, ask more questions as they come, or post if I wasn't clear. If you find me online (IM'ing) then I'll explain in excruciating detail what you are actually doing). |
Author: | Satis [ Sat Nov 01, 2003 7:28 pm ] |
Post subject: | |
Thanks Pig. I completely understand what you're talking about... I got a lengthy exhortation on the advantages of MySQL from a PHP friend I have. In fact, I plan on eventually doing it as a MySQL table. My main reason for going with flat text files was just to learn how it would be done and get a better handle on staight PHP. Once I have all that working, I'll probably just rewrite it all to use MySQL instead. In fact, I'm basically done with the flat text thing. The only thing I'm working on right now is setting a variable that displays either the first 10 posts (default) or all but the first 10 (when you click the 'older news' button). When I get to the point of sticking it into MySQL, I'll probably write a .htaccess protected form to automate inserting new news entries. Oh, and for the record, my news page is index2.html, which is basically some header stuff like title include header include news.txt include footer news.txt is where all the actual processing goes on. I'm making this sucker so modular I can do anything with it without having to rebuild it from scratch. At least, that's the plan. I'll let you know if I have any more questions. |
Author: | RB [ Mon Nov 03, 2003 2:46 am ] | |||||||||
Post subject: | ||||||||||
Disagree, barely. I gonna to tell what you mean thru my scope. A database would be much more effecient on WEB and similar envs. Why use programming if you are going to castrate the concept? That's like buying airplane so you can drive it on the street. If you want to drive airplane, go to the airfield. If you gonna drive on the street, then fuckin' buy a car. |
Page 1 of 1 | All times are UTC - 6 hours |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |