Here is a way to select element with multiple classes in jquery.
$(’table.cl1.cl2′).addClass(’abc’);
And to select the element which has one class
but not the other. This, does that:
$(’table.cl1:not(table.cl2)’).addClass(’xyz’);
Second one is pretty interesting which works like if clause.
Tags: javascript, jquery
Posted in tricks on August 31st, 2010 by jimy>
Zend_Controller_Request_Http has a rudimentary method
for detecting AJAX requests: isXmlHttpRequest().
This method looks for an HTTP request
header X-Requested-With with the value 'XMLHttpRequest';
if found, it returns TRUE.
$this->getRequest()->isXmlHttpRequest()
it is important to check that your ajax requests
contain the request header - X-Requested-With
Tags: zend
Posted in tricks on August 27th, 2010 by admin>
hi guys,
I came across a beautiful function of php which will convert any php array to the GET parameter for url.
E.g.
$data = array( ‘foo’ => ‘bar’, ‘jimy’ => ‘modi’ );
$url = http_build_query($data);
this will give you
foo=bar&jimy=modi
More info
Tags: php
Posted in tricks on August 27th, 2010 by jimy>
If a javascript string contains ASCII codes as a result of escaping HTML characters, to convert them into text, use the String.fromCharCode(); and replace functions as follows
str.replace(/&#(\d+);/g, function (m, n) { return String.fromCharCode(n); });
String.fromCharCode() is a static function and will be called by passing the string variable and using ‘String’ only. ie not like other string functions eg str.replace()
Tags: javascript
Posted in tricks on August 27th, 2010 by vineet>
After searching for more than four to five hours i got the link which give latitude, longitude and other information such as address including city and country. So here is a small function which will give you latitude and longitude of the given ip address.
function getLatLng($ip){
//get the contents from the site by file_get_contents.
$sXML = @file_get_contents(’http://ipinfodb.com/ip_query.php?ip=’.$ip.’&timezone=false’);
//make the response in a xml object so we can parse it.
$oXML = @new SimpleXMLElement($sXML);
$array = array(
‘Latitude’ => (string) $oXML->Latitude[0],
‘Longitude’ => (string) $oXML->Longitude[0]
);
return $array;
}
Tags: ip address, latitude, longitude, php
Posted in tricks on August 27th, 2010 by jimy>
Suppose you want to search a keyword in 5 different columns or almost in all the fields of the table, then MySQL
provides us with fulltext indexing and searching method.
Before using this method , you need to add FullText to the columns in which you want to search.
ALTER TABLE member ADD FULLTEXT(firstname, lastname,address);
Then comes your main query :
SELECT firstname, lastname,address FROM member
WHERE MATCH (firstname,lastname,address) AGAINST (’test’);
The Match will look for “exact match” in the above 3 columns and on successfull match it will return that row.
Suppose in member table there is a an entry with firstname = test then the output will be :
firstname lastname address
test abc xyz
Suppose you want to use wildcards then modify your query :
SELECT firstname, lastname,address FROM member
WHERE MATCH (firstname,lastname,address) AGAINST (’*test*’);
Tags: mysql
Posted in tricks on July 29th, 2010 by dharmesh22>
we can fire custom events in jquery and set an event handler for each event .
This enables loose coupling and code reuse . This can be used to achieve the observer design pattern .
$(’#txtAddress’).keyup(function() {
$(document).trigger(’ADDRESS_CHANGE’);
});
$(’#txtCity’).keyup(function() {
$(document).trigger(’CITY_CHANGE’);
});
to now bind the event :
$(document).bind(’ADDRESS_CHANGE’, function(e) {
UpdateName();
UpdateOtherText(e);
});
Hack Away
Tags: jquery
Posted in tricks on July 27th, 2010 by admin>
MySQL has a function called FOUND_ROWS which is faster than any other function for counting rows which is returned by the latest query, it is used same as MySQL “LASTINSERT_ID()”.
For example: if we are developing a pagination script and we want the total number of results returned by the Query, at the same case in pagination we use LIMIT for paging the record using the above function it will not return the limit results it will return the total available results.
How to use? suppose we have 20 records in our table and we are fetching only 10 records in a page, then the $total will return total 20 not 10.
$sql = “SELECT SQL_CALC_FOUND_ROWS * FROM tablename LIMIT 1, 10 “;
$results = mysql_query($sql);
$total = mysql_query(’SELECT FOUND_ROWS() as total’);
Tags: found_rows, mysql
Posted in tricks on July 20th, 2010 by Vinodkumar>
I spent about 35 minutes on this one and still havent found a logic to it .
But this hack should be remembered .
consider the markup : <div id = a ><input/><div id = “a_child” ></div> </div>
if you need to give a bottom border to the div with id = a and expect it to come below the div with id = “a_child” , then the following css needs to be in place :
#a{ height:auto;overflow:hidden;}
Thanks to vineet and jimit to get out of this one ..
Tags: css
Posted in tricks on July 17th, 2010 by admin>
To make a div or a paragraph editable set the attribute - contenteditable = true
give a fixed width to the div : - width:100px ;
after 100px the word should wrap down , for this add the css property :
word-wrap:break-word;
Happy Hacking
Tags: css
Posted in tricks on July 17th, 2010 by admin>