Page 1 of 1

Auto generating ID

Posted: Thu Jan 28, 2010 4:34 am
by johnjj
Hello.

Instead of the product name in the Admin panel, in trying to add a auto generating ID. Can please some one help me.

Thanks :)

Re: Auto generating ID

Posted: Thu Jan 28, 2010 4:39 am
by i2Paq
What have you come up with so far?

Re: Auto generating ID

Posted: Thu Jan 28, 2010 9:14 am
by johnjj
hi

Nothing, but if you can tell me what to do I can manage to do sumthing.

Thanks.

Re: Auto generating ID

Posted: Thu Jan 28, 2010 10:53 pm
by Qphoria
you need to give a lot more info. what starts the id? 00001? 000A? AAAA? 1234?
How will it work? you just want the name field to auto-populate with the next available number?

Re: Auto generating ID

Posted: Wed Feb 03, 2010 11:33 am
by johnjj
Hello

Thank for you r support, this is what i wanted n came up with in the file product_form.tpl


<?PHP
$random_id_length =6;
$rnd_id = crypt(uniqid(rand(),001));
$rnd_id = strip_tags(stripslashes($rnd_id));
$rnd_id = str_replace(".","",$rnd_id);
$rnd_id = strrev(str_replace("/","",$rnd_id));
$rnd_id = substr($rnd_id,0,$random_id_length);

# DB settings
$mysql_server = 'localhost';
$mysql_user = '######';
$mysql_passwd = '#####';
$mysql_db = #######';


# Connect to database
$conn = mysql_connect($mysql_server, $mysql_user, $mysql_passwd);

if (!$conn)
die("Unable to connect to db server!");

# Select the db
mysql_select_db ($mysql_db, $conn) || die("Unable to select db $mysql_db");

$sL = "select count(*) from product";

$result = mysql_query($sL);
$details = mysql_fetch_array($result);
$new_cnt = $details[0] + 1;
$cnt_id = 'AA0000'.$new_cnt;

echo "<input type='text' name='model' readonly='readonly' value='$cnt_id'>";
?>