I have a site where i need to allow people to upload a YouTube URL. I want to just store the ID in the MySQL DB and I need to be able to retrieve it later for embedding on the site. Sometimes people will paste a url cleanly like this...
"http://www.youtube.com/watch?v=P22G8YHveEg"
..where you could just explode the values at the equals sign and get the second item in the array to parse out the YouTube ID. It is nice to just have the YouTube ID so that you can use it as you need it to retrieve any info about the video that you might need.
Sometimes they paste the url like this:
"http://www.youtube.com/watch?v=P22G8YHveEg&feature=feedrec_grec_index."
So i needed a way to extract the "v" variable out of this url no matter how it is submitted into the DB.
This code allows you to get the query string variable that you are seeking...independent upon how many variables exist.
I just want to write about a great resource that i contribute to and use a lot. Hyperspatial has a code collective of snippets and frequently used code that is a good tool to use to find commonly used little tid bits. Here is a link to the code that i have submitted over there.
http://code.hyperspatial.com
There are many ways to write a script that will allow your site visitors to simply say "yes i liked this" or "no I do not like this" with a catchy thumbs up or down image. Here is a way to do it with "yes" or "no" buttons that will tally up the results.
This is a nice and clean quick tip to create a jump menu without a "go" button. Say for example you have a list of items in a database that need to have a details page based upon their "id". This will create a dropdown menu that is auto populated with the most up to date list.
I was working on a link sharing site and I decided to move the tags out of a box on a sidebar and into a menu. Moving tags away from the side required another visual cue to show how often tags are being used. This example assumes that you have created a "tags" table that is associated with your blog entries or links via a shared column. When I create a link for this site, I tag it and insert them into the tags table with the "id" of the link/entry being inserted at the same time. So now that I have the tags associated, I needed to call them out to the menu that I wanted to generate and dynamically change as people tag links.
Recently, I had a request from a client to create an RSS feed of its member's news. I was in luck when I remembered that the members were already entering in their own member news from their members-only area. In addition to adding contact info, I gave them the ability to enter in news and updates about their businesses, and I created a page for site visitors to review the news in one location. I felt like it would be great if I could harness this MySQL generated news list as an RSS feed.
A while back, I was working with a list of companies being displayed on a client's site, and I ran into an obvious issue. Some businesses' names begin with the word "the". Their names are in the MySQL database with the word "the" already in the business name column. I need to sort the business names alphabetically, but I don't want the "Ts" to be populated with all the "the's". Those businesses need to be sorted by the first letter after the "the". I have read that some people like to actually insert the word "the" into a separate column, then sort by the business name and then rebuild the two columns after the fact. These amount of steps seem to be a bit cumbersome, as one would need to check the name upon insertion and split the name if "the" exists, then always build the name again after sorting in the "select" statement.
So there are plenty of ways of displaying your MySQL rows with alternating colors. Here is a very simple (and probably well documented way) to make this work cleanly, but I get asked this often.