Thursday, April 26, 2007

Google results Incomplete

While playing around with Google, I found that although Google claims it has returned lakhs of entries for your search it never shows more than 1000 entries.
check this link out
this is the last page of the results for search keyword google.
and at the bottom it shows
If the above link is clicked to fetch omitted results, google doesn't shows all those records instead it repeats the same query and displays only till 1000 entries.
Strange fact is all the other search engines like Yahoo, ninemsn, ask, msn, etc all behave the same as Google. Nobody displays all the records.

Friday, April 20, 2007

String Manipulation . explode string

exploding string at each component character

the below mentioned preg_Split() function is very useful in exploding entire string for each of its characters;

$str = 'Mumbai';
$chars = preg_split('//', $str,-1, PREG_SPLIT_NO_EMPTY);
print_r($chars);
output
Array
(

[0] => M
[1] => u
[2] => m
[3] => b
[4] => a
[5] => i
)

Thursday, April 19, 2007

JS 3d arrays

To use multi-dimensional arrays in js, we have to define it as an array at each dimension. -
eg:

abc['test1'] = new Array();
abc['test1'][test2'] = new Array();
abc['test1'][test2']['test3'] = new Array();

foreach() substitute in JavaScript JS

JavaScript For...In Statement
The for...in statement is used to loop (iterate) through the elements of an array or through the properties of an object.
The code in the body of the for ... in loop is executed once for each element/property.
Syntax
for (variable in object)
{
code to be executed
}
The variable argument can be a named variable, an array element, or a property of an object.
Example
Using for...in to loop through an array:

var x
var mycars = new Array()
mycars[0] = "Saab"
mycars[1] = "Volvo"
mycars[2] = "BMW"
for (x in mycars)
{
document.write(mycars[x] + "
")
}

appendchild issue in IE

While Working in one of my applications I had to create new row dynamically on click of a button.

The below code worked fine with Mozilla, however nothing happened in IE also no errors were shown
var theTable = document.getElementById(tableId);
var rowIdAttribute = i+1;
var newRow = document.createElement('tr');

newRow.setAttribute("id", rowIdAttribute); theTable.appendChild(newRow );



I found that IE does not support appendChild to add new rows in the table
So I added a container element to place the new row and append that container element.
Correct code is as shown below which works fine both in IE and Mozilla


var theTable = document.getElementById(tableId);
var newtbody = document.createElement('TBODY');
var rowIdAttribute = i+1;
var newRow = document.createElement('tr');

newRow.setAttribute("id", rowIdAttribute);

newtbody.appendChild(newRow);
theTable.appendChild(newtbody);