Archive for February, 2010

February 25th, 2010

Python – Passing URL Parameters Variable To Python

The following python

script provides a simple

way to get a parameter

from url using the well

known syntax appended

at the end of the url

?parameter=value

In the following example

I am using url_parameter

as a parameter and the value could be any string you want.

Example url for testing purposes will be something like this:

http://erunways.com/examples/cgi-bin/index.py?url_parameter=Somthing

DEMO SOURCE

Here is the content of the source code for this script:


#!/usr/bin/env python# -*- coding: UTF-8 -*-# enable debugging
import cgitbcgitb.enable()
import cgi
print "Content-Type: text/plain;charset=utf-8"
print
print "Your URL parameter is: "
form = cgi.FieldStorage()
print form.getvalue('url_parameter')

February 23rd, 2010

TOP PHP MYSQL SELECT QUERIES EXAMPLES

The SELECT query plays a very

important role when working

with PHP and MYSQL. SELECT

is used when you are trying to

retrieve data from the database.

In this blog I am providing four

examples of how to retrieve that

data in the most efficient and quick

way. If you are planning on using

MYSQL with PHP extension I would

recommend that you become familier

with those examples.

1) The following query retrieves data from one field of the specified row found

in the result set:


$query  = “SELECT itemid, name FROM item ORDER BY name”;

$result_query = mysql_query($query);

$itemid = mysql_result($result_query, 0, “itemid”);

$name = mysql_result($result_query, 0 , “name”);

2) The following query retrieves an entire row of data from result set, placing

the values in an indexed array:


$query  = “SELECT itemid, name FROM item ORDER BY name”;

$result_query = mysql_query($query);

while (list($itemid, $name) = mysql_fetch_row($result_query))

{

Echo “Item: $name ($itemid) <br />”;

}

3) The following query retrieves results solely by numerical indeces:


$query  = “SELECT itemid, name FROM item ORDER BY name”;

$result_query = mysql_query($query);

while ($row = mysql_fetch_array($result_query, MYSQL_NUM))

{

$name = $row[1];

$itemid = $row[0];

Echo “Item:  $name ($itemid) <br />”;

}

4) The following query is almost the same as the previews but uses objects

instead of array:


$query  = “SELECT itemid, name FROM item ORDER BY name”;

$result_query = mysql_query($query);

while ($row  = mysql_fetch_object($result_query))

{

$name = $row -> name;

$itemid = $row -> itemid;

Echo “Item:  $name ($itemid) <br />”;

}

February 18th, 2010

GoDaddy .htaccess PHP RewriteRule RewriteEngine Rewrite rules For SEO URLS

This is a very common issue that

people run into when they decide to

switch to the GoDaddy’s amazingly

cheap hosting. I struggled with the

RewriteEngine after switching to GoDaddy

and finally came up with a simple fix. For

all of you that want to use the rewrite rules

in the .htaccess file for SEO purposes here is

the simple solution I came up with. By

default if you have a rewrite rule that has

the same name as the php file you will run

into trouble. The following example takes care of it.


########## Begin - Rewrite rules For SEO urls ##
#
Options -MultiViews
Options +FollowSymlinks

RewriteEngine on
#
#
#
#URL Rewriting for Videos
RewriteRule ^videos videos.php [nc]
########## End – Rewrite rules For SEO urls ##