Convert datetime format by using php :
$originalDate = "2010-03-21";
$newDate = date("d-m-Y", strtotime($originalDate));


$servertime = date("Y-m-d H:i:sa",time());
if(strtotime($servertime) < time()-10800)

the if statement will fail because variable $servertime contain value of "am/pm", need to delete the "a" from "Y-m-d H:i:sa" will fix it.

ADDTIME ('zzz'); and TIMEDIFF ('zzz') fail because there is a space before (

put array string / username on WHERE IN clause of mySQL :
$friendsArray = array("zac1987", "peter", "michelle");
foreach($friendsArray as $key => $friend) {
    $friendsArray[$key] = "'".mysql_real_escape_string($friend)."'";
}
$friendsArray2 = join(', ', $friendsArray);
$query120 = "SELECT picturemedium FROM users WHERE username IN ('$friendsArray2')";
echo $query120;


To delete an element from an array : $love3=array_diff($love2,array($username1));

To check if element is in array : if (in_array("Irix", $os)) { echo "Got Irix"; }

To add element to an array : $cart = array();
$cart[] = 13;
$cart[] = 14;


To show more descriptive error message for "Warning: mysql_fetch_row(): / mysql_fetch_array(); supplied argument is not a valid MySQL result resource" : print (mysql_error());

error_reporting(E_ALL);
ini_set("display_errors", 1);

two lines codes above show error "Undefined index: username". To fix it, use if(isset($username)){ ... }; It will show Warning if your array variable has empty value. You cannot write if (isset($array_variable())){ so, you have to declare all array variable like $array_variable = array(); to prevent Warning occur, because $array_variable will not return empty string if u declare it as an array, it will return "array" as output, so u won't get Warning.

replace value in array :
Let's say $setting_name_left is array that carry value "cus_name", "cus_phone", "remarks" :
$setting_name_left_for_table = str_replace("_", " ", $setting_name_left);
$setting_name_left_for_table = str_replace("remarks", "note", $setting_name_left_for_table);
$setting_name_left_for_table = join(' ', $setting_name_left_for_table);


Avoid php escape string on online hosting :
$description = stripslashes($_POST['description']); // weakness is it will delete \ when user type \.
or


Posted by Zac1987 on 14 September, 2011

0 comments






Enter your email address:

Subscribe in a reader

Follow zac1987 on Twitter

Donation

If you feel my website is informative and it is useful for you, please donate some money to support me or buy me a drink. I will continues this good works. Thank you.