Configure HTML/JavaScript

Thursday, April 28, 2011

Function to get next Database ID

the bellow function will give you the next auto increament id of your database primary key.

function getNextID($field_id){
$db =& JFactory::getDBO();
$sql = "SELECT max(id) FROM jos_table WHERE field_name=$name";
$db->setQuery($sql);
$acl_num = $db->loadResult();
if($acl_num<>null){
return ($acl_num + 1);
}else{
return 0;
}
}

in reference to:

"Some time we need to see some string type data of different rows in comma separated or other separated in a single field. for this type of implementation mysql have a function GROUP_CONCAT(field_value) . we can add GROUP BY cluse to get comma separated values in different cases."
- Techinical tips for practical uses (view on Google Sidewiki)

Thursday, February 10, 2011

Getting row values in comma separated using GROUP by or other queries in MySQL

Hi,

Some time we need to see some string type data of different rows in comma separated or other separated in a single field. for this type of implementation mysql have a function GROUP_CONCAT(field_value) . we can add GROUP BY cluse to get comma separated values in different cases.

Example:

GROUP_CONCAT([DISTINCT] expr [,expr ...]
[ORDER BY {unsigned_integer | col_name | expr}
[ASC | DESC] [,col_name ...]]
[SEPARATOR str_val])

mysql> SELECT student_name,
-> GROUP_CONCAT(test_score)
-> FROM student
-> GROUP BY student_name;

in reference to: Aniruddh (view on Google Sidewiki)

Thursday, January 20, 2011

Searching non alpha numeric character through REGEX through PHP

Hi,
you can search non-alpha numeric characters by simple adding a negation regex charactor in the regex string (^).

below is the Example

preg_replace('/[^A-Za-z0-9_]/', '', 'D"usseldorfer H"auptstrasse');

Thanks

in reference to: Aniruddh (view on Google Sidewiki)

Monday, December 20, 2010

Checking the Request is Ajax

//function to check if the request is made through ajax
function isAjax() {
return (isset($_SERVER['HTTP_X_REQUESTED_WITH']) &&
($_SERVER['HTTP_X_REQUESTED_WITH'] == 'XMLHttpRequest'));
}
}

in reference to: http://php.net/ (view on Google Sidewiki)

Thursday, December 9, 2010

managing multiple Databases in php

Hi,
This is important to manage your database connections in php if you are using many connections in a single application. you can use single ton pattern in php to make is clear.

Exe:
class Connector {
    private $conn;
    private $intranetdb = 'jprod';
    private $metricsdb = 'metrics_prod';
    private function __costructor(){
           
    }
    static function intranetDb(){
        return 'jprod';
    }
    static function metricsDb(){
        return 'metrics_prod';
    }
    static function makeConnection($host, $username, $password){
        return $this->conn = mysql_connect($host, $username, $password);
    }
    static function prodConnection(){
       
        $prod_dbhost         = 'localhost1';
        $prod_dbuser         = 'jroot';
        $prod_dbpass         = 'joomla1';
        /*
        $prod_dbhost         = 'localhost';
        $prod_dbuser         = 'root';
        $prod_dbpass         = '';
        */
        $prod_conn = mysql_connect($prod_dbhost, $prod_dbuser, $prod_dbpass) or die ('Error connecting to mysql');
        return $prod_conn;
    }
    static function metricsConnection(){
       
        $dbhost         = 'localhost2';
        $dbuser         = 'jroot';
        $dbpass         = 'joomla1';
        /*
        $dbhost         = 'localhost';
        $dbuser         = 'root';
        $dbpass         = '';
        */
        $db             = 'metrics_prod';
        $conn = mysql_connect($dbhost, $dbuser, $dbpass);
        return $conn;
    }
    static function closeConnection($resource){
            return mysql_close($resource);
    }
    static function freeResult($result){
            return mysql_free_result($result);
    }
}

Friday, November 12, 2010

file copy from url in java

public int copyfile(String filesToTransfor[]) {
int oneChar, count = 0;
if (filesToTransfor.length < 1) {
System.err.println("Two file path is required to complete the process");
System.exit(1);
}
try {
URL url = new URL(filesToTransfor[0]);
System.out.println("Opening connection to " + filesToTransfor[0] + "...");
URLConnection urlC = url.openConnection();
// Copy resource to local file, use remote file
// if no local file name specified
InputStream is = url.openStream();
// Print info about resource
System.out
.println("Copying resource (type: " + urlC.getContentType());
// Date date=new Date(urlC.getLastModified());
// System.out.println(", salesnet file modified on: " + date.toString() + ")...");
System.out.flush();
FileOutputStream fos = null;
if (filesToTransfor.length < 2) {
String localFile = null;
// Get only file name
StringTokenizer st = new StringTokenizer(url.getFile(), "/");
while (st.hasMoreTokens())
localFile = st.nextToken();
fos = new FileOutputStream(localFile);
} else
fos = new FileOutputStream(filesToTransfor[1]);

while ((oneChar = is.read()) != -1) {
fos.write(oneChar);
count++;
}
is.close();
fos.close();
System.out.println(count + " byte(s) copied");

} catch (MalformedURLException e) {
System.err.println(e.toString());
} catch (IOException e) {
System.err.println(e.toString());
}

return count;
}

in reference to: Google Toolbar Installed (view on Google Sidewiki)