Selasa, 13 September 2011

Php and mySQL Notes

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 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)){ ... };

Tidak ada komentar:

Posting Komentar