Monday, June 29, 2009

Javascript - Elements by Class

// JavaScript Document
// If Core doesn't exist, make it an empty object
Core = Core || {};
Core.getElementsByClass = function(theclass) {

var matchedArray = [];

if (typeof document.all != "undefined") { //Explorer 5.x and other browsers only
elementArray = document.all; //support document.all to retrieve all document
} //elements
else {
elementArray = document.getElementsByTagName("*");
}

//the following variable uses RegExp to find a particular string pattern.
//in this case, it is the name of the class we are searching for.
var pattern = new RegExp("(^| )" + theclass+ "( |$)");

var matchedArray[]; //to hold matched class name elements

//now we need to search through all the collected elements in the document and
//see if they match the class pattern described in the var pattern
for (var i=0; i if (pattern.test(elementArray[i].className)) {
matchedArray[matchedArray.length]=elementArray[i];
}
} //end for loop

return matchedArray;

} //end Core.getElementsByClass


alert("Hello there");

Back and working with PHP/MySQL and some Javascript

Using one of those free hosting sites that allow PHP/MySQL - http://www.atbhost.com in particular - I've started working on php scripts. I've also found Javascript to be helpful.

Monday, November 24, 2008

Back from a long Hiatus

It's been awhile since I last worked on this project. (Okay, so I didn't really get far) I am determined to finish it though. I'm back in action! I just dusted off Apache 2.2 and started it up and it failed to start. I just clicked on the services button (it can also be reached via press ing Start->Run-> then entering services.msc into the field and clicking 'OK'), right clicked on Apache2.2 in the list of services and selected properties. The drop down list under the Startup Type section was changed to disabled. I just changed it to automatic, clicked 'OK' and then clicked Start on the upper left of the services window and I was good to go.

Tuesday, May 1, 2007

My PHP Finally Creates A Database

I finally created a database using PHP. I just followed the example closely:
<?php
$link = mysql_connect('localhost', 'root', '*****');
if (!$link) {
die('Could not connect: ' . mysql_error());
}

$sql = 'CREATE DATABASE dental_office';
if (mysql_query($sql, $link)) {
echo "Database dental_office created successfully\n";
} else {
echo 'Error creating database: ' . mysql_error() . "\n";
}
?>


Using a string variable to capture the connection tag makes it a lot easier to call in the future. Soon I will be able to create code that allows patients to fill out information online and sent it to the dental office immediately. (This happens to be a very big convenience as I work at a dental office where that is needed :p)

My code went off without a hitch. I even found there are ways to connect directly to specific ports and sockets by replacing localhost with the site's name or IP. I only have one server and one data base so I don't think I'll be needing that I'm happy to finally be on track. Variables are running well, I'm connecting to MySQL through PHP, I've even gotten PHPMyAdmin to create tables for me on the database.

Everything is looking up for Milhouse, er Jay.
Hey! I just realized this is my 10th post! I've also reached another official benchmark. My Blog appears across two months, April and May!

To celebrate, here is Champagne!

Creative Commons License, photo from FreePhotoBank.org

Well I don't drink, but even non-drinkers can appreciate the majesty of Champagne, France!

Learning PHP-MySQL: Trudging Along

In my search for code I entered mysql php test on my Google search bar and the first result was PHP/MySQL Tutorial - Part 1 by freewebmasterhelp.com. Feeling lucky (pun intended) I clicked through and upon reading was convinced that a simple <?php phpinfo(); ?> was all I needed to check if MySQL was working properly. The tutorial tells me if MySQL is mentioned on the page then it has been installed. I see MySQL and MySQLi and decide to stop right there. Then I decide to start up again.
I see Part 4 - Displaying Data and decide to give their code a test drive. I get error messages th
at I do not even want to go into so I am going to install PHPMyAdmin instead.
Must...procrastinate.....longer.
PHPMyAdmin is an administrative tool that makes handling MySQL easier.

After downloading PHPMyAdmin I unzipped the contents into c:/myserver and entered http://localhost/phpMyAdmin-2.10.1-all-languages-utf-8-only/scripts/setup.php in my web browser.

Look at all these wonderful toys.

So after going through Servers and adding my own with info I found on <?php phpinfo(); ?> I went back to the drawing board and started echoing examples from the official PHP Manual. I have been able to connect to MySQL with the following code which I derived from their section on mysql_connect()
<?php
//Example 1352. mysql_connect() example
//http://us.php.net/manual/en/function.mysql-connect.php
$user = "root";
$password= "*****";
$link = mysql_connect('localhost', $user, $password);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>
I am able to manipulate databases using PHPMyAdmin. Unfortunately, I still can't create a database using PHP. At least I know it is possible to connect.

Sunday, April 29, 2007

Testing MySQL: Installing MySQL, configuring php.ini and removing deprecated tags.

Previously, I was testing MySQL and could not get a page to load at all. I was receiving the error message:
PHP Fatal error: Call to undefined function mysql_connect()

I added a couple extensions in php.ini and just now found a new error message appeared.
PHP Warning: PHP Startup: Unable to load dynamic library './php_mysql.dll'
- The specified module could not be found.\r\n in Unknown on line 0

It was not looking in the right directory, rather I never specified where to look. Now I have tried setting the extension directory with extension_dir = "c:\php\ext" in php.ini, I have received a new error message. (I'm getting somewhere!)
PHP Fatal error: Call to undefined function mysql_create_db() in
C:\\myserver\\test_mysql.php on line 33

I have a feeling I'll be doing a lot of php.ini configuring. After searching for the previous error in google I came across a list of emails in the archives of Neohapsis.com where someone mentioned that mysql_create_db() is deprecated. So much for using older tutorials. I searched for mysql_create-db() deprecated on Google and came across a comment on the manual that says mysql_query() should be used instead.

I went back into my test file and changed the two instances of mysql_create_db to mysql_query and finally something appears on the page. Unfortunately the variables are not appearing to be saved. Oh error looooog!,
PHP Warning: mysql_fetch_array(): supplied argument is not a valid MySQL
result resource in C:\\myserver\\test_mysql.php on line 66

Fetch doesn't have anything to fetch so it is reporting an error. I think I'll find someone elses file to test MySQL with (ignores the little voice saying "Make one yourself you lazy oaf")