Showing posts with label developer php. Show all posts
Showing posts with label developer php. Show all posts

Thursday, October 27, 2011

Netbean chinese character problem

Probably happen in my pc (Window XP Home)
Create a new .php file, then when I paste the chinese character it show all right

Problem rises when the display (like export into PDF)
This is because the character encoding for the netbeans (NetBeans IDE 6.9.1) is not UTF-8

So simply fix this problem by changing the file type. As for me, I'm using notepad2 to change to file type into UTF-8. Below is the example


http://localhost/search/

Tuesday, September 6, 2011

cakephp check database configuration exist and connection alive valid

Keyword
Check cakephp database configuration exist
Check cakephp database can be connect

In cakephp you need to configure the connection
The configuration file was in app/config/database.php

Inside the file, you can see 2 variable which is 'default' and 'test'

By default is 'default' but if you want to use 'test' in the controller for example, you need to call it like this
$this->Mmodel->useDbConfig = 'test';
 

Problem arise is, can we connect to 'test' without problem?

So, here is the code I made. Been googling it and quite hard to found the solution, thus I'm putting this in my blog. lol...

This code will check
- Does the configuration 'test' exist
- If the configuration exist, does the database connection valid

If these 2 condition is pass, you can only have SQL Syntax Error like selecting table that does not exist

So here is the code (its free)
//Checking is done by connecting with the  database
if (class_exists('DATABASE_CONFIG')){
    $dbConfigName1 = 'test'; //<-- PUT YOUR DATABASE CONFIG VARIABLE NAME HERE

    $dbConfig1 = new DATABASE_CONFIG();
    //pr( $dbConfig1);                    

    if( isset( $dbConfig1->$dbConfigName1)){                       

        //Now check wether the database configuration, its alive!
        //pr( $dbConfig1->$dbConfigName1);
        $dbTemp1 =& ConnectionManager::getDataSource($dbConfigName1);

        if( $dbTemp1->isConnected() == true){

            //Means database exist and you can use it
            echo "DATABASE CONFIG '$dbConfigName1' EXIST AND MANAGE TO CONNECT";
        }
        else{

            //Database configuration exist, but cannot connect to the database
            echo "DATABASE CONFIG '$dbConfigName1' EXIST BUT FAILED TO CONNECT";
        }
    }
    else{

        //The database configuration does not exist
        echo "HAS NO DATABASE CONFIGURATION WITH NAME '$dbConfigName1'";
    }
}
else{

    //The database.php file not even exist. How can this be? IMPOSIBIEBERBEL!
    echo "CANNOT FIND THE 'database.php' CONFIGURATION FILE";
}

Reference
http://bakery.cakephp.org/articles/T0aD/2009/07/08/handle-database-connection-errors
http://debuggable.com/posts/handling-database-connection-errors-in-cakephp:480f4dd5-9570-421a-a04d-43cdcbdd56cb

Tuesday, June 7, 2011

Get web server application folder name WAMP LAMP

Let say you have a web application like wordpress in your localhost web server (WAMP)
The wordpress name is 'wordpressasipo'

Thus, the path to these is
C:\wamp\www\wordpressasipo

While in localhost it will be
http://localhost:80/wordpressasipo

The problem here is how the get the 'application name' (which is wordpressasipo) dynamically
Means even after you change the folder name (into wordpressasipo1 for example) it will still work

Here is the solution, quite usefull and I cant get this in quick googling

basename( realpath('.'));

Thus, if your application was in C:\wamp\www\wordpressasipo will return string wordpressasipo 

Friday, May 6, 2011

phpmyadmin too many table in database cause pagination

Too many table will automatically create a page pagination

If you are using phpmyadmin version 3.3.9, and your table in the database is alot (about 600 table)
then the page number will appear (these called pagination in web term, I think)

These page number is quite annoying since I remember some important table name from the database and having a page number slow me down cause I search the table name by using "Ctrl + F" from Google Chrome
Thus, when I Ctrl+F and type the table name, it does not appear...

Note that phpmyadmin work best when using Google Chrome (because of its "Ctrl +F" function) compared to Firefox, Opera and Safari (I have test them all and these in only an opinion)

So, the reason behind all my problem lies in the default config @global integer $cfg['MaxTableList'] where it will do a pagination for database table (set default into display 250 table in a page)

The reason, change this and all problem solved!

So, regarding on which IDE did you use in programming, search globally (in whole project) for string name @global integer $cfg['MaxTableList']

If you are using windows with WampServer Version 2.1, the phpmyadmin program is located at C:\wamp5\apps\phpmyadmin3.3.9

If you are lazy or not have a capability to find the whole project, here is the location
C:\wamp5\apps\phpmyadmin3.3.9\libraries\config.default.php (on line 501)

thats all, hope its usefull

Thursday, March 24, 2011

Disable history back if pressing backspace

If you press backspace on the website page (but not on textbox) it will go to its previous page
This is to disable them

Taken from here, then I modified
http://www.sitepoint.com/forums/javascript-15/disable-back-javascript-168890.html

These is javascript coding
//DISABLE "GO BACK TO PREVIOUS HISTORY" IF PRESSING "BACKSPACE"
if (typeof window.event != 'undefined')
    document.onkeydown = function()
    {
        if( event.keyCode == 8){
            theEvent = event.srcElement.tagName.toUpperCase();
            if( theEvent == 'HTML'){
                return false;
            }
            else if( theEvent == 'INPUT'){
                theType = event.srcElement.getAttribute('type').toUpperCase();
                //alert(theType);
                switch(theType){
                    case 'TEXT':
                        return true;
                        break;

                   default:
                        return false;
                }
                return false;
            }
            else{
                switch( theEvent){
                    case 'TEXTAREA':
                        return true;
                        break;

                    default:
                        //alert('Backspace pressed on ' + theEvent + ', return false');
                        return false;
                }

                return false;
            }
        }
    }
else
    document.onkeypress = function(e)
    {
        if( e.keyCode == 8){
            theEvent = e.target.nodeName.toUpperCase();
            if( theEvent == 'HTML'){
                return false;
            }
            else if( theEvent == 'INPUT'){
                theType = e.target.getAttribute('type').toUpperCase();
                //alert(theType);
                switch(theType){
                    case 'TEXT':
                        return true;
                        break;

                   default:
                        return false;
                }
                return false;
            }
            else{
                switch( theEvent){
                    case 'TEXTAREA':
                        return true;
                        break;

                    default:
                        //alert('Backspace pressed on ' + theEvent + ', return false');
                        return false;
                }

                return false;
            }
        }
    }

Saturday, March 19, 2011

javascript detect and capture keyboard keycode

These is how to capture what user have type in their keyboard
The captured data is the "keycode" which is an integer

Like 'enter' key, the code is 13

Some data that I have discover and might be usefull to others and myself
These was tested and the same for IE, Firefox, Google Chrome and Safari
a until z keycode 97 until 122
A until Z keycode 65 until 90
0 until 9 keycode 48 until 57


Lets get to the code

function whatKeyCodeHaveIType( theEvent)
{
    charCode = (theEvent.which) ? theEvent.which : theEvent.keyCode

    theTempoElement = document.getElementById('thisiswhatyouhavetpye');
    theTempoElement.innerHTML = theTempoElement.innerHTML + ', ' + charCode;

    //This is to ignore "ENTER" key. Its usefull to prevent a form from autosubmit if you press enter
    return (charCode != 13);
}

//Later in HTML, use these
<input id="whatyouhavetype" style="width: 500px;" onkeypress="return whatKeyCodeHaveIType(event);"/>
<textarea id="thisiswhatyouhavetpye" cols="70" rows="5"></textarea>

Type something here :


javascript detect finish typing keystroke delay autocomplete

Okay, the title might be confusing but here is what these about

You want to execute certain function, right after the user has finish its typing

These is different from normal 'keypress' or 'keyup' or 'keydown' event detection because these will execute a function every key is press. Right now you want to give certain delay so that the function only execute at the right time

These is important if you developing an autocomplete (AJAX) because you dont want to execute the script too much. Typing "HELLO" means you do the SQL statement 5 times
H
HE
HEL
HELL
HELLO


But if you do a proper keystroke delay (detect user finish typing) you will only execute the SQL statement once
HELLO


Cut to the story, hopefully understand what I was trying to explain at the top

Here is the function
var typingTimer;
var doneTypingInterval = 700;

//Detect keystroke and only execute after the user has finish typing
function delayExecute()
{
    clearTimeout(typingTimer);
        typingTimer = setTimeout(
        function(){somethingExecuted('typesomethinghere')},
        doneTypingInterval
    );

    return true;
}

function somethingExecuted( theInputName)
{
    alert( "You have type '" + document.getElementById(theInputName).value + "'");
}

//Later in the HTML code, put these
<input onkeypress="return delayExecute();" id="typesomethinghere">

Type something here : (These input id is 'typesomethinghere')
The script will only execute after you finish typing. By assuming when you have stop typing for 0.7 seconds, means you have finish typing

Type something here :
These is what happen if you dont use the script



Monday, March 14, 2011

Install LAMP on Ubuntu

These is a double posting, the original was from here http://asipi.blogspot.com/2009/10/haih.html

I write it back here because the title and here will be the latest updated place
(Yes I do update these post again if got any changes)


1

Install apache & mysql & phpmyadmin : http://www.howtoforge.com/ubuntu_lamp_for_newbies

*Update 23 Jan 2010
My Software source was from Malaysia and it has problem!. So it set my source to "Main Server" (Software source download from Main Server)


2

Enable the www folder
This will make your be able to add new folder into the localhost
using terminal :

sudo chmod -R 777 '/var/www'

Please note that /var/www is your root for the website
/var/www/smellynomore means http://localhost/smellynomore


3

You will realize that u cant open the phpmyadmin on http://localhost/phpmyadmin
This is because when you see inside /var/www there is no "phpmyadmin" folder

Solve it by referring here http://ubuntuforums.org/showthread.php?t=1036836

Solve by doing this in terminal :

sudo ln -s '/usr/share/phpmyadmin' '/var/www'



4

Additional configuration for the mysql

When you first time install the mySQL, everything is working fine.
But then, after you reboot the PC, the mySQL server cant start.

The mySQL configuration file will be missing after boot
After some haih...checking, you will realize that file inside "/var/run/mysqld" is missing

I solve it by this link, http://ubuntuforums.org/showthread.php?t=386056
Try to chown to "mysql.mysql" if owned by root, and give it a 755
It is because of the folder write permission

How to chown and chmod, please note that I dont know what happen to security issue when I done this, just want to 'make it work!'

sudo chown -R asipo '/var/run/mysqld'
sudo chmod -R 777 '/var/run/mysqld'




5

Load the mod_rewrite module
I google here to solve it http://ubuntuforums.org/showthread.php?t=255556&page=2

Using terminal :

sudo a2enmod rewrite
sudo gedit /etc/apache2/sites-enabled/000-default


After that change AllowOverride None to AllowOverride All

Then, restart Apache

sudo /etc/init.d/apache2 force-reload



6

Additional, command to mySQL server (check, start, restart and stop)
http://abbysays.wordpress.com/2008/05/20/how-to-startstop-mysql-server-on-ubuntu-804/

Setting up the cakePHP 1.2.5
There will be 2 problem
1. Warning (512): /var/www/cakemake/app/tmp/cache/ is not writable [CORE/cake/libs/cache/file.php, line 262]
2. Your tmp directory is NOT writable.

Solve by : Once again chmod 777 is not secure, yeah!

sudo chown -R asipo '/var/www/smellynomore/app/tmp'
sudo chmod -R 777 '/var/www/smellynomore/app/tmp'




7

Install x-debug
http://ubuntuforums.org/showthread.php?t=525257

EDITED #2 (Feb 2011)
I dont know why lately my xdebug does not working. So I edit the php.ini file
I make the all to be "Deleopment mode" because its defaulted to "Production mode"
So I guess that is the reson, plus use this on ERROR Report
error_reporting = E_ALL & ~E_DEPRECATED & ~E_NOTICE


8

After that, it will read index.html
I dont know how to change it for the thing to refer into index.php

However, this is the index.php code (simple version of mine)

<p><b>Localhost</b></p>
<p>Select folder or file to navigate</p>

<?php

echo "<ul>";
if ($handle = opendir('.')) {
    while (false !== ($file = readdir($handle))) {
        if ($file != "." && $file != "..") {
            echo "<li><a href='$file'>$file<a></li>";
        }
    }
    closedir($handle);
}
echo "</ul>";
?>
If you have been wandering how I put this code into this blog. This is the place http://asipi.blogspot.com/2011/01/write-blog-post-using-tinymce.html

Thus when you open your http://localhost/index.php will get something like this


9

phpMyAdmin login might be annoying, solve it from here http://asipi.blogspot.com/2011/02/disable-phpmyadmin-login.html


10 Edit 28 Nov 2012
To install CURL. I follow this website http://buzznol.blogspot.com/2008/12/install-curl-extension-for-php-in.html

Basically, in terminal type : sudo apt-get install curl libcurl3 libcurl3-dev php5-curl
Then restart the LAMP server, then test it using var_dump(curl_version()); make sure to put -pre- html tag around it

Note that to restart the server. Using this command seems to be even better. Feel like it was relly restarting... sudo /etc/init.d/apache2 restart

Thats all
good luck, kupo!

Thursday, February 17, 2011

Disable phpmyadmin login

PhpMyAdmin is a webbased database management application and it is a very good tool for developer.

But there is one problem if you want to install it localhost which is annoying login after AFK for a while

I have google for these solution and the result wasnt good enough so I post this so I can refer it back

Manage to work it out by referring the manual http://www.phpmyadmin.net/documentation/#servers_user


Nows lets disable the annoying login

Advantage: no annoying
Disadvantage: Less secure, password stored in a file without encrypted

These was tested on Ubuntu machine version 10.10 so I'm not sure about windows
The version of phpmyadmin is 3.3.7deb3build0.10.10.1

1st open the configuration of the phpmyadmin file

sudo gedit /etc/phpmyadmin/config.inc.php



Search for string "/* Authentication type */" (its at line no 35)
Disable the "cookie" auth_type and put these code. It should look like these

/* Authentication type */
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'mypasswordissecret';


So you eventually change the auth_type into 'config' and you required to put the username and password for that

To test the annoying login is now disabled, restart your FireFox (reset the cache) and try to direct to the phpmyadmin (In my case I type "http://localhost/phpmyadmin/" in my FireFox URL)

It work when you are not asked for login. KUPO!

p/s: I know the file was /etc/phpmyadmin/config.ini.php is from file /var/www/phpmyadmin/config.inc.php

Edit 29 Nov 2012
For phpMyAdmin 3.4.11 the configuration file for windows was in libraries/config.default.php
here is my setting, for localhost development
$cfg['Servers'][$i]['auth_type'] = 'config'; //Default is cookie
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '';
$cfg['Servers'][$i]['nopassword'] = true; //Default is false
$cfg['Servers'][$i]['AllowNoPassword'] = true; //Default is false

Sunday, January 30, 2011

Prevent mail from spam or junk by encryption from crawler

If you write a blog and put your email on it. There is a chance for you to get Spam/Junk mail
This can be cause of many reason but I'm focus on crawler method

How this spam works?
Basically this is the procedure
1. They find your email
2. They write email to you

Spam usually include 1000 email or more and of course it is done by using a bot (a system) and not just people manually type in

To find your email
They using web-crawler, spam-crawler or anything-crawler. These crawler will browse slowly through the internet (from blog to blog, website to website until forever). If your blog put an hyperlink of your friend blog (blogroll they called) these crawler will go into it

Thus in, programming these crawler detect 2 things

1st detection
Detect "http://" text. If they found and word, URL or string match. They will retrieve the link and put in on the "Next going to be crawl list"

2nd detection
Since they want to spam to your mail, they simply find any string or word with "@" symbol. Thus your email will be captured in these process

Write email to you (spam)
These is a process of producing mass email and of course they use the list they got from the first step and use a bot (system) to mass mail it


Prevention

There is 2 type of prevention
1. Email filter (thats why you have spam/junk mail categories)
2. Prevent your email from being on the spammer list

1st prevention - Filter your mailbox
This is already common and build in feature for almost all email system like gmail and others. So no need discussing much

2nd prevention - Prevent from listed
This is what I want to discussed about
Usually people will make their email not in easy format or encryption.

Using different email format like (let say your email is ajskdhqjeakjbdia@gmail.com)

Email: ajskdhqjeakjbdia (@gmail)

Email: ajskdhqjeakjbdia at gmail dot com

Or they use encryption like these

ajskdhqjeakjbdia@gmail.com
(It looks normal but it is actually encrpted)

So these encryption can be easily google. But I'm suggesting you the simplest one which taken from these website http://www.web-designz.com/tools/email_encoder.shtml
Note: The simplest method might also means it is easily detectable by the crawler

If you are a programmer and wandering how did the website do the answer is they are using convertToUnicode(...) function

If you view the page source. It wont show and "@" or your email at all because it is encrypted and of course the crawler is a system, they read the page source and not reading like you did (using web browser)

-End-

Saturday, January 29, 2011

Write blog post using TinyMCE

Google blog text editor has improved!.They have "Edit HTML" or "Compose" tab (like below)



Tuesday, January 25, 2011

HTML UTF encoding entities


I was doing some project require math symbol. The key was not exist in keyboard
The website that I use as reference is
http://www.fileformat.info/info/unicode/char/b1/index.htm
The link is a plus minus symbol (±). You can search fur further symbol at the top left

Or also here
http://www.danshort.com/HTMLentities/index.php?w=hertz

Sunday, January 23, 2011

CakePHP jquery autocomplete

Im using cakephp 1.2 and want to make autocomplete on them
Have googling for several hours (including tying it) and finally succeed

p/s: Im using try an error method. Im afraid that this 3rd try was success because of additional code I have put during try #1 and #2

1st I try to use this and succeess (except when want to autocomplete from database source)
Using original jquery http://jqueryui.com/demos/autocomplete/ which is version jquery-ui-1.8.8.custom.min.js and jquery-ui-1.8.8.custom.css

2nd was from this blog (this fail)
http://nuts-and-bolts-of-cakephp.com/2008/05/07/jquery-autocomplete-in-cakephp/
http://www.pengoworks.com/workshop/jquery/autocomplete.htm

3rd was from this website
http://www.cakephp.bee.pl/ajax/autoComplete

Thanks for all those programmer who make my life easier

After several investigation (I go crazy with these 2nd try for almost 2 days and turned out it cause of URL?)
I manage to enable the 2nd try. The reason of error is because I didnt put my system name
the website tutorial said "/products/autoComplete" but if your CakePHP 1.2 system name is 'accounting' means its going to become '/accounting/products/autoComplete'

What next? I want to make the view to be able to save more Account name. Thus is use a loop like this
input("Account.$aa.name"); ?>
input("Account.$aa.id"); ?>

Remember, the account name is just a name. At the controller what matters is the Account.$aa.id
Thus, after the autocomplete on the Account Name, the Account Id will be put the Id of the selective Account

To do this you require to modify function findValue(...) because this is where the event for 'Choosing which Account Name from the list of autocomplete'. And also a dummy input and one new function

New dummy input (on the view)
<input id="tempCount" value="" />

New dummy function (on the view at the javascript)
function tempCountert( theTempCountValue)
{
document.getElementById('tempCount').value = theTempCountValue;
}
Then you need to change you loop for the account name

From
input("Account.$aa.name"); ?>

To
input("Account.$aa.name", array( 'onchange'=>'tempCountert("Account'.$aa.'Id")')); ?>

Finally will be on the function findValue(li). Make sure to add this code
var updatedColumner = document.getElementById('tempCount').value;
document.getElementById(updatedColumner).value = sValue;



How my code works?
  1. You type in some value in the 'Account name' and the autocomplete list out the match
  2. When you click one of the match result. The dummy input (tempCount) will change the value to Account Name index. let say Account.0.name will print out 'Account0Id' in dummy input
  3. Function findValue(...) will be executed. And get the value in dummy input. Thus change the value

Thursday, January 20, 2011

PHP generate document PDF, ODT, Excel (XLS)

Just to record down any PHP library that can help in generate document

PDF
FPDF = http://www.fpdf.org/

ODT
odtPHP = http://www.odtphp.com/

XLS (Excel)
PHPExcel = http://phpexcel.codeplex.com/

odtPHP is from Anaska. Who / what is Anaska?
Not sure for myself but I do belive they produce something really useful. Check out your WAMP it is from Anaska too :D

Wednesday, January 12, 2011

jQuery navigation menu

Im not sure does anybody know about this. Think it will be easier to find in google
Below is the link for website that show example on jQuery navigation menu

36 Eye-Catching Jquery Navigation Menus
http://www.1stwebdesigner.com/resources/36-eye-catching-jquery-navigation-menus/

By the way, the website it self http://www.1stwebdesigner.com is totally awesome for me

Tuesday, January 11, 2011

PHPExcel

PHPExcel make a nice looking table header
Actually is not really nice looking. Just a proper presentation...
There is too many code and I got no time to upload...

Sources from here
http://phpexcel.codeplex.com/Thread/View.aspx?ThreadId=32427

$headerStart = 22; //Start row

foreach( array( 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'M', 'N', 'O', 'Q', 'R', 'S', 'T') as $alphabet){
$objPHPExcel->getActiveSheet()->getStyle($alphabet.$headerStart)->getAlignment()->setWrapText(true);
$objPHPExcel->getActiveSheet()->mergeCells( $alphabet.$headerStart.":".$alphabet.($headerStart+1));
$objPHPExcel->getActiveSheet()->getStyle($alphabet.$headerStart)->getAlignment()->setVertical( PHPExcel_Style_Alignment::VERTICAL_CENTER);
}

Wednesday, January 5, 2011

CakePHP connect 2, many, multiple database

Tag
CakePHP connect with more than 1 database
CakePHP connect multiple database
CakePHP connect more database
CakePHP connect 2 database
CakePHP connect with 2 database. 1 is CakePHP structured and another 1 is not

The main source is from here
http://blog.4webby.com/posts/view/6/cakephp_models_using_multiple_db_connections

Repeat the same thing
class DATABASE_CONFIG {

var $default = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'your_host',
'login' => 'your_login_1',
'password' => 'your_password_1',
'database' => 'DB_1',
'prefix' => ''
);

var $general_syst = array(
'driver' => 'mysql',
'persistent' => false,
'host' => 'your_host',
'login' => 'your_login_2',
'password' => 'your_password_2',
'database' => 'DB_2',
'prefix' => ''
);
}
?>

class User extends AppModel {

var $name = 'User';
var $useDbConfig = 'general_syst';

//your code here
//....
}

class Post extends AppModel {

var $name = 'Post';
var $useDbConfig = 'default';

//your code here
//....
}

$this->Post->bla_bla_bla : data will be retrieved/inserted/updated from DB_1
$this->User->bla_bla_bla : data will be retrieved/inserted/updated from DB_2


Here is some additional
1. I can connect even without make it persistance.

pr($this->Student->useDbConfig);
$this->Student->useDbConfig = 'general_syst';
$ret = $this->Student->query("SELECT * FROM tbl_lecturer");


Note that tbl_lecturer is another non cakePHP database. It used MySQL database and query does take the data nicely

If you want to check the database connection. Refer here http://asipi.blogspot.com/2011/09/cakephp-check-database-configuration.html

Sunday, January 2, 2011

Smarty array

Case: Want to make a loop but need to check "the value is an array" or "the value has a value". I'm using smarty code template (.tpl file). Keep having this problem so I job this down to myself

Reference
http://www.smarty.net/forums/viewtopic.php?t=9891

Rewrite it back
use count() -> http://uk.php.net/manual/function.count.php
or isset() -> http://uk.php.net/manual/en/function.isset.php
or empty() -> http://uk.php.net/manual/en/function.empty.php

Maybe later want to write how to create a loop from the array data... but quite lazy rite now

Tuesday, December 14, 2010

FPDF - MutiCell - underline on each line

FPDF - MutiCell - underline on each line


Draw line under each line when new line is created when using FPDF. Or simply like picture below


Lazy to put picture


 


If you are using FPDF and want to make a line at the bottom of the text using Muticell, the parameter you send willl be like this


$pdf->MultiCell( 10, 100, "Hello World", 'B')


Where the 'B' represent line at bottom


 


But if you have a case like $pdf->MultiCell( 10, 100, "Hello \nWorld", 'B') //New line


or $pdf->MultiCell( 10, 100, "Hello World Hello World Hello World Hello World Hello World Hello World ", 'B') //Text too long auto new line


They will look like this


Lazy to put picture


 


And what you want is to look like this


Lazy to put picture


 


If you change the text into underline, it also does solve the purpose but it is not underline upon cell. It will be underline upon text


Lazy to put picture


 


So what left is only a tweak to the FPDF where I will tell you where to modify, which is in the function MultiCell(...) of course


First of all, I'm using FPDF version 1.53 (2004-12-31) where Olivier PLATHEY said "You may use and modify this software as you wish."


So this tweak is legal


Second, this code I write is free you may use and modify what I code as you wish. This is also 'AS IS', if anything happen dont blame me


If got bug, I dont care because with this code I already manage to get what I want


 


Lets start


 


Step 1


Go to the function MultiCell($w,$h,$txt,$border=0,$align='J',$fill=0)


 


Step 2


Inside there, you will see function Cell(...) is called 4 times and what you need to do is add additional code at the bottom of cell number 1 and 3


If I was correct


Cell no 1 is at line 755


Cell no 3 is at line 794


 


Step 3


Make the code to look like this. Make it like that at the 1st and 3rd cell



$this->Cell($w,$h,substr($s,$j,$i-$j),$b,2,$align,$fill);

//Hassif. If you want the Multicell to have a bottom line at each text. use this
//Common border 'B' only bottom line at the end of text. Not at each line of text
if( strpos($border,'Z')){
$this->Line( $this->x, $this->y, $w+$this->x, $this->y);
}



 


Step 4


It done. So to use this feature you need to put $pdf->MultiCell( 10, 100, "Hello \nWorld", 'BZ') which is additional 'Z' character


 


Im kind of busy right now to explain further, so later...

Thursday, November 25, 2010

mysql find duplicate record

I take it from here. Put in my own blog cause I keep using them
http://www.petefreitag.com/item/169.cfm

SELECT email,
COUNT(email) AS NumOccurrences
FROM users
GROUP BY email
HAVING ( COUNT(email) > 1 )

SELECT email
FROM users
GROUP BY email
HAVING ( COUNT(email) = 1 )

31 May 2011
It turns out these code was pretty awesome when I want to make a dynamic drop down selection
I can make it display unique value and sorted by most use at the top