ajax XML


header('Content-type: text/xml');

<?php echo $description; ?>


httpRequest.responseXML.getElementsByTagName('description')[0].firstChild.data;

javascript trim function

function trim(stringToTrim) {
return stringToTrim.replace(/^\s+|\s+$/g,"");
}
function ltrim(stringToTrim) {
return stringToTrim.replace(/^\s+/,"");
}
function rtrim(stringToTrim) {
return stringToTrim.replace(/\s+$/,"");
}

javascript drag and drop



drag Me!



CSS selector

input[type=submit]:hover, input[type=button]:hover{
  background-color:#FFBBCC !important;
}

Mysql update with conditional

+----+----------+--------+
| id | code |subcode |
+----+----------+--------+
| 1 |A001-123 | A001 |
| 2 |A001-123 | D003 |
| 3 |A001-456 | A001 |
| 4 |A001-456 | A001 |
| 5 |A001-456 | D002 |
| 6 |A001-789 | A001 |
+----+----------+--------+

UPDATE test as t1,
(SELECT code,
replace( substring( substring_index( code, '-', 2 ),
length( substring_index( code, '-', 2 -1 ) ) +1 ) ,
'-', '' ) AS ref //split
FROM test
WHERE code IN(
'A001-123', 'A001-456', 'A001-789'
) GROUP BY code
) as t2
SET t1.subcode=
IF(t1.subcode='A001', 'A002', t1.subcode) ,
t1.code=concat("A002-",t2.ref)
WHERE t1.code IN(
'A001-123', 'A001-456', 'A001-789'
) AND t1.code=t2.code


+----+----------+--------+
| id | code |subcode |
+----+----------+--------+
| 1 |A002-123 | A002 |
| 2 |A002-123 | D003 |
| 3 |A002-456 | A002 |
| 4 |A002-456 | A002 |
| 5 |A002-456 | D002 |
| 6 |A002-789 | A002 |
+----+----------+--------+

MYSQL split delimited strings functions

It's pretty easy to create your own string functions for many examples listed here

## Split delimited strings

CREATE FUNCTION strSplit(
x varchar(255),
delim varchar(12),
pos int
)
returns varchar(255)
return replace(substring(
substring_index(x, delim, pos),
length(substring_index(x, delim, pos - 1)) + 1),
delim, '');


select strSplit("aaa,b,cc,d", ',', 2) as second;
+--------+
| second |
+--------+
| b |
+--------+

select strSplit("a|bb|ccc|dd", '|', 3) as third;
+-------+
| third |
+-------+
| ccc |
+-------+

select strSplit("aaa,b,cc,d", ',', 7) as 7th;
+------+
| 7th |
+------+
| NULL |
+------+
Credits go to Chris Stubben

getElementById('description').value + IE javascript bugs

Let say you have a html like below.

<html>
<head>
<title>IE document.getElementById bug</title>
<meta name="description" content="IE bugs" />
</head>
<body>
<textarea name="description" id="description">
This is information about the bug
</textarea>
<script type="text/javascript">
alert(document.getElementById('description').value);
</script>
</body>
</html>

okay,

If you view the example in Firefox, you will get a JavaScript alert message :
  This is information about the bug

However, if you view it in IE7 the JavaScript alert will contain the word “undefined”.

The error is caused because IE’s document.getElementById(’description’) sees the meta tag with the name attribute set to “description” and since it treats name and id attributes as interchangeable, returns the meta tag instead of the textarea which actually has an id set to “description”.

JavaScript programmers who are familiar with this bug often take great care to avoid the problem by being circumspect with the names and ids of their elements. However, this becomes increasingly difficult as applications become more complex with multiple reusable parts that are included into various parts of the same system, especially with multiple programmers working concurrently. Naming conventions can help, but there are times when the id of an input element (which must be unique) differs from its name attribute, which does not have to be unique.

How to solve it,
You can change the textarea name . May be change to "desc"

Other Solution or more details can take a look on this post:
http://www.sixteensmallstones.org/ie-javascript-bugs-overriding-internet-explorers-documentgetelementbyid-to-be-w3c-compliant-exposes-an-additional-bug-in-getattributes

Problems Executing fpdf in IE

Sometimes when we using IE to display the pdf for FPDF.
It can't generate the pdf, or It close it suddenly, or it just display with

Internet Explorer Cannot Download Error Message

but when we view in firefox it display nicely, It is something to do with the cache.

In the php file we can add this before the session_start(),

if(ereg( "MSIE", $_SERVER['HTTP_USER_AGENT'])){
session_cache_limiter('private');
}


OR ADD this..

if(ereg( "MSIE", $_SERVER['HTTP_USER_AGENT'])){
header('Cache-Control: maxage=3600');
header('Pragma: public');
}


If you are looking to send files such as PDFs or Excel spreadsheets or Microsoft Office documents and are having issues with IE7, IE6, or IE5.5 not being able to open/download the files over an SSL connection, but still need not allow caching,
then set the maxage=1
Granted, this will cache your file for one second, but it's as close to an un-cached download as you can get when using IE over SSL.

Original post from:
http://in2.php.net/manual/en/function.header.php#83219

add meta tags,keywords for a specific posts on blogger


1. Switch to the Edit HTML tab of your template and find this line:

b:include data='blog' name='all-head-content'/

2. Add this code just below that line:

<b:if cond='data:blog.url == "http://YOUR-BLOG-URL.com/"'>
<meta content='DESCRIPTION' name='description'/>
<meta content='KEYWORDS' name='keywords'/>
</b:if>


This was done to add META Tags to the main page of the blog.

3. Now add this code just below the code you add just now:

<b:if cond='data:blog.url == "http://YOUR-BLOG-URL.com/2009/03/xxx.html"'>
<meta content='Type you post description here.' name='description'/>
<meta content='Type, the, post, keywords, here' name='keywords'/>
</b:if>


Replace http://YOUR-BLOG-URL.com/2009/03/xxx.html with the
URL of the specific post you want to change the META Tags of.

4. Repeat Step 3 for as many blog posts you want to have unique META Tags for.


Hello Guys..

Hi,

Welcome to my blog..
I hope to learn new things and happy to meet some new friends in here.. No matter you have the same interest with me or not.. Nice to meet you all.. haha.. If got some news, discussion,no matter in programming, travel, movies welcome to share it out here..

regards,
chaiwei

register_global issue

What are Register Global Variables?

It is a frequent necessity to transfer variable values between pages. You may have an HTML form which asks for user input to named fields. These fields (as well as hidden variables) will be transferred to a PHP page for processing. This may be the same page that defines the form, or a different one. A method of either 'post' or 'get' must be given in the form tag.

So, how do these variables and their data get into my PHP code?

Once upon a time, most PHP programmers simply grabbed variables and values by using them in their code. Let's say you had two fields in a form, named "name" and "email". You could simply use $name and $email in your code (the receiving, or target, page), and they would have the values filled in by the user in the form. Life was simple, wasn't it? $name and $email were examples of a special kind of PHP variable, called a register global variable. You simply used it, and it was magically there to pull in data transferred from a form or a link on another page.

eg. Register_global = on

<?php
$conn=mysql_connect('localhost', 'mysqluser', 'mysqlpwd');
if ($save){
$sql='INSERT INTO user VALUES( "'.$name.'" , "'.$email.'" )';
mysql_query($sql,$conn) or die('Insertion stage failed');
}
?>

<>
<>
< method="POST">
< name="name" type="text">
< name="email" type="text">
< name="save" type="submit">
< /form >
< /body>
< /html>

eg. Register_global = off

<?php
$conn=mysql_connect('localhost', 'mysqluser', 'mysqlpwd');
if ($_POST['save']){
$sql='INSERT INTO user VALUES( "'.$_POST['name'].'" , "'.$_POST['email'].'" )';
mysql_query($sql,$conn) or die('Insertion stage failed');
}
?>

<>
<>
< method="POST">
< name="name" type="text">
< name="email" type="text">
< name="save" type="submit">
< /form >
< /body>
< /html>



Using globals in PHP is not recommended for those just starting, like us.

**This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 6.0.0. Relying on this feature is highly discouraged.

Though it is cool and convenient to call variables from anywhere and to any nesting of scripts, it will make your script vulnerable to hacks if you dont take caution.

On the other hand, learning to pass and call variables in a more secret way is more rewarding.You will also be aware to check on every security holes your script will have in the future.

PHP Single quote vs Double quote

Single quotes are faster to execute as compare to double quotes, but the difference is negligible for simple statements.

the double quotes are parsed by php to find where there is any variable that needs to be displayed e.g

$w = "world";
echo " Hello $w"; // taken as Hello World
echo 'Hello $w'; // taken as Hello $w



Sometimes people use double quotes in PHP to avoid having to use the period to separate code. For example, you could write:

$color='blue';
echo "I have a $color shirt on today";

It was faster and easier but is not better.
A better way to write this code would be:


echo 'I have a ' .$color. ' shirt on today';

Although it is produce the same output. But phrasing your code in the second method will result in less chance of error messages, or problems with other programmers deciphering your code.

echo -- PHP

<?php
echo "Welcome to Coding blogspot";
echo "Hello World";
?>


Welcome to Coding blogspot
Hello World





learning PHP

PHP, which stands for "PHP: Hypertext Preprocessor" is a powerful server-side scripting language that is especially suited for Web development and can be embedded into HTML. Its syntax draws upon C, Java, and Perl, and is easy to learn.

The main goal of the language is to allow web developers to write dynamically generated web pages quickly, but you can do much more with PHP.
PHP is often used together with Apache (web server) on various operating systems combine with Mysql (database).

If you are just learning PHP, XAMPP is an easy to install Apache distribution containing MySQL, PHP and Perl. XAMPP is really very easy to install and to use - just download, extract and start.
It is available for linux, windows, Mac OS X and Solaris.

XAMPP is a compilation of free software (comparable to a Linux distribution), it's free of charge and it's free to copy under the terms of the GNU GENERAL PUBLIC LICENSE. But it is only the compilation of XAMPP that is published under GPL. Please check every single license of the contained products to get an overview of what is, and what isn't, allowed.

just keep in mind that these installation packages are for development use, and are not built for a production enviroment, the preformance and security of these tools is not setup for use in a public website.