#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    sydeny nsw aus
    Posts
    53
    Rep Power
    14
    I just write a record to my sql database, how can i get current (last)record number any help would be appreaciate.
  2. #2
  3. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    Are you talking about the id generated by an auto_increment field??

    If so you can use last_insert_id
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    sydeny nsw aus
    Posts
    53
    Rep Power
    14
    <BLOCKQUOTE><font size="1" face="Verdana,Arial,Helvetica">quote:</font><HR>Originally posted by rod k:
    Are you talking about the id generated by an auto_increment field??

    If so you can use last_insert_id
    [/quote]

    Yes, that's exactly what I am talking about,I am trying do like this

    array_unshift($arrlink, "<a href="http://www.xxxx.com/display.php?id="$last_insert_id"" target="_blank">$title</a><br>n");

    but something wrong with it,what I want is to make URL like http://www.xxx.com/display.php?id=163 in text file for each line,could you help again.

    thanks a lot for help

  6. #4
  7. No Profile Picture
    Apprentice Deity
    Devshed Loyal (3000 - 3499 posts)

    Join Date
    Jul 1999
    Location
    Niagara Falls (On the wrong side of the gorge)
    Posts
    3,237
    Rep Power
    18
    OK, I couldn't be more specific since I didn't know what scripting language you were using.

    In PHP, after you run your insert you can grab the last insert id like this:

    $link=mysql_pconnect(foo,bar,foobar);
    mysql_db_select(whatever);
    $result=mysql_query("insert into table ...");
    $id=mysql_insert_id($link);
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2000
    Location
    sydeny nsw aus
    Posts
    53
    Rep Power
    14
    First, You are realy nice,I feel so lucky can get your help,you just told me what I am looking for.

    I use PHP, before you second time answer my question, I try to use $query2 = "select id from content where title = '$title'";
    $result2 = MYSQL_QUERY($query2);
    $row2 = mysql_fetch_array($result2);
    $id=$row2[0];

    but your way just what I am looking for, I can only use last line
    $id=mysql_insert_id($link);
    to replace above three line I used in my script.

    thanks a lot, all the best to you


Similar Threads

  1. Finding current record in a recordset
    By Anubus in forum Visual Basic Programming
    Replies: 7
    Last Post: January 27th, 2004, 09:39 PM
  2. Odd problem with a hash and foreach loop
    By quantumechanix in forum Perl Programming
    Replies: 7
    Last Post: December 15th, 2003, 05:06 PM
  3. Need help finding a seg fault!
    By oblik in forum C Programming
    Replies: 13
    Last Post: October 8th, 2003, 05:24 PM

IMN logo majestic logo threadwatch logo seochat tools logo