Page 1 of 1

Reference Number...HELP!!!

Posted: Wed Jan 14, 2004 12:15 pm
by apek
i have a new pronblem...heheh..
I have a submit form that is managed with PHP. On the form, there has to be a reference number that has to be incremented every time a user submits.And the reference number interacts with mysql..

heres my code:

Code: Select all

//---------------------------------------
   //            DATE FUNCTION
   //---------------------------------------
   $Tdate = getdate();
    $datToday = date("d/m/Y");
    $year=$Tdate['year'];
   //---------------------------------------
   //          REFFRENCE NUMBER
   //---------------------------------------

    $query = "Select * from ".$DBprefix." rujAduan";
    $logCursor = mysql_query($query);

    if ($logCursor.$EOF) {
        $refNum = 1;
    } else {
        $refNum = $logCursor["ref"] + 1;
    }

    if ($refNum < 10) {
          $refNumber = "00".$refNum;
     } else {
          if ($refNum < 100) {
              $refNumber = "0".$refNum;
          } else {
              $refNumber = $refNum;
          }
        }

    $referNum = "REF".$refNumber."/".$year;
?>
the output is like REF001/2004..
but when i submit it again,it still show REF001/2004..
it suppose to show REF002/2004 (increment by 1)..
wheres the error??
hmm...help!!!!!!!!!


hmmm..i try to check in my mysql database..
theres a strange thing happens...
the rujAduan table is consist of "ID" and "ref" field...
suppose the "ref" field is increased by 1...(look at the code)
but why must the ID field is increase?
haaaaaa.......HELP!!!!!!!!!!!

Posted: Thu Jan 15, 2004 3:02 am
by twigletmac
Can you please post the table structure so that we can see what is going on. You'll probably find it easier to use an autoincrementing ID field and then construct the reference from that.

Mac