Category Archives for Programming

WordPress – Creating a Simple mySQL Query Plugin

Simple PHP WordPress Plugin to Query Database

Creating a plugin for WordPress is relatively simple and getting information back into your blog post or page. Take a look at the following video to cover the basic steps of creating a plugin. Once you understand how to create a basic plugin, we will dive into creating a plugin to query a mySQL Database.

 

WordPress Creating your first simple wordpress plugin

Product_Query.php

Below Plugin lists how to make a simple DB query plugin. Below is also a 2 hour video of the process of creating the plugin thru trial and error

 

Plugin Build Video showing the process of creating a mySQL Plugin for WordPress

 

db_config.php

Script is just the basic DB configuration so you don’t have to store your user and password in your main script

 

 

You may also be interested in the Amazon API Post or the PHP Email Form

 

Please go ahead and leave me a comment…

I would love to hear from you and if I have missed anything, let me know and I will add it.

I would appreciate you linking back to my blog if you found any of these articles useful.

PHP – Infinite Scroll Pagination using JQuery Ajax Example

Infinite Page Scroll Logo

 

How to make a site with infinite page scroll

All credits for the code go to these guys at ItSolutionStuff.com for the code. The code is good, but it has an issue if you scroll too fast with the browser, it gets confused and duplicates lines which makes things pretty messy quickly. I found a fix on Stack Flow which corrects the problem, so I am going to post the new code to use. Most of the code is the same except for the AJAX stuff, there is a bunch of changes we need to make.

 

You can see the scroll in action here CoolHipThings.com

 

Step 1 – Create the Posts table

 

Step 2 – Create the DB Configuration file

db_config.PHP

 

Step 3 – Create index.PHP

index.PHP

 

 

Update to JavaScript in index.PHP

Notice all the loaded = statements. Also the if statement had to be updated. You can read the original StackOverFlow Article here

index.php

 

Step 4 – Create data.PHP

data.PHP

 

Step 5 – Create loadMoreData.PHP

loadMoreData.PHP 

 

 

You may also be interested in the Amazon API Post or the PHP Email Form

 

Please go ahead and leave me a comment…

I would love to hear from you and if I have missed anything, let me know and I will add it.

I would appreciate you linking back to my blog if you found any of these articles useful.
 

Creating a YouTube Pop Up Window (onClick)

YouTube.com Logo

 

Creating a YouTube Popup Window

Create a small pop window with a youtube video with minimum code requirements.

 

Youtube Pop Up Example

 

If you want to see it in action, click here and then click on the Watch Video Link

 

Javascript Code

Please this code in between your html header tag. Original Post can be found here on StackOverflow

 

HTML Code

 

My Changes

I made slight changes to the code as I wanted to be able to input a youtube url. This doesn’t seem to work with the shortened version of the youtube URL

 

 

My $post variable would equal a field from my DB, notice I have added the embed into the URL

https://www.youtube.com/embed/OZ92BgOqq28

 

You may also be interested in the Amazon API Post or the AWS Cloud as Personal WebServer Post

 

Please go ahead and leave me a comment…

I would love to hear from you and if I have missed anything, let me know and I will add it.

I would appreciate you linking back to my blog if you found any of these articles useful.

PHP Use the Amazon API to Get Product Prices

Amazon Price API

Getting prices using the Amazon API

I am going to show you how to use the script below to get a price using the Amazon API, the easiest way. I appreciate you linking back to my website if you find this useful.

Here is a great script to grab the prices from the Amazon. I found this well-written script by this SITE. What I found is that it printed out the raw API information which I couldn’t use.

Then I found this website and a post from Alejandro which helped explain how to use it.

 

The just of it is to use the following call to get the price for the product you provide from the $response = getAmazonPrice(“com”, $asin);

Snippet of code to grab the price from the $response

Notice the return $response[‘price’]; This will deliver the price you are looking for for the product. $response[‘code’]; will provide the currency such as USD or CAD

I think take the price and update my database tables daily with the Amazon prices. I am not sure if the prices have to be done in real time but figured this would just slow down my website, so I thought updating maybe once or twice a day would be sufficient.

 

Amazon.PHP API get Price code

 

Updating DB with Prices

Populating your mySQL Database with the Prices which you can query later, I run this nightly, you may find this useful.

I just run it on the command line, php -f price.php. You don’t need the html.

Price.PHP

Please go ahead and comment…

I would love to hear from you and if I have missed anything, let me know and I will add it.

I would appreciate you linking back to my blog if you found any of these articles useful.

 

You may also be interested in the Email Form Post.

PHP Email Contact Form

Bootstrap Contact Form

If you one of those guys struggling to get the PHP Mail to work like it should, take a look at this form. I have used a PHP/HTML Form and perl to send the actual mail. I couldn’t get the php mail to work, no matter what I did to the php.ini. I had no issues sending mail from the command line, just not from a php file. I decided to use perl to send the actual mail which worked just fine, although I shouldn’t have had to go to perl to send the mail. I personally think the PHP Mail implementation is seriously broken.

I got the original form here, by Pavel Malos, it’s worth checking it out as it may work for you. I like the look of the form with the curved boxes vs the general boring boxes.

 

You going to need the following to make this work

Contact Form

What the final contact form will look like, you can play around with the background colour.

Image of What the form box looks like

Contact.PHP

This is the final PHP/HTML code that displays the form, make sure you grab the css file as well or use the link below in your code and don’t forget to get the cgi-lib.pl. You can see this form in action at coolhipthings.com

Mail.CGI

This is my mail.cgi I pulled from my scripts and you can test it from the command line by running perl mail.cgi and it should run with no errors.

 

CGI-LIB.PL

This is an old but reliable cgi library, I searched and doesn’t seem to be readily available on the internet. There are probably some other libraries you can use instead that are more modern, but I have been using this one for over 10 years and know it works and is solid.

 

Please go ahead and comment

I would love to hear from you and if I have missed anything, let me know and I will add it.

 

You might also want to take a look at my review of creating a Personal Webserver on AWS Cloud.