Friday, 6 April 2012

How To Increment A Counter In MySQL Based On A Radio Button Click

Asked recently on Formspring:

how to increment count in database on clicking radio button

There are a few ways to go about this. I’ll demonstrate two: a traditional, PHP / MySQL only, postback approach, and a jQuery version that uses AJAX to asynchronously record and update the counts.

Just to be clear: In order to complete this solution, we have to use both JavaScript and a server-side scripting language. We use JavaScript to intercept the user clicking the radio button, but process the fact that the button was clicked on the server.

Also, for the purpose of this tutorial, I’ll assume that the radio button involved is part of a group. That is, we have several radio buttons, all with the same name, but different values, e.g.:

<form id="myform" name="myform" method="post">
	<p>Select a color:</p>
	<label id="l_red"><input type="radio" id="r_red" name="color_name" value="red" />Red</label> (<label id="c_red">0</label>) |
	<label id="l_green"><input type="radio" id="r_green" name="color_name" value="green" />Green</label> (<label id="c_green">0</label>) |
	<label id="l_blue"><input type="radio" id="r_blue" name="color_name" value="blue" />Blue</label> (<label id="c_blue">0</label>) |
	<label id="l_black"><input type="radio" id="r_black" name="color_name" value="black" />Black</label> (<label id="c_black">0</label>)
</form>

Continue reading: How To Increment A Counter In MySQL Based On A Radio Button Click »

Thursday, 15 March 2012

Displaying Selected YouTube Data API Thumbnails On A Web Page Via ASP.NET Web Forms

Previously, I blogged about “Displaying Selected YouTube Video Thumbnails On An ASP.NET Web Forms Page,” when you know the video IDs of the thumbnails you want to hyperlink.

A reader recently asked me how to hyperlink YouTube video thumbnails based on searching for a keyword. I promised to address that, so here goes.

Interestingly enough, searching the YouTube Data API is accomplished in a REST-like manner quite similar to the methodology I used for shortening URLs in ASP.NET via the bit.ly API.

  • Form a simple request URL to the YouTube Data API that contains the appropriate search parameters;
  • Use a WebRequest to send that URL to Google, which returns an XML document with results;
  • Use WebResponse to dump that stream into an XmlDocument;
  • Use XPath and XmlNode‘s SelectNodes method to recursively get the thumbnails from each entry; and
  • Bind up a pile of Hyperlink controls, which are added dynamically to a Panel control.

Sounds more complicated than it actually is. Let’s do it.
Continue reading: Displaying Selected YouTube Data API Thumbnails On A Web Page Via ASP.NET Web Forms »

Sunday, 11 March 2012

What’s Happening This Week On dougv.com

An update on what’s coming to this blog the week of March 11-17, 2012:

Part 3 of using the authorize.net Server Integration Method with PHP. This post will cover the process of checking form inputs for range and proper values; storing the order’s details locally, for fulfillment; and submitting the order for payment.

Later, I’ll post on using Relay Response to finalize orders; as well as a simple system for seeing order details / cleaning up incomplete or abandoned orders.

Part 2 of displaying YouTube thumbnails on an ASP.NET Web Forms page. Specifically, I’ll describe the process of searching for a term via the YouTube Data API, getting the XML result returned by Google, and displaying that information on your page.

Also this week, I am going through old blog entries, cleaning up their appearance, checking code and fixing the taxonomies (categories / tags) in which they belong.

The old syntax highlighting plugin I was using has left some code blocks unreadable, and some of the older code I have written is either superseded by a later post or isn’t really the best way to go about doing things. I’ll be noting that where it’s the case.

That process is proving slow; I am though about 50 posts so far, with about another 200 to go. So bear with me, and thanks!

Thursday, 8 March 2012

Displaying Selected YouTube Video Thumbnails On An ASP.NET Web Forms Page

I received a kind email recently from a reader, thanking me for my article titled “Retaining Values In A Form Following PHP Postback And Clearing Form Values After Successful PHP Form Processing“.

He also asked how he could use the YouTube Data API to search for videos by keyword; display thumbnails of those videos on an ASP.NET page; then either hyperlink to those videos on YouTube, or display them on his page via the YouTube Player API.

I’ll address that specific question in an upcoming post. First, I want to show how to do what the questioner asks if you already know the video IDs of specific YouTube videos you want to show on a page.

If you know the video ID(s) for the YouTube videos you want to display on a page, you can call them directly from YouTube’s image servers, thanks to a predictable URL and naming scheme, and hotlinking.
Continue reading: Displaying Selected YouTube Video Thumbnails On An ASP.NET Web Forms Page »

Wednesday, 7 March 2012

Converting Latitude And Longitude Coordinates Between Decimal And Degrees, Minutes, Seconds

I received an email yesterday from a reader who needed help with implementing my blog post, “Calculating The Bearing And Compass Rose Direction Between Two Latitude / Longitude Coordinates In PHP.”

His problem: He has latitude and longitude coordinates in his database tables that are in degrees-minutes-seconds (DMS) format, rather than decimal format. In other words, his coordinates look more like 55° 45′ 06″ N, 37° 37′ 04″ E than 55.751667, 37.617778.

So, my reader needed a way to convert back and forth between the two.

Fortunately, that’s easily done with a couple PHP functions. And since there’s not a lot that comes up in a Google search about how to make those conversions in PHP (lots of standalone converters, some JavaScript code, little PHP), I’ll fill the void here.

I should also note this function can be used for my other PHP latitude / longitude post, “Getting All ZIP Codes In A Given Radius From A Known Point / ZIP Code Via PHP And MySQL.”
Continue reading: Converting Latitude And Longitude Coordinates Between Decimal And Degrees, Minutes, Seconds »