Forum Moderators: coopster
function GenUID(){
$oid = . $iLastID();
if ($oid < 10)
$oid = '00' . $oid;
else if ($oid < 100)
$oid = '0' . $oid;
return 'ODG_' . $oid;
}
What way will this work?
e.g What I've tried....
$Gen_UID = GenUID()$query = "INSERT into `my_table_name`(
id_with_prefix,
other_column)
VALUES ('"
. $Gen_UID . "','"
. $_POST['created_by_id'] . "')";
mysql_query($query)or die(mysql_error());
Can't seem to get the funcion to fire correctly.... All on the same *.php file. SQL qill fire with no problems..... as long I as leave the function out.
Is there another way to do what I'm trying to do with the fuction thats short and sweet? I can do other ways but its sloppy.
Have also tried putting the funtions inline... Can't remember how to use $this--> but I think that might be my solution.
Anyone?
Thanks in advance!
MySQL Zero Fill [dev.mysql.com]
I just need to evaluate PKs from tables and put a prefix in front of it.... i.e. uid 7 i need to make ODG_007 for the utf8 text. uid 77 i would need to make ODG_077
Again legacy app I'm trying to integrate.
BTW.... thanks for your help the other day. Worked like a charm.
Have you tried concatenating the whole thing on each line?
function GenUID(){
$oid = . $iLastID();
if ($oid < 10)
$oid = 'ODG_' . '00' . $oid;
else if ($oid < 100)
$oid = 'ODG_' . '0' . $oid;
return $oid;
}
FYI.... after beating my head against the wall for a little bit... I realized I was trying to call the result of a function that didn't exist.
FIrst and formost.... $iListID is defined a ways back in the code by
$iListID = mysql_insert_id();
Its returned as an int no?
Thats my problem now. I've tried the following which will complete but only returns OGG_00. What I'm trying to accomplish is ODG_001 or ODG_010 depding on the evaluation of $iListID
function GenUID(){
$oid = $iListID;
if ($oid < 10)
$oid = 'ODG_' . '00' . $oid;
else if ($oid < 100)
$oid = 'ODG_' . '0' . $oid;
return $oid;
}
SO...... I was thinking its a format issue and I have to cast it. I've failed with all of the following solutions.
1st Tried to cast $iListID as $oid = number_format($iListID);
2nd Tried to cast $iListID as $oid = is_numeric($iListID);
3rd Tried to create an actual function as I initial was writting it:
That failure was something like this:
function GetOID(){
return $iListID;
}
function GenUID(){
$oid = GetOID();
if ($oid < 10)
$oid = 'ODG_' . '00' . $oid;
else if ($oid < 100)
$oid = 'ODG_' . '0' . $oid;
return $oid;
}
Any suggestions?