nox.freak  [ Profile ]

Sort by: Date / Title /

  1. 2 months ago
    This will get the last entry into a database where COL is equal to something.
    1. SELECT * FROM TABLE WHERE COL=something ORDER BY id DESC LIMIT 0,1
  2. 2 months ago
    Takes a birth date and will spit out how old that person is.
    1. function getAge($date)
    2. {
    3.         list($y,$m,$d) = explode("-", $date);
    4.         $age = date("Y") - $y;
    5.         if( date("md") < $m.$d )
    6.         {
    7.                 $age--;
    8.         }
    9.         return $age;
    10. }
  3. 2 months ago
    This is just a basic way to query a MySQL database.
    1. define("DBNAME", "db_name");
    2. define("HOST", "localhost");
    3. define("USER", "foo");
    4. define("PASSWORD", "var");
    5.  
    6. $dbconnect = mysql_connect(HOST, USER, PASSWORD);
    7. mysql_select_db(DBNAME, $dbconnect);
    8.  
    9. $sql = 'SELECT * FROM table';
    10. $q = mysql_query($sql, $dbconnect) or die("Error with SQL: $sql");
    11. $num = mysql_num_rows($q);
    12. for ($i=0; $i<$num; $i++)
    13. {
    14.         $dbOut = mysql_fetch_assoc($q);
    15.         echo $dbOut['col'];
    16. }
  4. sponsorised links
  5. 2 months ago
    Handles response from an ajax request.
    1. function ajaxRequest()
    2. {
    3.         var opt = 's=whatever you want to pass';
    4.         var page = 'ajax_page.php';
    5.  
    6.         var http = createRequestObject();
    7.         http.onreadystatechange = function()
    8.         {
    9.                 if((http.readyState == 4) && (http.status == 200))
    10.                 {
    11.                         var text = http.responseText;
    12.                 }
    13.         }
    14.         http.open('POST', page, true);
    15.         http.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    16.         http.setRequestHeader("Content-length", opt.length);
    17.         http.setRequestHeader("Connection", "close");
    18.         http.send(opt);
    19. }
  6. 2 months ago
    Checks to see if browser is IE based or other.
    1. function createRequestObject(handler)
    2. {
    3.         var xmlHttp;
    4.         try
    5.         {
    6.                 // Firefox, Opera 8.0+, Safari
    7.                 var xmlHttp = new XMLHttpRequest();
    8.                 xmlHttp.onload=handler;
    9.                 xmlHttp.onerror=handler;
    10.                 return xmlHttp;
    11.         }
    12.         catch (e)
    13.         {
    14.                 // Internet Explorer
    15.                 try
    16.                 {
    17.                         xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
    18.                         return xmlHttp;
    19.                 }
    20.                 catch (e)
    21.                 {
    22.                         try
    23.                         {
    24.                                 xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
    25.                                 return xmlHttp;
    26.                         }
    27.                         catch (e)
    28.                         {
    29.                                 alert("Your browser does not support AJAX!");
    30.                                 return false;
    31.                         }
    32.                 }
    33.         }
    34. }
  7. 2 months ago
    Checks emails format, unlike others it supports have a plus (+) sign in the address. NOTE: this is easy for the user to by pass, as it is in javascript witch is not server side code.
    1. function emlChk(str) // email format checker/validator.
    2. {
    3.         var filter=/^([\w-]+((?:\.|\+)[\w-]+)*)@((?:[\w-]+\.)*\w[\w-]{0,66})\.([a-z]{2,6}(?:\.[a-z]{2})?)$/i
    4.         if(filter.test(str))
    5.         {
    6.                 return true
    7.         } else {
    8.                 return false
    9.         }
    10. }

First / Previous / Next / Last / Page 1 of 1 (6 posteets)