eKini: Web Developer Blog http://blog.ekini.net PHP, MySQL, Javascript, MVC, Zend Framework, AJAX, jQuery Javascript Framework, Graphics and Design Fri, 04 Jul 2008 02:28:05 +0000 http://wordpress.org/?v=2.5 en jQuery: How to handle radio buttons http://blog.ekini.net/2008/07/03/jquery-how-to-handle-radio-buttons/ http://blog.ekini.net/2008/07/03/jquery-how-to-handle-radio-buttons/#comments Thu, 03 Jul 2008 06:59:35 +0000 Wenbert http://blog.ekini.net/?p=437 Regular < input type="radio" name="empType" value="temporary" /> Temporary Then the jQuery code: (assuming that you have already included the JS file in the header…) $("input[@name='empType']").change( function() { [...]]]> Here is a quick tutorial on how to handle radion buttons using jQuery.

< input type="radio" name="empType" value="regular" /> Regular
< input type="radio" name="empType" value="temporary" /> Temporary

Then the jQuery code: (assuming that you have already included the JS file in the header…)

 $("input[@name='empType']").change(
        function() {
            if ($("input[@name='empType']:checked").val()) {
                alert($("input[@name='empType']:checked").val());
            }
        }
    );
]]>
http://blog.ekini.net/2008/07/03/jquery-how-to-handle-radio-buttons/feed/
Kanye West pissed off. Delay in Bonnaroo. Pearl Jam ended 1 hour late. http://blog.ekini.net/2008/06/26/kanye-west-pissed-off-delay-in-bonnaroo-pearl-jam-ended-1-hour-late/ http://blog.ekini.net/2008/06/26/kanye-west-pissed-off-delay-in-bonnaroo-pearl-jam-ended-1-hour-late/#comments Thu, 26 Jun 2008 03:47:18 +0000 Wenbert http://blog.ekini.net/?p=436 Hey, I love Pearl Jam. If they will have a concert here, I will kill for the tickets. Click here for Kanye’s blog.

]]>
http://blog.ekini.net/2008/06/26/kanye-west-pissed-off-delay-in-bonnaroo-pearl-jam-ended-1-hour-late/feed/
How to get Cross Browser Compatibility Every Time http://blog.ekini.net/2008/06/19/how-to-get-cross-browser-compatibility-every-time/ http://blog.ekini.net/2008/06/19/how-to-get-cross-browser-compatibility-every-time/#comments Thu, 19 Jun 2008 08:39:33 +0000 Wenbert http://blog.ekini.net/?p=435 Yet another CSS post. The second one for today.

Cross-browser compatibility is one of the most time consuming tasks for any web designer. We’ve seen many different articles over the net describing common problems and fixes. I’ve collated all the information I could find to create some coding conventions for ensuring that your site will work first time in every browser. There are some things you should consider for Safari and Firefox also, and IE isn’t always the culprit for your CSS woes.

]]>
http://blog.ekini.net/2008/06/19/how-to-get-cross-browser-compatibility-every-time/feed/
Perfect CSS Layouts. No CSS hacks. SEO friendly. No Images. No JavaScript. Cross-browser & iPhone compatible. http://blog.ekini.net/2008/06/19/perfect-css-layouts-no-css-hacks-seo-friendly-no-images-no-javascript-cross-browser-iphone-compatible/ http://blog.ekini.net/2008/06/19/perfect-css-layouts-no-css-hacks-seo-friendly-no-images-no-javascript-cross-browser-iphone-compatible/#comments Thu, 19 Jun 2008 05:43:36 +0000 Wenbert http://blog.ekini.net/?p=434 I had to post this.

No CSS hacks

The CSS used for this layout is 100% valid and hack free. To overcome Internet Explorer’s broken box model, no horizontal padding or margins are used. Instead, this design uses percentage widths and clever relative positioning.

SEO friendly 2-1-3 column ordering

The higher up content is in your page code, the more important it is considered by search engine algorithms. To make your website as optimised as possible your main page content must come before the side columns. This layout does exactly that: The center page comes first, then the left column and finally the right column (see the nested div structure diagram for more info). The columns can also be configured to any other order if required.
Full length column background colours

In this layout the background colours of each column will always stretch to the length of the longest column. This feature was traditionally only available with table based layouts but now with a little CSS trickery we can do exactly the same with divs. Say goodbye to annoying short columns!

No Images

This layout requires no images. Many CSS website designs need images to colour in the column backgrounds but that is not necessary with this design. Why waste bandwidth and precious HTTP requests when you can do everything in pure CSS and XHTML?

No JavaScript

JavaScript is not required. Some website layouts rely on JavaScript hacks to resize divs and force elements into place but you won’t see any of that nonsense here.

Resizable text compatible

This layout is fully compatible with resizable text. Resizable text is important for web accessibility. People who are vision impaired can make the text larger so it’s easier for them to read. It is becoming increasingly more important to make your website resizable text compatible because people are expecting higher levels of web accessibility. Apple have made resizing the text on a website simple with the pinch gesture on their multi-touch trackpad. So far this trackpad is only available on the MacBook Air but it will soon be rolled out to all of their systems. Is your website text-resizing compatible?

Here is the source.

]]>
http://blog.ekini.net/2008/06/19/perfect-css-layouts-no-css-hacks-seo-friendly-no-images-no-javascript-cross-browser-iphone-compatible/feed/
Importing from Huge CSV Files to MySQL Database and more… http://blog.ekini.net/2008/06/18/importing-from-huge-csv-files-to-mysql-database-and-more/ http://blog.ekini.net/2008/06/18/importing-from-huge-csv-files-to-mysql-database-and-more/#comments Wed, 18 Jun 2008 10:53:19 +0000 Wenbert http://blog.ekini.net/?p=433 The scenario: I am given a huge CSV File dumped thru FTP from some big JDE-ish system everyday. The CSV File is about 15MB or so. The file has around 60,000 lines in it.

What I needed to do is to update a “main” transaction table. Which means I have to lookup each line in the CSV File and then search each row in the transaction table, and then update the row if a match is found. But I figured that it would be crazy to directly handle each line in the file and then go to MySQL for each line.

The pseudo code would look something like this:

1) Open CSV File
2) Loop each line of the file
3) Use $row[0] + $row[1] + $row[2] in a WHERE statement to search the MySQL Database
4) If row is found, update the row in MySQL. If not found, then insert the row.

In case you didn’t notice, steps 2-4 would loop 60,000 times! And note that the mysql table I had already had 300,000 records in it. Can you imagine how much memory and resources this script would eat up if I implemented the code above?

First, opening the big csv file would already consume a lot of resources. On top of that, we have to loop thru each line of the file and do database updates. This would do just fine if you were handling like 100 lines, but 60,000 would hurt a lot.

So what I did was I just let MySQL do most of the hard work. I created a temporary table in MySQL. I made a script that imports the CSV file into the temporary mysql table. After that, I used MySQL queries to compare the temporary table and the main transaction table. I used queries such as these:

$sql = "
INSERT `transactions`
(`fieldA`,
`fieldB`,
`… this means more fields …`,
`… this means more fields …`,
`fieldX`)
SELECT
daily.fieldA,
daily.fieldB,
… this means more fields …,
… this means more fields …,
daily.FieldX
FROM "
.$table_name." daily
WHERE
NOT EXISTS
(SELECT
t.fieldA,
t.fieldB,
t.fieldC,
t.fieldD
FROM transactions t WHERE
t.fieldA = daily.fieldA AND
t.fieldB = daily.fieldB AND
t.fieldC = daily.fieldC AND
t.fieldD = daily.fieldD)
"
;

And for the updates I used something like this:

$sql = "
        UPDATE `transactions` t , `"
.$table_name."` daily
        SET
            t.fieldA  = daily.fieldA,
            t.fieldB  = daily.fieldB,
            t.fieldC  = daily.fieldC,
            t.fieldD  = daily.fieldD,
            /* more fields */

        WHERE
            t.fieldA  = daily.fieldA AND
            t.fieldB  = daily.fieldB AND
            t.fieldC  = daily.fieldC AND
            t.fieldD  = daily.fieldD
        ";
 

So there you have it. Once you have the CSV file imported into a MySQL table, you can basically do anything with it and let MySQL do all the hard work for you.

]]>
http://blog.ekini.net/2008/06/18/importing-from-huge-csv-files-to-mysql-database-and-more/feed/
Visor: A Quake-like / Counterstrike-like console for the Mac http://blog.ekini.net/2008/06/15/visor-a-quake-like-counterstrike-like-console-for-the-mac/ http://blog.ekini.net/2008/06/15/visor-a-quake-like-counterstrike-like-console-for-the-mac/#comments Sun, 15 Jun 2008 12:58:39 +0000 Wenbert http://blog.ekini.net/?p=432 This is probably one of the coolest applications/plugin I have installed on my Mac. It brings out a Quake-like console that comes down from the top of your screen. Talking about convenience! I never liked the Widget Term - takes forever to load. And the Terminal.app just adds more clutter to my screen real estate.

You can download Visor here: http://code.google.com/p/blacktree-visor/

It is free and it is from Blacktree - the creator of Quicksilver, another very cool application for the Mac.

]]>
http://blog.ekini.net/2008/06/15/visor-a-quake-like-counterstrike-like-console-for-the-mac/feed/
Zend Framework without mod_rewrite in Windows http://blog.ekini.net/2008/06/05/zend-framework-without-mod_rewrite-in-windows/ http://blog.ekini.net/2008/06/05/zend-framework-without-mod_rewrite-in-windows/#comments Thu, 05 Jun 2008 06:14:09 +0000 Wenbert http://blog.ekini.net/?p=431 Rob Allen posted an entry in his blog about using Zend Framework in an IIS on WIndows 2003 Server.

Some of our Zend Framework applications have to run on IIS without ISAPI_Rewrite installed. In these cases we need urls of the form http://www.example.com/index.php?module=mod&controller=con&action=act. I couldn’t get this to work out of the box with Zend Framework 1.5, so wrote my own router called App_Controller_Router_Route_RequestVars.

This code obviously only supports what I needed and I’ve only tested it on IIS for Windows 2003 Server, so you may need to tweak to make it do what you want! Feel free to share any fixes :)

]]>
http://blog.ekini.net/2008/06/05/zend-framework-without-mod_rewrite-in-windows/feed/
I am passively looking for a job. http://blog.ekini.net/2008/06/03/i-am-passively-looking-for-a-job/ http://blog.ekini.net/2008/06/03/i-am-passively-looking-for-a-job/#comments Tue, 03 Jun 2008 11:29:48 +0000 Wenbert http://blog.ekini.net/?p=430 I am passively looking for a job. Passively because I do not really want to leave my current job (good benefits, acceptable salary, etc.) BUT I am looking for greener pastures.

At the moment, my eyes are set on Singapore. I figured that it would be easier for me to get a job there compared to the US, Canada or Australia.

Anyways, if you are looking for a PHP Web/Application Developer contact me at wenbert[AT]ekini.net and I will send you my resume.

I learn fast and love being with people who know more than I do. I am very passionate about the Web and Web Development — I been freelancing since college until now, I do not feel tired/bored.

]]>
http://blog.ekini.net/2008/06/03/i-am-passively-looking-for-a-job/feed/
Uploading huge files (i mean huge ones, like 5Gig and upwards). No PHP :P http://blog.ekini.net/2008/05/27/uploading-huge-files-i-mean-huge-ones-like-5gig-and-upwards-no-php-p/ http://blog.ekini.net/2008/05/27/uploading-huge-files-i-mean-huge-ones-like-5gig-and-upwards-no-php-p/#comments Tue, 27 May 2008 08:59:54 +0000 Wenbert http://blog.ekini.net/?p=429 Okay, here is an interesting find.

Although I have never had a client who asked me to upload files larger than 10MB :P , i have always wondered if there was a better way to do it without using PHP. The biggest file I was able to handle using PHP was zipping a directory with lots of files. The zip file created is about 2Gig. PHP ate up a lot of memory! It gobbled up the 4gig ram of the server :P But I found a way around it by using system() calls. I got the list of directories and ran tar inside the system() call. Worked like a charm.

Now back to the large file uploads, the post recommends using Tramline - but I have doubts because it is still in its earl stages. Does know of other solutions to uploading huge files aside from using Tramline?

]]>
http://blog.ekini.net/2008/05/27/uploading-huge-files-i-mean-huge-ones-like-5gig-and-upwards-no-php-p/feed/
Bored. http://blog.ekini.net/2008/05/27/bored-2/ http://blog.ekini.net/2008/05/27/bored-2/#comments Tue, 27 May 2008 01:27:32 +0000 Wenbert http://blog.ekini.net/?p=426

]]>
http://blog.ekini.net/2008/05/27/bored-2/feed/
Booklet Creator :) http://blog.ekini.net/2008/05/23/booklet-creator/ http://blog.ekini.net/2008/05/23/booklet-creator/#comments Fri, 23 May 2008 05:11:37 +0000 Wenbert http://blog.ekini.net/?p=425 http://bookletcreator.com/ There!

]]>
http://blog.ekini.net/2008/05/23/booklet-creator/feed/
A Simple Recommendation System in MySQL http://blog.ekini.net/2008/05/23/a-simple-recommendation-system-in-mysql/ http://blog.ekini.net/2008/05/23/a-simple-recommendation-system-in-mysql/#comments Fri, 23 May 2008 01:51:52 +0000 Wenbert http://blog.ekini.net/?p=424 I am posting this because I know I will need this soon or later.

I have built a simple recommendation for one of the websites I work with. It is only based on social relationships and does not take into account other parameters. The basic idea is if I like an item, select other items liked by people who also like this item and it can be used to build lists of similar items as seen on Amazon or YouTube. If we use as an example people who like movies (tables Person, Movie and many-to-many relationship PersonMovie), this can be expressed in SQL using several joins:

SELECT DISTINCT Movie.*, COUNT(Person.ID) AS PersonCount
FROM Movie
JOIN PersonMovie ON Movie.ID = PersonMovie.MovieID
JOIN Person ON PersonMovie.PersonID = Person.ID
JOIN PersonMovie AS PersonMovie1 ON Person.ID = PersonMovie1.PersonID
JOIN Movie AS Movie1 ON PersonMovie1.MovieID = Movie1.ID
WHERE Movie1.ID = 1 AND Movie.ID != Movie1.ID
GROUP BY Movie.ID
ORDER BY PersonCount DESC
 

First we join movies to people and then backwards to the specific movie with ID = 1 that we want to get similar movies for. PersonCount is the relevance factor — the higher it is, the more people like the movie.

]]>
http://blog.ekini.net/2008/05/23/a-simple-recommendation-system-in-mysql/feed/
Morph Exchange to offer PHP http://blog.ekini.net/2008/05/22/morph-exchange-to-offer-php/ http://blog.ekini.net/2008/05/22/morph-exchange-to-offer-php/#comments Thu, 22 May 2008 07:06:37 +0000 Wenbert http://blog.ekini.net/?p=422 Morph Exchange brought by Mor.ph is “Software as a Service” company that provides applications spaces/platforms for Ruby on Rails and just recently Java. A few weeks back, I emailed them if they have support for PHP. And guess what, they have plans. But they did not give me a specific time when the release date will be — no month, no date, no year — they just said that they will.

But my sources tell me that Morph will release PHP support early next year. Next year is such a long wait! They better come up with PHP support faster or else (*ahem* maybe)  Heroku will beat them to it. PHP has such a wide user-base that whoever comes up with something for it like RoR appspaces in Morph will have lots of users jumping into their band-wagon. Most advanced PHP developers are not satisfied with shared-hosting shit. We want appspaces and SVN. Manual FTP upload is dead.

More info on Mor.ph

]]>
http://blog.ekini.net/2008/05/22/morph-exchange-to-offer-php/feed/
Zend Framework and Dojo Javascript Toolkit Partners http://blog.ekini.net/2008/05/22/zend-framework-and-dojo-javascript-toolkit-partners/ http://blog.ekini.net/2008/05/22/zend-framework-and-dojo-javascript-toolkit-partners/#comments Thu, 22 May 2008 00:23:23 +0000 Wenbert http://blog.ekini.net/?p=421 This has been out like crazy in the PHP Community. All my RSS Feeds for PHP have like 2 or 3 links related to the ZF and Dojo partnership so you have probably heard of this post.

I have known about Dojo a few years back before MVC frameworks were going mainstream. I think Dojo was the  obvious choice for the Zend Framework Team. Dojo is very mature and it has lots of components. I have no idea how bloated it is though. Personally, I would have selected jQuery because I use it :P and second, I love it’s small size and functionality. It is about time is tag along with the others and start using Dojo too :D

]]>
http://blog.ekini.net/2008/05/22/zend-framework-and-dojo-javascript-toolkit-partners/feed/
Zend Framework How To: Handling checkboxes using Zend_Form and jQuery http://blog.ekini.net/2008/05/20/zend-framework-how-to-handling-checkboxes-using-zend_form-and-jquery/ http://blog.ekini.net/2008/05/20/zend-framework-how-to-handling-checkboxes-using-zend_form-and-jquery/#comments Tue, 20 May 2008 05:46:46 +0000 Wenbert http://blog.ekini.net/?p=420 I am sharing this because it took me a while to figure out how to handle checkboxes using jQuery.

First off, let us create a checkbox using Zend_Form.

class forms_CoolForm extends Zend_Form
{
    public function __construct($options = NULL)
    {
        parent::__construct($options);
        $this->setName(‘cool_form’);

        $content = new Zend_Form_Element_Textarea(‘notes’);
        $content->setLabel(‘Content’)
                ->setAttrib(‘class’,‘my_textarea’)
                ->setAttrib(‘id’,‘textarea_id’)
                ->addValidator(‘NotEmpty’)
                ->setRequired(true);
               
             
        $submit = new Zend_Form_Element_Button(‘button’);
        $submit->setLabel(‘Go’)
               ->setAttrib(‘class’,‘my_submit’)
               ->setAttrib(‘id’,’submit_id’);
       
        $ispublic = new Zend_Form_Element_Checkbox(‘is_public’);
        $ispublic->setLabel(‘Allow anyone to view this post?’)
                 ->setAttrib(‘id’,‘is_public’);

        $this->addElements(array($content, $ispublic, $submit));
    }
}
 

The code for the Zend_Form_Element_Checkbox above will generate something like this:

<input type="checkbox" value="0" id="is_public" name="is_public"/>
 

Notice that the value is always Zero? Usually, in jQuery, we get used to getting the value of inputs using:

$(‘#is_public’).val();
 

With that we can do all sort of things. But .val() will always return “0″. So the trick is, you need to check if the checkbox is “Checked” using something like this:

if($(‘#is_public’).is(‘:checked’)) {
    temp_public = ‘yes’;
} else {
    temp_public = ‘no’;
}
//then you send temp_public to other functions — AJAX stuff or DOM modification
 

That’s about it. Basically it just the .is() in jQuery.

]]>
http://blog.ekini.net/2008/05/20/zend-framework-how-to-handling-checkboxes-using-zend_form-and-jquery/feed/