question about altering table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • runway27
    Banned
    New Member
    • Sep 2007
    • 54

    question about altering table

    i have a field in a table called refid which is varchar defined as NULL.

    presently every time an insert query is executed i get the lastid and use this to update the refid field in such a way that this field records information like E1 E2 E3..... as per the code below.
    ---------------------------------------------------------------
    $lastid = mysql_insert_id ();
    UPDATE tablename SET refid = 'E$lastid' WHERE ref = '$lastid'
    ---------------------------------------------------------------

    now what i need is instead of the refid starting from E1 E2 E3.... is it possible to chnage this to E101 E102 E103......

    please provide the sql query in order to get this format.

    also since i am presently doing a test with the table i dont mind dropping the table and recreating the table in order to get the above result.

    please advice.

    thanks.
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by runway27
    i have a field in a table called refid which is varchar defined as NULL.

    presently every time an insert query is executed i get the lastid and use this to update the refid field in such a way that this field records information like E1 E2 E3..... as per the code below.
    ---------------------------------------------------------------
    $lastid = mysql_insert_id ();
    UPDATE tablename SET refid = 'E$lastid' WHERE ref = '$lastid'
    ---------------------------------------------------------------

    now what i need is instead of the refid starting from E1 E2 E3.... is it possible to chnage this to E101 E102 E103......

    please provide the sql query in order to get this format.

    also since i am presently doing a test with the table i dont mind dropping the table and recreating the table in order to get the above result.

    please advice.

    thanks.
    Try this:

    Code:
    $lastid = mysql_insert_id();
    $lastid = $lastid + 100;
    UPDATE tablename SET refid = 'E$lastid' WHERE ref = '$lastid'

    Comment

    • mwasif
      Recognized Expert Contributor
      • Jul 2006
      • 802

      #3
      What would you like refid to be if the $lastid are 100,250,9786. Do you want to plus 100 as amitpatel66 suggested or you want to append '10' with $lastid?

      Comment

      Working...