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)

1 comment:

  1. Hi,
    Sorry, i forgot to mention about the programming language and the type of variable used here.

    Its for the php and joomla programmers (these are software languages). this code will help you find the next registration number of users. for example you have a software to register users(like student, customers of your shoap, etc). And want the system should generate the registeration number of the user. then the above code will do that for you.

    Thanks

    ReplyDelete