Learn , Share , Enjoy

Determine element is visible or not

if($(’element:visible’).length < 1){
alert(’Element is In Visible’);
}
else{
alert(’Element is Visible’);
}


Retriving multiple values from a single field of your database

if your having a field in your table which holds multiple values and you want to display the same.then use “spliti”
example:
company_dept is the field name.
$sql=”SELECT *from table_name”;
$ex=mysql_query($sql)
$result=mysql_fetch_array($ex);

$cmp_dept=$result['company_dept'];//when you echo this will display all the values
suppose you want single value then

$dept=spliti(”,”, $cmp_dept, 5);//this will split a string into array

$cnt=count($dept);//this will count the number of elements in the array

for output:print_r($dept)
or echo $dept[0];

spliti is case insensitive whereas split is not.
for more info visit:http://www.php.net/manual/en/function.spliti.php


Inserting multiple values from a listbox into the database

if you have a listbox called “department” and want to insert multiple values from the listbox into the database,then:
when the user submits the form,store the value in a variable
$company_dept=$_POST['department'];
query:INSERT into table_name values(’”.join(”,”,$company_dept).”‘)


validate email in javascript

var str = $(”#email”).val();
if((str.indexOf(”.”) > 2) && (str.indexOf(”@”) > 0) && ((str.indexOf(”.”) + 1) < str.length-1)){
alert(”valid”);
}
else{
alert(”Invalid”);
}


Eclipse shortcut

To comment out a line of html code in eclipse IDE , use the following shortcut
ctrl + /


Email check in php

function isValidEmail($email){
return eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]
+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$", $email);
}

Make your css dynamic

To implement constants in css , let your php script output as css by passing the following headers :

header(’content-type:text/css’);
header(”Expires: “.gmdate(”D, d M Y H:i:s”, (time()+900)) . ” GMT”);


Using Column alias in where clause

select (basicsal + hra) as salary from employee where salary > 5000
It will give error (Unkown column salary in where clause.
Instead you can use :
select (basicsal + hra) as salary from employee having salary > 5000


Wordpress – different single.php for different categories

if you have a category called photos and another category called videos , you need to format the single.php differently for each category . this is easy and you can just write the following code in single.php :

if ( in_category(’2′) ) {
include(TEMPLATEPATH . ‘/single-kodetricks.php’);
}
else
include(TEMPLATEPATH . ‘/single-blog.php’);


To display 2 decimal after , Javascript

to display 2 decimal after any number use toFixed() function of javascript
eg. var num = 25;
alert(num.toFixed(2));
it will give 25.00 instead of only 25


Website speed

we can minimise all the js and place it in a single file at the end of the project .
this will reduce the number of http requests and save response time


Post A Trick

How does "Kodetricks" work?

We at kodeplay like to share knowledge. With Kodetricks, even you can join us. All you need to do is post a programming related trick if you have one or rate a trick if you like someone else's.


Find us on

Technology

Contact Us