Saragon Posted April 17, 2006 Share Posted April 17, 2006 This might belong in the "Tutorial Help" section, but I'm new enough to PHP that I definitely qualify as a newbie, so here goes.I'm currently trying to do several things at once: Build a webpage (something I'm not too bad at, at least from a design perspective) and learn PHP (something I've just started at, and am not at all good with yet.) My design for the site includes a newspost/blog on the front page, but every open-source PHP blog I've come across (even the ones that claim to be simple) have too much excess on them. All I'm really looking for is a way to organize bits of news by date of creation and post a certain number to the front page, with an archive page for the rest.Since it's for my personal site, I can add complexity to it as I see fit, and so this strikes me as a great opportunity to learn some 'real world' PHP at a level slightly above most beginner tutorials. Unfortunately, I can't find any tutorials or guides on how to build a very basic blog from the ground up, and I'm not good enough at PHP yet to disassemble other blogging code and see how it's done.What I need, therefore, is a good 'DIY' blog tutorial that others have either found or made (I couldn't find one in the tutorial section here, sadly.) Barring that, I'd be happy with a suggestion or two on how I should start thinking the design through. I figure that best practice is to write entries, timestamps, etc. to a database, just as everything else is database-driven these days; beyond that, I really don't have any requirements.Any advice and help is [i]much[/i] appreciated. Thanks a lot! Quote Link to comment Share on other sites More sharing options...
redbullmarky Posted April 17, 2006 Share Posted April 17, 2006 the same principles apply to many things, but here's an idea. building blogs is relatively straightforward, but can appear tricky if youre new to PHP.what information do you want for each blog entry? you need to think about content, such as the title, main text, date/time, user id (if youre not the only person posting), pictures, etc. the blog i use only has these 5 fields in my MySQL database:id - the record keypublic - this is set to y or n, and determines whether it's just a saved entry or whether it has been published.date - a timestamp of when the blog entry was createdtitle - simple title for the blog entryentry - the text that makes up the main blog entry.of course, you could also use a plain text file or even a XML file if you know much about them instead of a mysql db. the principles are very similar with each. in some ways too, using a text file or a XML-type file would be easier than also having to learn MySQL.once you've planned how youre going to store the data, the whole process of putting the blog together is fairly straightforward. if you're using MySQL, then ANY mysql tutorial will get you the basics you need, including using SELECT/ORDER BY (for getting blog records to be displayed), INSERT (for creating new entries) and UPDATE (for editing existing entries). you don't need to go any further than that for now.once you've got the grasp of that, all you need to do (in HTML) is design a 'container' where a single blog entry will go. wrap it in a PHP 'while' loop to read all of your SELECTed entries from the database, using the 'echo' function to display the information you've read from a blog entry.ok, i've not gone as far as posting the code for you, but if you can get a clear idea of what you need and how it should look, the amount of PHP you need to get the whole job done is very minimal.hope that helps a bit,Mark[b]edit[/b]: i do have bits and bobs of a simple blog script i use (have a look at it working here [a href=\"http://www.crashandburn.co.uk/blog.php\" target=\"_blank\"]http://www.crashandburn.co.uk/blog.php[/a] and here [a href=\"http://www.thedinnertimes.com/columns/\" target=\"_blank\"]http://www.thedinnertimes.com/columns/[/a] ). youre welcome to have the scripts to have a look although for the sake of getting to grips with things and figuring it out, youre better have a bash at it yourself. if you want them tho, just drop me a PM. Quote Link to comment Share on other sites More sharing options...
Saragon Posted April 18, 2006 Author Share Posted April 18, 2006 [b]redbullmarky[/b] -- thanks very much! I understand XML a bit better than SQL, so that'll probably be the way to go (and it will be much more portable and easier to tie into an RSS feed, too, I think.) [b]cphp[/b]'s [a href=\"http://www.phpfreaks.com/tutorials/135/0.php\" target=\"_blank\"]Planning PHP Projects[/a] tutorial has also helped me get organized, so he deserves some credit too.My one concern about using XML to store blog data is the slow increase in read time: As I append blocks of data to the XML file, the most recent entry (and thus the entry called first for display) is the last major element in the file. The second entry will be the second-to-last, and so on and so forth. Thus any script that pulls data from the XML file by timestamp will have to go all the way to the end of the file to get it -- very slow. It's only text, so it's not a [i]huge[/i] problem, but is there a clever way to either (a) insert entries into the 'top' of the XML file, so that the most recent items are accessed first by a simple search? or (b) 'jump' quickly to an element with a particular value or attribute value? (If there isn't, the easiest thing to do be to create individual XML files for a particular period of time, say a year, to keep search times per file low.) 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.