Archive

Archive for the ‘PHP’ Category

PHP Script Library

February 7th, 2009

Script Library
In order to help pay for the site I have thrown togather a great starter library for the noobie php programmer:

PHP Programmer Scripts

Includes:

arrays - An array is a data structure that stores single or multiple values in a single value
dbconnect - Shows how to connect to a MySQL Database
functions - Teaches how to create a function and call it out in a script
for each/while/for loops - how to effectively use loops
forms - How to use a form to send information to the script
helloworld - The basic hey Im here, Im new and I am proud script
if/else/elseif statements - How to selectively choose what the script executes
switches - If you would like to create a simple oop website this is a good thing to know
includes - This will help in organizing all your external files
variables - How to properly use a variable
comments - How to comment out your code

Scripts

Pricing and Consultation

January 22nd, 2009

SEO Implementation

Sometimes it becomes difficult to keep a full time programmer for implementing SEO content on client websites. This can be costly and many times unnecessary. We can help!

Our team, will implement content for technologies sent to the web browser/client such as HTML, JavaScript, CSS, and on the server-side frameworks such as Ruby, PHP, JSP, ASP .NET.

We will ensure that your content is up on your client website within 3 business days of request. Any requests sent after 12pm(EST) will be started the following day. Contact us at Support@actionwerx.com.

Free Initial Consultation

We offer a free consultation to get the basic information about our clients. Please feel free to set an appointment up by sending an email to: support@actionwerx.com

Paid Consultation & Website Reviews
We offer paid consultation and reviews for existing or proposed websites or projects:

Telephone consultation: $20 per call/hour
Written review of website: $599 (Delivered as Word document)

Special: Get two reviews with free consultation — includes two(2) written reviews from design, marketing, usability and search engine optimization viewpoints, plus a one-hour follow-up telephone consultation.

Websites, Blogs & Redesigns

Custom websites start at $5,000 for a logo and 10-page website built with the aim of high search engine rankings, ad copy assistance, image enhance­ment, search engine submissions as needed, and ongoing consultation throughout the project. Pricing not based solely on number of pages.

Custom blog design is usually $1,500 for blog software installation, a logo and a custom design built with the aim of high search engine rankings. Image enhancement and assistance with using your blog are included. We include functionality and user-friendly features beyond the default blog design, such as a site map listing your blog pages and a contact page email form.

A new website (custom web design)
Redesign your website (website redesign)
A new blog (custom blog design)
Redesign you blog
Custom logo (logo design)

Services below are offered with new website addition:

E-commerce (shopping cart/order form)
Domain name assistance (site.com)
Search engine friendly design/SEO
Ad copy writing assistance
Search Engine Optimization
Search engine optimization to gain better search engine positions.
Pricing dependent upon scope of project
Website Updates & Maintenance Packages

*Billed monthly per initial agreement with clients

We can maintain and update your website — as and when you need it:

3 month package — $975 ($325 month)
6 month package  - $1800 ($300 month)
12 month package — $3000 ($250 month)
Web Hosting
Solid, reliable, managed web hosting for your website.
Standard Web Hosting Account: $360 per year plus one-time $50 setup fee

Web Hosting & Website Updates
Need both web hosting and website updates or maintenance?
Standard Web Hosting Account: $360 per year plus the Hourly Maintenance Package selected above (we’ll waive our $50 web hosting setup fee)

PHP

JobberBase SEO Mod

December 7th, 2008

Search Engine Optimization is important if you want to show high in the search engine results pages. Many webmasters pay big money to have a SEO company optimize their websites. I am the lead programmer for such a company and found JobberBase while searching for a job search website that I could utilize for personal use. I fell in love with it right away, but noticed that it did not have SEO tags that were easily editable by the user/webmaster. So I started adding code and came up with the following tutorial, this tutorial will show you how to add SEO capabilities to your JobberBase website.  I tried to make this as simple as possible, so enjoy:

Backup your database and your files before attempting this install

1. Alter db table:

ALTER TABLE `categories` ADD `title` TEXT NOT NULL AFTER `var_name` ,
ADD `description` TEXT NOT NULL AFTER `title` ,
ADD `keywords` TEXT NOT NULL AFTER `description` ;

2. In “admin/_templates/categories.tpl”:

Find:

<a href=”#” title=”Save” class=”saveCategory”><img src=”{$BASE_URL}img/disk.png” alt=”Save” /> Save</a>

Add After:

<label><span>Title:</span><input type=”text” size=”60″ name=”title[{$category.id}]” value=”{$category.title}” /></label>
<label><span>Description:</span><input type=”text” size=”60″ name=”desc[{$category.id}]” value=”{$category.description}”/></label>
<label><span>Keywords:</span><input type=”text” size=”60″ name=”keys[{$category.id}]” value=”{$category.keywords}” /></label>

3. In “_includes/functions.php”:

Find:

function get_categories()
{
global $db;
$categories = array();
$sql = ‘SELECT id, name, var_name
FROM categories
ORDER BY `category_order` ASC’;
$result = $db->query($sql);
while ($row = $result->fetch_assoc())
{
$categories[] = array(’id’ => $row['id'], ‘name’ => $row['name'], ‘var_name’ => $row['var_name']);
}
return $categories;
}

Change to:

function get_categories()
{
global $db;
$categories = array();
$sql = ‘SELECT *
FROM categories
ORDER BY `category_order` ASC’;
$result = $db->query($sql);
while ($row = $result->fetch_assoc())
{
$categories[] = array(’id’ => $row['id'], ‘name’ => $row['name'], ‘var_name’ => $row['var_name'], ‘title’ => $row['title'], ‘description’ => $row['description'], ‘keywords’ => $row['keywords']);
}
return $categories;
}

4. In “admin/page_categories.php”:

Find:

case ’saveCategory’:
$result = $db -> query(’
UPDATE
`categories`
SET
`var_name` = \” . $_POST['url'] . ‘\’,
`name` = \” . $_POST['name'] . ‘\’
WHERE
`id` = ‘ . intval($_POST['category']) . ‘
‘);

break;

Change to:

case ’saveCategory’:
$result = $db -> query(’
UPDATE
`categories`
SET
`var_name` = \” . $_POST['url'] . ‘\’,
`name` = \” . $_POST['name'] . ‘\’,
`title` = \” . $_POST['title'] . ‘\’,
`description` = \” . $_POST['description'] . ‘\’,
`keywords` = \” . $_POST['keywords'] . ‘\’
WHERE
`id` = ‘ . intval($_POST['category']) . ‘
‘);
break;

Then Find:

$last = $result->fetch_assoc();
$db->query(’
INSERT INTO
`categories`
VALUES (
NULL,
\’enter a name\’,
\’custom url\’,
‘ . (intval($last['category_order']) + 1) . ‘
)
‘);

Change to:

$last = $result->fetch_assoc();
$db->query(’
INSERT INTO
`categories`
VALUES (
NULL,
\’enter a name\’,
\’custom url\’,
\’SEO Title\’,
\’SEO Description\’,
\’SEO Keywords\’,
‘ . (intval($last['category_order']) + 1) . ‘
)
‘);

5. In “admin/js/categories.js”:

Find:

‘img/disk.png” alt=”Save” /> Save</a>’,

Add After:

‘<label><span>Title:</span><input type=”text” size=”60″ name=”title[]” value=”newcategory” /></label>’,
‘<label><span>Description:</span><input type=”text” size=”60″ name=”description[]” value=”newcategory” /></label>’,
‘<label><span>Keywords:</span><input type=”text” size=”60″ name=”keywords[]” value=”newcategory” /></label>’,

KEEP FILE OPEN

6. In the same file, “categories.js”:

Find:

name: $(el).parent().find(’input:first’).val(),

Add after:

title: $(el).parent().find(’input:eq(1)’).val(),
description: $(el).parent().find(’input:eq(2)’).val(),
keywords: $(el).parent().find(’input:eq(3)’).val(),

KEEP FILE OPEN

7. In the same file, “categories.js”

Find:

.find(’input:first’)
.attr(’name’, ‘name[' + id + ']‘)
.end()

Add after:

.find(’input:text.eq(1)’)
.attr(’name’, ‘title[' + id + ']‘)
.end()
.find(’input:text.eq(2)’)
.attr(’name’, ‘description[' + id + ']‘)
.end()
.find(’input:text.eq(3)’)
.attr(’name’, ‘keywords[' + id + ']‘)
.end()

8. In the file, “/page_category.php”

[b]NOTE:[/b] [u]Not[/u] the “/admin/page_category.php”

Find:

$html_title = ‘Are you looking for ‘ . $extra . ‘ ‘ . $id . ‘ jobs?’;
$meta_description = ”;

Replace with:

$smarty->assign(’seo_title’, get_seo_title($id));
$smarty->assign(’seo_desc’, get_seo_desc($id));
$smarty->assign(’seo_keys’, get_seo_keys($id));

9. In the file, “/_includes/functions.php”

Find:

function get_categories()
{
*** Removed to save space ***
}

Add After:

function get_seo_title($id)
{
global $db;
$sql = ‘SELECT *
FROM categories
WHERE var_name = “‘.$id.’”‘;
$result = $db->query($sql);
$row = $result->fetch_assoc();
return $row['title'];
}
function get_seo_desc($id)
{
global $db;
$sql = ‘SELECT *
FROM categories
WHERE var_name = “‘.$id.’”‘;
$result = $db->query($sql);
$row = $result->fetch_assoc();
return $row['description'];
}
function get_seo_keys($id)
{
global $db;
$sql = ‘SELECT *
FROM categories
WHERE var_name = “‘.$id.’”‘;
$result = $db->query($sql);
$row = $result->fetch_assoc();
return $row['keywords'];
}

10. In “/_templates/header.tpl”

Find:

<title>{$html_title}</title>
<meta http-equiv=”Content-Type” content=”application/xhtml+xml; charset=utf-8″ />
<meta name=”description” content=”{$meta_description}” />
<meta name=”keywords” content=”{$meta_keywords}” />

Replace with:

<title>{$seo.title}</title>
<meta name=”description” content=”{$seo_desc}” />
<meta name=”keywords” content=”{$seo_keys}” />
<meta http-equiv=”Content-Type” content=”application/xhtml+xml; charset=utf-8″ />

11. In “/page_home.php”

Find:

$html_title = $translations['homepage']['title'] . SITE_NAME;

Replace with:

$smarty->assign(’seo_title’, “This is the homepage title”);
$smarty->assign(’seo_desc’, “This is the homepage Description”);
$smarty->assign(’seo_keys’, “This is the homepage keyword”);

Change that last set of information to set you homepage SEO values.

If you have any questions I will be more than happy to discuss them here. If there are any errors I apologize ahead of time as this was done late last night. My time is tight but figured this one to be useful to people.

Thank you JobberBase for your hard work and efforts. Great App!!

PHP

Fetch Data From MYSQL Using PHP

November 16th, 2008

$query = “SELECT * FROM table”;
$result = mysql_query($query) or die(mysql_error());

while($row = mysql_fetch_array($result)){
echo $row['column1']. ” - “. $row['column2']. “
“;
}

This script will come in handy for the new PHP Programmer. You can fetch information from the database and display it directly to your browser. These scripts are made for simplicity. I may someday write a tutorial but as you know there are plenty of tutorials for a PHP Programmer.

Scripts

Connect to MYSQL database using PHP

November 16th, 2008

mysql_connect(”localhost”, “USER”, “PASS”) or die(mysql_error());
echo “Connected to MySQL”;
mysql_select_db(”DATABASE”) or die(mysql_error());
echo “Connected to Database”;

This is a simple mysql db connection script for the PHP Programmer. All you have to do is replace the USER, PASS and DATABASE with your settings. You may also need to change the localhost with your own setting also. These scripts are intended for educational purposes. Feel free to use them as you need.

OOP Programming is becoming more and more popular among web owners and programmers. Here is an example for getting data from the db using OOP PHP Programming.

Create a table named our_table and create a field for ID. Now enter a coupe id’s in this new table. When you have your db set create the following files.

Name a file include.php and add this:

include ‘function.php’;
require_once(’DB.php’);

$host = ‘localhost’;
$user = ‘your user’;
$pass = ‘your pass’;
$database = ‘your db’;

$dsn = “mysql://$user:$pass@$host/$database”;
$db = DB::connect($dsn, false);

function GetMainContent()
{
global $db;

$result = $db->query(’SELECT * FROM our_table ORDER BY id ASC’);

$selfArray = array();
while ($row = $result->fetchRow(DB_FETCHMODE_ASSOC))
{
$myContent = new ContentBag($row["id"]);
array_push($selfArray, $myContent);
}
return $selfArray;
$db->disconnect();

}

Now create a file named function.php and add this:

class ContentBag
{

public $id;

function __construct($Id=null)
{
if (!empty($Id))
{
$this->id = $Id;
}

}

}

Now in your view file named index.php add this:

include (”includes.php”);
$get_id = GetMainContent();
echo “\n”;
foreach ($get_id as $text)
{
echo “ID: ” . $text->lid . ”
\n”;
}

Scripts

Send Email with PHP

November 14th, 2008

$EMAIL_HEADER = “From: Sender Name <sender@example.com>\r\n”;
$EMAIL_HEADER .= “MIME-Version: 1.0\r\n”;
$EMAIL_HEADER .= “X-Priority: 1\r\n”;
$EMAIL_HEADER .= “X-MSmail-Priority: High\r\n”;

$MESSAGE=”
Hello there,

This is a test message.

From Admin.”;

mail(”recipient@domain.com”, “Example Subject”, $MESSAGE, $EMAIL_HEADER);

Scripts

Link Without Underline Tutorial

November 14th, 2008

At times we will need to create a link without the underline so that it fits better with our text. Its fairly simple here goes:

PHP Programmer
vs.
PHP Developer

Simply add this style to the css stylesheet for anchor tags to be displayed without the underline or to the link code:

<a href=”#” style=”text-decoration:none;”>Link</a>

These decoration values dont work with all browsers but are worth knowing:

none, underline, overline, line-through or blink

Some of you may be looking for a simple way to write a PHP link, well here goes:

echo ‘<a href=”‘. $linkVar .’” style=”text-decoration:none;”>’. $nameVar .’</a>’;

or

echo ‘<a href=”#” style=”text-decoration:none;”>My Link</a>’;

Basics

PHP Programmer Tutorial for Building an OOP Class.

November 13th, 2008

A class is a representation of an abstract data type. What this means to the PHP Programmer is that a class is a schematic for building or constructing our box. It consists of variables and functions that allow that fictional click. With this schematic, we can construct our box exactly how we want.

class Box
{
var $stuff;

function Box($stuff) {
$this->contents = $stuff;
}

function click_box() {
return $this->contents;
}
}

$aBox = new Box(”Alex”);
echo $aBox->click_box();

If we look at our schematic, it has a variable $stuff which is used to remember what is in the box. It also has two functions: Box and click_box.

When we “click” the box, PHP will look for and execute the function with the same name as the class. This is all that the function does, initialize the content of the box when clicked.

The variable $this is used for telling the Box that contents is a variable that belongs to the whole class and not the function. The $stuff variable will only exist inside the scope of the function Box. $this->contents is a variable that was defined to be part of the entire class.

The function click_box will return the value stored within the class’ contents variable, $this->contents.

When the PHP Programmer executes the entire script, the class Box is defined, new constructs or builds the box and passes Alex to its function. This function, which has the same name as the class, will accept the value passed to it and it will also store it within the class variable. This way it will be accessible to all of the functions throughout the class.

OOP

PHP Programmer Introduction to OOP Programming & Creating an Object.

November 13th, 2008

In this tutorial I will explain how to start OOP properly and how to polish your skills as a PHP Programmer.

Object-Oriented Programming (OOP) tutorials can be filled with programming theory and big words such as inheritance, encapsulation and abstraction. You will see that many will explain code by comparing their samples to toasters and car radios, which should help confuse the reader some.

Once you take away all the big words and chest bumping that comes with OOP, you will find it interesting and very helpful. As the years move along you will understand why…

I don’t want this to be another cookie-cutter tutorial that only serves to confuse you.
It is this PHP Programmer’s intention to explore OOP with you in a way that will help you sharpen your skills as a PHP Developer. As I mentioned, over the years you will build a foundation that is strong and helpful to yourself and others.

I want you to imagine a box. This box can be any type of box: Cardboard, Wood, Plastic,Rubber, Small, Large…

Next, imagine that you placed something inside this box: a pebble, a book, a box of matches…

Wouldn’t it be neat to touch the box and then it tells us what is inside of it? Actually, with OOP it is possible!!

$aBox = new Box(”Alex”);
echo $aBox->click_box();

The variable $aBox is equal to our new magical Box(). What is known to PHP Programmer’s in OOP as an object.

Now that we have an active variable($aBox) representing the Box(), we want to put Alex in the box. When we want to “click” the button to tell us whats inside of this box, we will ask using a get_whats_inside function to $abox.

As you figured, we cannot run this code yet. We havent given any directions as to what the click button is supposed to do. You will find this in our next section on classes.

Next Section - Classes

OOP

How To Create A Simple Hello World Script

November 10th, 2008

This is a simple tutorial on how to create a simple PHP Hello World script. This basic knowledge will get the novice PHP Programmer get started with building their first PHP script. First off we will need to create the delimiters for PHP as follows:

<?php

……

?>

This will allow you to paste the code so that the server can begin translating what is between the PHP delimiter tags. Every PHP programmer is very familiar with these delimiters and uses them in most or all of their PHP development.

Our next step will show you how to “Print” or echo the PHP Hello World Text to the browser page.

<?

echo “Hello, World!”;

?>

This is what your output will look like:

Hello, World!

That is it! Our PHP Programmer has shown you how to create a simple Hello World PHP script. Now go try it out on your server and come back and leave a comment as to how it went or other suggestions that you may have.

Basics