Blog

Newest Post
Blog Archives
Blog Categories

Portfolio

3D Models
Banners
Brochures
Business Cards
Custom Programming
Environments
Flash Projects
Game Design
Image Altering
Web Design

About

Resume
Recommendation Letters

Contact

July 18, 2008

Creating a Pop Up Window with Javascript

Filed under: JavaScript,The Coding World — admin @ 10:37 am

Here is how to create a simple pop-up window using java script.

This will create a pop-up window on page load:
Place this javascript in the <head>  section of the webpage.

View Code JAVASCRIPT
onload = function () {
  PopUpURL    = "page.php";
  PopUpLeft   =  100;
  PopUpTop    =  100;
  PopUpWidth  =  600;
  PopUpHeight =  300;
   popO='left='+PopUpLeft+',top='+PopUpTop+',width='+PopUpWidth+',height='+PopUpHeight
  window.open(PopUpURL,'nrc',popO);
}

Here is how to create a Pop Up Window from a link:
Place the following code in the <head> section

View Code JAVASCRIPT
var newwindow;
function popup(url)
{
newwindow=window.open(url,'name','height=500,width=333');
if (window.focus) {newwindow.focus()}
}

This part goes in the link tag:

 <a href="javascript:popup('poppedexample.html');">Pop it</a>

July 1, 2008

Creating a perminent redirect in the .htaccess file

Filed under: .htaccess — admin @ 9:32 am

A search engine friendly way to redirect an old page to a new one is to add the following line in your .htaccess file.

“Redirect permanent /old-page.html http://www.newsite.com/new-page.html”

Direct the ErrorDocument 404 to a webpage

Filed under: .htaccess — admin @ 9:31 am

If you would like the “404 Webpage Not Found” error to redirect to another page on your website – just simply create (or edit) your .htaccess file. This file should be at the root level of your site’s directory where your root webpages are stored.

Add the following line: “ErrorDocument 404 /pagename.html”

May 23, 2008

PHP Dynamic Variables

Filed under: PHP,The Coding World — admin @ 9:21 am

Let’s say that you have a bunch of data in a recordset and you want to populate that data into a list of variables. In my example we will draw 20 items from a players inventory from a MySQL table which stores all the items for a player in rows we call “slot_1, slot_2, slot_3, … all the way to 20″. So when we pull all of the items from the MySQL table we want to assign them to variables respectively. For example, our variable of “slot_1″ that we are creating will equal “slot_1″ from the MySQL table.

//the recordset
 
mysql_select_db($database_connect, $connect);
$query_Recordset1 = sprintf("SELECT * FROM inventory WHERE player_id='$hero_id'");
$Recordset1 = mysql_query($query_Recordset1, $connect) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
 
//Loop and assign the variables accordingly
 
$i=1; do {
${"slot_{$i}"} = $row_Recordset1['slot_'.$i];
$i++;} while ($i&lt;=20);

If we were to update the MySQL table with a dynamic variable, it would look like this.

 
$updateItemSQL = sprintf("UPDATE inventory SET slot_$slot=%s WHERE player_id='$hero_id'",
GetSQLValueString($new_item, "int"));

March 25, 2008

MYSQL JOINS

Filed under: PHP — admin @ 6:07 am

MYSQL Joins are confusing, to say the least. I was successfully able to do one a few different ways and thought it be best to write down how I did it so I can do it in the future.

What I had was two different tables. One table was xcart_products_categories which stores all “productid” and matches them with which category they go to “categoryid”. The other table which was xcart_products had the “productid” and all of its information.

So if you are wanting to list all of the products from a certain category only, which I needed to list all the charms in the charms category (#344), you would need to use a MYSQL join.

Here is how I did it:

View Code MYSQL
SELECT xcart_products.*, xcart_products_categories.*
FROM xcart_products_categories 
LEFT JOIN xcart_products ON xcart_products_categories.productid = xcart_products.productid  
WHERE xcart_products_categories.categoryid='344'

There is a reason I did a LEFT JOIN. If I did a regular JOIN or an INNER JOIN then I would only get the products from “xcart_products” that matched on the categoryid, but I even wanted the ones that may have had a blank productid just in case I was retarded and forgot to mark one.

JOIN three tables

Now I needed to join three tables. The actual price of the product was in a third table called “xcart_pricing”. Here is how I joined all three tables.

View Code MYSQL
SELECT xcart_products.*, xcart_products_categories.*, xcart_pricing.price
FROM (xcart_products_categories LEFT JOIN xcart_products ON xcart_products_categories.productid = xcart_products.productid)
INNER JOIN xcart_pricing ON xcart_products.productid = xcart_pricing.productid 
WHERE xcart_products_categories.categoryid='344'

I did a standard INNER JOIN for the pricing table because I only needed the ones with for the productid that matched in both tables. I didn’t need any extras.

March 19, 2008

Update a mysql database and retain special characters

Filed under: PHP — admin @ 10:33 am

To update a mysql database and retain special characters such as possessiveness, or if you are updating a database where you field contains any special characters you will need to use the “addslashes” function to your mysql statement.

$updateSQL = sprintf("UPDATE db_table SET db_field=%s WHERE db_row='".addslashes($title)."'",
GetSQLValueString($value, "text"));

February 22, 2008

Reset a php Recordset

Filed under: PHP — admin @ 4:34 pm

When you run a recordset through a loop, you will not be able to re-run the recordset further down in the same page. Here is how to reset the recordset so you can use it again on the same page. Just place this code after your loop. Change the “$Recordset” to your recordset’s variable.

if (mysql_num_rows($Recordset) > 0)  {
mysql_data_seek($Recordset, 0);
$row_Recordset = mysql_fetch_assoc($Recordset);
}

November 22, 2007

Get Page Name from Web Address using PHP

Filed under: PHP — admin @ 12:55 pm

This syntax is useful for dynamically creating web pages. For example with PHP you can recognize the page you are on and then display a proper header for that page.

i.e. let’s say the weblink is “www.page.com/form.php”

$page_name =  basename($_SERVER['PHP_SELF'],".php");

The “$page_name” would equal “form” for the .php was dropped.

Capitalize the First Letters in a String with PHP

Filed under: PHP — admin @ 12:48 pm

This is a useful syntax just another one that just slips my mind.

$string = 'john doe';
$new_string = ucwords($string);
echo $new_string; //John Doe

Character Replace within a String using PHP

Filed under: PHP — admin @ 12:45 pm

Replacing a character within a string is easy and very useful. The only problem is I have the hardest time remembering the syntax so I figured I would post it here.

$string = 'test-data';
 
//Remove the "-" and replace it with a space
$new_string = str_replace('-',' ', $string );
 
echo $new_string; //test data
« Previous PageNext Page »
© - Digital Epiphany Designs, Online Portfolio for Web Design, Custom Programming, Grapic Design and Game Design.