Archive for March, 2008I remembered when I first started doing systems administration. One of the first (and simplest) things I had to do was learn how to generate a self-signed SSL certificate because I didn’t want to pay for one. Well, since my first time doing it, I’ve done the process about 2^18 times now, so it’s second nature to me. But, to some folks who don’t want to read the lengthy explanation on what each step does, here’s a breakdown of what commands you’ll issue on a Linux server. Explanation about the steps will follow. Howdy all, I made a post below relating to PHP, and the caching engine is not deleting the cache, so the post is showing up with < and > characters as literals, thus showing text boxes and other things that’s supposed to be straight code. Give it about 24 hours, and if it isn’t fixed, I’ll look into what’s causing the problems. Update (3/28/2008): I thought it was a problem with wpsupercache, but in fact it wasn’t. It was a problem with the Wordpress plugin Google Code Prettify and/or something internal to Wordpress. I say this because my code snippets, which originally had < and > characters inline were rendering the HTML as literal HTML - not what I wanted. But when I figured that I’d change the snippets to use < and > instead, it _still_ got rendered as literal < and > characters. Weird - no? Well, check out the most previous post prior to this, and I’ll (hopefully) update my archives with the syntax used in the wp-syntax plugin. One of my friends who has used PHP in the past, but hasn’t touched it in a while, recently asked me what the best was to handle mass edits and deletions on a page. To understand more what he’s talking about, he has a form with a table of data, each containing checkboxes in a column labeled as Delete? He wants to know how he should handle the deleting multiple rows in a fast and efficient way. How it may have been done (and you may be doing it right now) might look like this: <form action="deleteCategories.php" method="post"> <input type="checkbox" name="deleteCategory1" /> Category 1<br /> <input type="checkbox" name="deleteCategory2" /> Category 2<br /> <input type="checkbox" name="deleteCategory3" /> Category 3<br /> </form>
The above code is highly inefficient, and if you’re dealing with database records, I honestly don’t see how your application would survive. You would have to add lines to deal with other records, which would make your application severely crippled, or extremely difficult to maintain - one of the two. The solution to this is simple: use an “HTML Array”. When I say this, some people who have spent their lives working in HTML are going to say that HTML doesn’t have arrays. Of course they don’t. It’s PHP, though, that does. However, you have to pass to PHP the “array” in a certain fashion so that when it loads up it’s scripts, it knows its an array. Here’s how it works. In PHP, arrays are usually written to and read from like this:
So, in HTML, how on earth do you do arrays? You don’t have an <form action="deleteCategories.php" method="post"> <input type="checkbox" name="delete[category][]" value="1" />Category 1<br /> <input type="checkbox" name="delete[category][]" value="2" />Category 2<br /> <input type="checkbox" name="delete[category][]" value="3" />Category 3<br /> </form> What you see is I’ve named the checkbox fields the same name. In normal HTML land, this would be a no-no, and there’s a way to get around it if it doesn’t validate. That is, you simply switch to the following: <form action="deleteCategories.php" method="post"> <input type="checkbox" name="delete[category][1]" />Category 1<br /> <input type="checkbox" name="delete[category][2]" />Category 2<br /> <input type="checkbox" name="delete[category][3]" />Category 3<br /> </form> Now each checkbox has it’s own name and doesn’t overlap with others. We’ll consider the first HTML set case 1 and the second case 2. Here’s where the true PHP “magic” takes over and makes this a really powerful solution. You don’t have to then check and delete with the following code:
The above code is horrible. If you’re currently writing code like that above, slap yourself in the face with a nice wet fish. You’re about to get a rude awakening. Here’s how you’re actually going to use it:
In either case, only the checkboxes that are selected come through as the array, but in either case, PHP converts what looks like a name with special characters in HTML to an actual PHP array. It’s very powerful and you can script code to handle what you need to and not have to worry about adding or changing it as your database grows. |