Welcome guest. Before posting on our computer help forum, you must register. Click here it's easy and free.

Author Topic: INSERT-UPDATE mysql  (Read 2742 times)

0 Members and 1 Guest are viewing this topic.

dthscyth

    Topic Starter


    Rookie

    INSERT-UPDATE mysql
    « on: May 25, 2010, 06:26:35 AM »
    I want to create a column which concatenates YYYY(date) and a 00(int) -> not auto increment, the result would be like this 201001, 201002, so on... The last two digit would increment every time a new row is inserted. Does anyone know how to deal with this?

    Because the code i wrote doesn't seem to work, Here's my code.

    $sql = "INSERT INTO my_table(send_to, request_id) VALUES('$send_to', '$request_id');
    //insert new row, the request_id here is int

    $sql = "SELECT (request_id + 1) AS request_id1, id FROM my_table ORDER BY id DESC LIMIT 1";
    $reqID = $row['request_id1'];
    $id = $row['id'];
    //assuming mysql_query & mysql_fetch_array is done.
    //id is the primary key, this code selects the last row and then add the request_id by 1

    $sql = "UPDATE my_table SET request_id = $reqID WHERE id = $id";
    //the problem here is it keeps on inserting new row but the value of request_id still the same