Simple MySQL to CSV

I needed to make a quick export earlier this week so that we could get records into another program. At first I though I’d need to find a php library to make a csv for me (to save me the time of making the script myself) but it terns out that the process couldn’t be easier. The csv format is very easy to create and really seems to follow several key rules. First, you put things in quotation marks. If it’s a number you don’t have to, but just to be safe I put everything in quotation mark (it was also easier coding wise). Second, if there is a quotation in a cell you must put another quotation before it. Finally, you must create a new line at the end of every new like (obviously), With That in mind I made this:

Snipplr: http://snipplr.com/view/58408/simple-mysql-to-csv/

The code is pretty self explanatory, just doest what you need to as mentioned in the first paragraph. I tested it (admittedly in a limited fashion) and it works great. I don’t think there could be an potential problems but as this was created in less than 5 minutes as really just a quick test I’m not sure. If anybody find anything that might cause issues let me know and I’ll expand upon it but as of now it does exactly what I created it for.

Backend Update

I updated the back end a bit, made sure I was running the newest version of wordpress and whatnot. Part of this update required me to go back through and update all the previous code sections to work with the new code display plugin I’m using. Overall a pretty minor update.

Simpler, Single Loop WordPress Theme Creation

Recently I’ve been making alot of wordpress themes (just not my own) I always like to keep the files to a minimum. In wordpress, the loop.php file is the traditional one to handle displaying all the posts, pages, media, and anything else you can look at in wordpress. The official wordpress themes, and countless others, use multiple “loops”, one for the main page, one for the an individual post, and even one for the pages in some themes. This clutters up the files and generally makes things a mess. I created a simple function to call that lets me filter things instead. First, you need this in the theme functions.php file

Snipplr: http://snipplr.com/view/58053/simple-single-loopphp-word-press-theme-function/

Then, instead of requiring the loop.php file in your theme index you just insert the new the_loop() function, with all of the items you want filtered out. You can use whatever arbitrary names you’d like, just use the same names in your master loop. First you call the loop like this:

Snipplr: http://snipplr.com/view/58053/simple-single-loopphp-word-press-theme-function/

Then you program your loop to use the display() function to determine if it’s going to show that, in the example above it would look like this:

Snipplr: http://snipplr.com/view/58053/simple-single-loopphp-word-press-theme-function/

In that case it will show the header and the content (since we didn’t tell it not to when calling the_loop() but won’t call the comments or meta because we did. Pretty simple little bit of code that saves a lot of time in the long run since now everything can be in one file and if you change something you only have to look in that same file. Thats it for now, it’s been a long week. Next week I hopefully will be starting on the new theme for this site as well as posting something a little meatier, a simple modular site system.