Make an archive-like page in PHP?

1 Answer

Answer :

Hi Davey, Here is some quick and dirty code for your ‘showarticlesfor($year)’ function which should get the job done (NOTE: I am assuming you are using MySQL as your DBMS): function showarticlesfor($year){ $connection = mysql_connect(“MY_HOST”, “MY_USER_NAME”,“MY_PASSWORD”) or die(mysql_error()); mysql_select_db(“MY_DATABASE”, $connection); $result = mysql_query(“SELECT title, DATE_FORMAT(TABLE_NAME.date, ’%d-%m’) FROM TABLE_NAME WHERE DATE_FORMAT(TABLE_NAME.date, ’%Y’) = ’$year’”, $connection) or die(mysql_error()); if(mysql_num_rows($result) > 0){ echo ”<br />$year<br /><br />”; while($row = mysql_fetch_assoc($result)){ echo ”{$row[“date”]} {$row[“title”]}<br />\n”; } } } Be sure to replace ‘MY_HOST’, ‘MY_USER_NAME’, ‘MY_PASSWORD’, ‘MY_DATABASE’, and TABLE_NAME with the appropriate information. Also note that using the word ‘date’ as a column title in your table is not a good idea, as a lot of DBMS have this as a reserved word for their function/datatype, so you have to reference it in a SELECT as ‘TABLE_NAME.date’. Explanation: Basically, you are selecting all the data from your table that has a year of $year. You are also formatting the date output to be “day-month”. If there were any records returned to you, we first output the year, followed by a few breaks, and finally by the records (the while loop). References: MySQL DATE_FORMAT PHP mysql_fetch_assoc()

Related questions

Description : Is it possible to store PHP scripts in the cloud?

Last Answer : answer:Yes Simplest example would be to grab the script from a service, stick it in a variable and eval it. Could you provide an example of why you’d want to? I can’t think of a good reason to do it offhand.

Description : Which is better between PHP and ASP.net?

Last Answer : answer:I prefer PHP. It is well documented and very portable. ASP is non starter for me since I refuse to use IIS. I like Ruby and Python too. But when I have to start a project from scratch I use PHP and CodeIgniter.

Description : What's your favorite PHP integrated development environment (IDE)?

Last Answer : If I did PHP development, I’d probably use Coda: http://www.panic.com/coda/

Description : What's the best way to deploy a PHP application?

Last Answer : answer:debian package At a previous job I had to install/maintain a site written in CakePHP. I made it into a debian package. “aptitude install projectname” and you’re done (although I guess that is technically “touching the server”) Send me a PM and I can give you the details.

Description : PHP problem with && and possibly a malfuntioning array?

Last Answer : answer:Unfortunately the examples above don't really shed a lot of light without some additional information. Maybe we can help with some troubleshooting tips in general? A couple of things that come to mind ... is where you're expecting it. Good luck with it, I hope it all comes together.

Description : Which windows application for writing PHP codes?

Last Answer : answer:Don’t know about compiling php? and debugging is also foreign to me. But Notepad++ is awesome.

Description : If I already know basic PHP/MySQL, what else should I learn to use Google App Engine?

Last Answer : answer:I am not an expert, I just started reading up on this myself, but here are a couple of starting points on data storage. Rather than a separately maintained SQL database, ... .com/appengine/articles/datastore/overview.html http://code.google.com/appengine/docs/python/datastore/overview.html

Description : PHP echo number of instances if specific word?

Last Answer : make a while loop that goes through the contents of the array. prior to the array define a counting variable and give it the value 0. during each loop, increase the value by 1 if the word “and” is encountered

Description : How would I check if an XML element exists in PHP?

Last Answer : Wrap it in an if that checks for the existence first if($status->item(0)) { $eventStatus = $status->item(0)>getAttributeNode( value )->value; } and run from there, I haven't actually run your ... and does just about everything you'll want (then you can use the DOM stuff to fill in the blanks)

Description : How would I perform this operation on a string in PHP?

Last Answer : That isn’t XML, that’s HTML. Can you not grab the data in a format where times are stamps?

Description : [PHP] Forgot Password Help?

Last Answer : You could try using the built in PHP crypt() function, you pass the string and a salt you want to encrypt, then to decrypt it use the decrypt() function and the same salt. That should give you the same password back. Though really you should try to push for a randomly generated password on reset.

Description : Referencing a class from another class [PHP]?

Last Answer : Great question! I wish I knew.

Description : Cloning Objects in PHP?

Last Answer : I usually use it when I'm at a midpoint that I'll be using for several objects. How about a oversimplified example just to illustrate the point? If I'm programming a Christmas story and have ... formatted request that I'll be reusing, and then clone the XML object before filling in the particulars.

Description : Does including a file with lots of functions slow down PHP applications?

Last Answer : It is always better to short the calls to the server, so it is a good practice to keep it in one file and one call. But also the the size of the file been called sometimes slows ... the time periods of the requests to the server. There is also PHPSpeedy that makes the requests significantly faster.

Description : I'm in PHP right now. Will a transition to Objective-C be relatively easy, or do you think I should try other languages first?

Last Answer : answer:Objective-C is a compiled language, strong typed, then is different to Php in many ways. Since 2.0 version, Obj-C has its own garbage-collector for memory management. I don't try to ... want to do with Objective-C ? Cocoa framework is really interesting, you should take a look at it !

Description : What is the best php framework?

Last Answer : I have found cake to be the most portable and easy to install. If I had to choose a MVC PHP framework I would go with Cake.

Description : Cut a string into pieces (PHP! ;-) )

Last Answer : You could use substr while looping up to the length of the string and using array_push to build your $string_array.

Description : What's the best editor for PHP/Javascript work?

Last Answer : Vim

Description : Anybody know how I can integrate .zip files with PHP?

Last Answer : http://www.net2ftp.com/ allows you to do this. You could dig through the source (you can download it there) and figure out how they did it. Or you could just install net2ftp and have them use that instead.

Description : Free PHP Web Server for Dreamweaver?

Last Answer : answer:This is probably your best bet for getting PHP, Apache, and MySQL running easily. http://www.apachefriends.org/en/xampp.html It works well on most operating systems. I can't help with Dreamweaver ... add that xampp runs on your computer. No need for a external server. It is great for testing.

Description : External Link to PHP module execute twice?

Last Answer : answer:I'm not sure I understand the question correctly, but if I do: it sounds like whatever program you're embedding your link in ( email or word document ) is loading the URL more than once. It' ... has been moved, and only raises an error if the appropriate row can't be found in either table.

Description : How do you get the link posted and not the updated page?

Last Answer : You don't have control over it. The URL that you referred to today is pointing to a page that is housed at a server somewhere else. It isn't under your control or Fluther's - it is under the control of ... a month or a year ago. Summary: it isn't under your control. You get the page they send you.

Description : How is Facebook updating my page if I didn't refresh the page at all?

Last Answer : answer:They’ve probably put something like this in there somewhere. Which would make the page refresh every 5 seconds.

Description : What does the term "internet 2" refer to when designing a web page...precisely, how is that different than internet 1 sites?

Last Answer : Um… Do you mean Web 2.0?

Description : Any way to practice web page creation offline?

Last Answer : answer:You can do HTML, CSS, and Javascript with just notepad and a web browser. Just save the file with an .html extension and it should interpret correctly. W3Schools is a great place to start, they ... guides and you can figure out what you want to explore further from there. Good luck with it.

Description : How to implement a JavaScript code that doing "Set as my Home Page" in Google Chrome?

Last Answer : So, you’re saying the JavaScript code for doing this works in IE and Firefox, but not Chrome? That’s weird. Let me see if I can find a script for you.

Description : How can I specify the page name for Twitter and Facebook sharing buttons on front page of website?

Last Answer : answer:I know what you're talking about and have had a bit of experience designing a system like the Facebook and Twitter ones for a site I co-developed. Here's an example of how you do it on our ... because that seems to be related to the Like button in some way. Sorry I can't be more helpful

Description : How can I implement in my small web site company how many members are observing each page right now?

Last Answer : I've seem people use the window.onbeforeunload event to do this. A common problem with this method is a script not finishing in time. You can use the event to open a new web page that runs a ... , but never sends display information. That way you don't have to worry about your function being killed.

Description : Is there a program I can get for Firefox to highlight multiple items on a web page, and have them saty highlighted as I browse?

Last Answer : I have most of the add-ons and I haven’t seen it.

Description : Executing JavaScript in a page retrieved using AJAX?

Last Answer : Would assigning the scripts in page B to an “onload” event handler not work? (I’m new to this, but that seems possible. Forgive my kneejerk response.)

Description : What is a data page ?

Last Answer : A database is made up of one or more interrelated files , called a database.

Description : What is a page with multiple slides called ?

Last Answer : A page with multiple slides is called Hand outs .

Description : How do you get to the bottom or top of the page in Google Archive?

Last Answer : Tropical_Willie just posted the answer on your other Google doodle question.

Description : Using a PHP page to post "blog" entries on my website.

Last Answer : answer:It shouldn't be too hard- you'll probably want to apply the CSS to the page that is retrieving and displaying the information, not the page you use to enter it. Whatever code is generating your ... CSS classes, id tags, and DIVs to. It's hard to get specific without actually seeing the code.

Description : Primary language used for static web page design is: a) HTML b) PHP c) Perl d) None of These

Last Answer : a) HTML

Description : How can I make pages like this in Tumblr?

Last Answer : answer:I don't know much about Tumblr but from what I understand it's not as fully functioning as other kinds of blogs, and it doesn't allow pages like Wordpress does. If Tumblr allows you ... If Tumblr doesn't support that feature you may be better off moving your blog to Wordpress or Blogger.

Description : What kind of script/program/CMS/etc. is needed to make a site like care.com, airbnb.com, schoolofeverything.com, fiverr.com?

Last Answer : All the sites you posted are so different I don’t think you can use a CMS without being heavily modified. I would charge about 20K to even touch it if I was doing it from scratch.

Description : How can I make Open Office look like a dictionary book?

Last Answer : I find it easier to create columnar data in a spreadsheet. If you already have Open Office, Calc should work fine for you.

Description : How to make a structured-like web via those extensible markup language?

Last Answer : I’m not following your question.

Description : I want to make a question and answer site like mind. Domain and hosting are ready. Can anyone make it ? Don't build with WordPress. Ans Bangla should not be made in this way. Knock if there is anyone like that.

Last Answer : You can contract with the admin of this website. He can make you a site.

Description : What is a good programming language to make a multiple choice quiz?

Last Answer : Google classroom should work.

Description : I want to make a video games, where do I start?

Last Answer : answer:This may sound vague, but yes, and then some. Seriously, you need a WIDE range of skills to make video games. A wide enough range that most games are made by teams as it's extremely rare to ... , I'd say the best place to start is the concept, followed by the design, then assembling a team.

Description : Can you help me find an App that can help one make App's? (any platform, including pen and paper, details inside)

Last Answer : answer:I'm not sure if it's quite what you're looking for, but my buddy makes AppCooker. You can use it with AppTaster to create mockups and make them play. I can't speak to their efficacy personally because ... charge $75-125/hour. If that's the route you end up wanting to take, feel free to PM me.

Description : If I must have an android smartphone to make apps for it, what is my best option?

Last Answer : answer:Go with the pure Google experience (vanilla Android). You can get the Galaxy Nexus from Verizon or Sprint - or go straight to Google and buy directly so you don't need a contract. Phone ... get the latest updates in a timely manner. This is important if you're going to be developing.

Description : I'm clueless. Why do people make a differentiation between Apps and other programs? What's the difference?

Last Answer : answer:“App” == “Application” == “Program” Same thing.

Description : Why does Microsoft make it so hard for programmers to call their application programs?

Last Answer : Have you explored Entity Framework 4.0/4.1? I have played around with it and it looks promising.

Description : What are the most important things that make a web site successful?

Last Answer : answer:Well, success is definately a function of the content. The usability is the multiplier, and the exponent is the time it has been available. I think it may actually be that simple, ... something similar in form. Advertisement plus a value derived from media attention can be the added value.

Description : Computer programmers: if you had to make a music video of the beauty/elegance of your thought process, what music and visuals would you pick?

Last Answer : answer:There are many aspects to programming, and so it's hard to come up with an analogy that fits them all. I used to write a fair amount of poetry in what feels like a former life. ... They have some actions which are public facing, and others that are strictly private and not exposed to others.

Description : How to make custom command to text in Mac OSX?

Last Answer : TextExpander does something similar. I can type “MBP” and have “MacBook Pro” appear for me.

Description : Got a Macbook for programming, did I make a mistake?

Last Answer : Linux